     1                                  ; ****************************************************************************
     2                                  ; playmod.asm (for MSDOS)
     3                                  ; ----------------------------------------------------------------------------
     4                                  ; PLAYMOD.COM ! VIA VT8237 MOD PLAYER & VGA DEMO program by Erdogan TAN
     5                                  ;
     6                                  ; 13/02/2017
     7                                  ;
     8                                  ; [ Last Modification: 15/02/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.COM' ('tinyplay.asm') source code by Erdogan Tan
    14                                  ;					                      (13/02/2017)
    15                                  ;
    16                                  ; Derived from source code of 'PLAYER.COM' ('PLAYER.ASM') by Erdogan Tan
    17                                  ;							      (08/12/2016) 
    18                                  ; Assembler: NASM 2.11
    19                                  ; ----------------------------------------------------------------------------
    20                                  ;	   nasm  playmod.asm -l playmod.lst -o PLAYMOD.COM	
    21                                  ; ****************************************************************************
    22                                  
    23                                  ; Tiny MOD Player v0.1b by Carlos Hasan.
    24                                  ;		July 14th, 1993.
    25                                  
    26                                  ;=============================================================================
    27                                  ;               PLAYER.ASM
    28                                  ;=============================================================================
    29                                  ; Audio controller, codec & PCI functions are derived from '.wav file player 
    30                                  ; for DOS' source code by Jeff Leyda (PLAYER.EXE), Sep 02, 2002 .
    31                                  
    32                                  [BITS 16]
    33                                  [org 100h]
    34                                  
    35                                  Start:
    36 00000000 E8E500                  		call    DetectVT8233		; Detect the VT8233 Audio Device
    37                                  GetFileName:    				; Parse  the Command line...
    38 00000003 BE8000                  		mov	si, 80h
    39 00000006 8A1C                    		mov	bl, [si]
    40 00000008 30FF                    		xor	bh, bh
    41 0000000A 43                      		inc	bx
    42 0000000B C60000                  		mov	byte [si+bx], 0		; make AsciiZ filename.
    43 0000000E 46                      		inc	si
    44                                  ScanName:       
    45 0000000F AC                      		lodsb
    46 00000010 84C0                    		test	al, al
    47 00000012 0F84C800                		je	pmsg_2017
    48 00000016 3C20                    		cmp	al, 20h
    49 00000018 74F5                    		je	short ScanName		; scan start of name.
    50 0000001A 89F7                    		mov	di, si
    51 0000001C 4F                      		dec	di
    52                                  ScanPeriod:
    53 0000001D AC                      		lodsb
    54 0000001E 3C2E                    		cmp	al, '.'			; if period NOT found,
    55 00000020 7410                    		je	short PrintMesg		; then add a .MOD extension.
    56 00000022 84C0                    		test	al, al
    57 00000024 75F7                    		jnz	short ScanPeriod
    58 00000026 4E                      		dec	si
    59                                  SetExt:
    60                                  		;mov	byte [si+0], '.'
    61                                  		;mov	byte [si+1], 'M'
    62                                  		;mov	byte [si+2], 'O'
    63                                  		;mov	byte [si+3], 'D'
    64 00000027 66C7042E4D4F44          		mov	dword [si], '.MOD'
    65 0000002E C6440400                		mov	byte [si+4], 0
    66                                  
    67 00000032 B80009                  PrintMesg:      mov     ax, 0900h		; Prints the Credits Text.
    68                                  		;lea    dx, [Credits]
    69 00000035 BA[100F]                		mov	dx, Credits
    70 00000038 CD21                    		int     21h
    71                                  LoadMod:  
    72                                  		; es:di = Filename address
    73 0000003A 06                      		push	es
    74 0000003B 57                      		push	di
    75 0000003C E89006                  		call    LoadModule		; Load the MODule...
    76                                  
    77 0000003F 833E[4E22]00            		cmp     word [ErrorInfo], 0	; any error loading?
    78 00000044 740B                    		je      short init_codec
    79                                  
    80 00000046 B80009                  		mov     ax, 0900h		; yes, print error and Exit.
    81                                  		;lea    dx, [ErrorMesg]
    82 00000049 BA[440F]                		mov	dx, ErrorMesg
    83 0000004C CD21                    		int     21h
    84 0000004E E98600                  		jmp     Exit
    85                                  
    86                                  init_codec:
    87                                  	; init AC97 codec
    88                                  _a1:
    89 00000051 B041                    	mov	al, VIA_ACLINK_CTRL  ; AC link interface control (41h)
    90 00000053 E8F701                  	call	pciRegRead8
    91                                  
    92 00000056 B040                    	mov	al, VIA_ACLINK_STAT  ; AC Link interface status (40h)
    93 00000058 E8F201                  	call	pciRegRead8
    94                                  	
    95                                  	;movzx	eax, dl
    96                                  	;test	al, VIA_ACLINK_C00_READY  ; 1 ; primary codec ready ?
    97                                  	;jnz	short _a2
    98                                  
    99 0000005B E87703                  	call	reset_codec
   100 0000005E 731E                    	jnc	short _a2 ; EAX = 1
   101                                  
   102                                  	;test	al, VIA_ACLINK_C00_READY 	
   103                                          ;jnz     short _a2
   104                                  
   105                                  _codec_err:
   106 00000060 0E                      	push	cs
   107 00000061 1F                      	pop	ds
   108 00000062 BA[6B00]                        mov	dx, CodecErrMsg
   109 00000065 B409                            mov     ah, 9
   110 00000067 CD21                            int     21h
   111 00000069 EB6C                            jmp     Exit
   112                                  
   113 0000006B 436F64656320457272-     CodecErrMsg db "Codec Error #"
   113 00000074 6F722023           
   114 00000078 3020210D0A24            ErrNo	db	"0 !", CR,LF,"$"
   115                                  
   116                                  _a2:
   117                                  	; eax = 1
   118 0000007E E8BC03                  	call	codec_io_w16 ; w32
   119                                  	
   120                                  	;call	detect_codec
   121                                  
   122 00000081 E85704                  	call	channel_reset
   123                                  
   124 00000084 E8120D                  	call	write_ac97_dev_info 
   125                                  
   126                                  ; setup the Codec (actually mixer registers) 
   127 00000087 E89202                          call    codecConfig                     ; unmute codec, set rates.
   128 0000008A 7307                    	jnc	short PlayNow
   129                                  
   130 0000008C 0430                    	add	al, '0'
   131 0000008E A2[7800]                	mov	[ErrNo], al
   132 00000091 EBCD                    	jmp	short _codec_err
   133                                  
   134                                  PlayNow:  
   135 00000093 B8[4C11]                	mov	ax, BdlBuffer
   136 00000096 A3[3611]                	mov	[BDL_BUFFER], ax
   137                                      
   138 00000099 B8[4C12]                	mov	ax, DmaBuffer		; DmaBuffer (4096 bytes) buff addr
   139 0000009C A3[3811]                	mov	[DMA_BUFFER1], ax	; 2048 byte half buffer 1 
   140                                  
   141 0000009F 050008                  	add	ax, BUFFERSIZE		; code/current segment
   142 000000A2 A3[3A11]                	mov	[DMA_BUFFER2], ax	; 2048 byte half buffer 2
   143                                    
   144 000000A5 C706[8C26]2256          	mov     word [MixSpeed], 22050	; Mixing at 22.050 kHz
   145                                  
   146 000000AB E8E20B                  	call    StartPlaying
   147                                  
   148 000000AE B81300                  	mov     ax, 0013h		; Set Mode 320x200x256
   149 000000B1 CD10                    	int     10h
   150                                  
   151 000000B3 B98000                  	mov     cx, 128			; Make a lookup table
   152 000000B6 31DB                    	xor     bx, bx			; for fastest pixel
   153 000000B8 BA002D                  	mov     dx, 320*(100-64)	; addressing.
   154                                  MakeOfs:        
   155 000000BB 8997[6083]              	mov     [RowOfs+bx], dx
   156 000000BF 8997[6283]              	mov     [RowOfs+bx+2], dx
   157 000000C3 81C24001                	add     dx, 320
   158 000000C7 83C304                  	add     bx, 4
   159 000000CA E2EF                    	loop    MakeOfs
   160                                  
   161                                  ; Note: Normally IRQ 0 calls the ModPlay Polling at 18.2Hz thru
   162                                  ;       the software interrupt 1Ch. If the IRQ 0 is disabled, then
   163                                  ;       the INT 1Ch MUST BE CALLED at least MixSpeed/1024 times per
   164                                  ;       second, or the module will sound "looped".
   165                                  ;       Because we need better sync with the ModPlayer to draw the scope,
   166                                  ;       the polling is called from my routine, and then the irq 0 must be
   167                                  ;       disabled. The [DmaBuffer] points to the current buffer of 8-bit
   168                                  ;       samples played by the Sound Blaster. Note that some samples are
   169                                  ;       discarded in the next code, just for fun!
   170                                  
   171                                  	;in     al, 21h			; disable irq 0!
   172                                  	;or     al, 00000001b
   173                                  	;out    21h, al
   174                                  		
   175 000000CC E85404                  	call	ModPlay ; 13/02/2017
   176                                  
   177                                  	;in	al, 21h			; enable irq 0!
   178                                  	;and	al, 11111110b
   179                                  	;out	21h, al
   180                                  
   181 000000CF B80300                  	mov     ax, 0003h		; Set Text Mode 80x25x16
   182 000000D2 CD10                    	int     10h
   183                                  
   184 000000D4 E8390C                  	call	StopPlaying		; STOP!
   185                                  Exit:           
   186                                  	;call    FreeModule             ; Free MODule core.
   187                                  error_exit:
   188 000000D7 B8004C                  	mov     ax, 4C00h		; Bye!
   189 000000DA CD21                    	int     21h
   190                                  here:
   191 000000DC EBFE                    	jmp	short here
   192                                  
   193                                  pmsg_2017:
   194 000000DE B80009                  	mov     ax, 0900h		; Prints the Credits Text.
   195                                  	;lea    dx, [msg_2017]
   196 000000E1 BA[B80E]                	mov	dx, msg_2017
   197 000000E4 CD21                    	int     21h
   198 000000E6 EBEF                    	jmp	short Exit
   199                                  
   200                                  DetectVT8233:
   201                                  	; 13/02/2017
   202 000000E8 66B806115930                    mov     eax, (VT8233_DID << 16) + VIA_VID
   203 000000EE E8F201                          call    pciFindDevice
   204 000000F1 7342                            jnc     short _1
   205                                  
   206                                  ; couldn't find the audio device!
   207                                  
   208 000000F3 0E                      	push	cs
   209 000000F4 1F                      	pop	ds
   210 000000F5 BA[FE00]                        mov     dx, noDevMsg
   211 000000F8 B409                            mov     ah, 9
   212 000000FA CD21                            int     21h
   213 000000FC EBD9                            jmp     short error_exit
   214                                  
   215 000000FE 4572726F723A20556E-     noDevMsg db "Error: Unable to find VIA VT8233 based audio device!",CR,LF,"$"
   215 00000107 61626C6520746F2066-
   215 00000110 696E64205649412056-
   215 00000119 543832333320626173-
   215 00000122 656420617564696F20-
   215 0000012B 646576696365210D0A-
   215 00000134 24                 
   216                                  
   217                                  _1:
   218                                  	; 12/11/2016
   219                                  	; Erdogan Tan - 8/11/2016
   220                                  	; References: Kolibrios - vt823x.asm (2016)
   221                                  	;	      VIA VT8235 V-Link South Bridge (VT8235-VIA.PDF)(2002)
   222                                  	;	      lowlevel.eu - AC97 (2016)
   223                                  	;	      .wav player for DOS by Jeff Leyda (2002) -this file-
   224                                  	;	      Linux kernel - via82xx.c (2016)
   225                                  
   226                                  	; eax = BUS/DEV/FN
   227                                  	;	00000000BBBBBBBBDDDDDFFF00000000
   228                                  	; edx = DEV/VENDOR
   229                                  	;	DDDDDDDDDDDDDDDDVVVVVVVVVVVVVVVV
   230                                  
   231 00000135 66A3[3E11]              	mov	[bus_dev_fn], eax
   232 00000139 668916[4211]            	mov	[dev_vendor], edx
   233                                  
   234                                  	; init controller
   235 0000013E B004                    	mov	al, PCI_CMD_REG ; command register (04h)
   236 00000140 E82001                  	call	pciRegRead32
   237                                  
   238                                  	; eax = BUS/DEV/FN/REG
   239                                  	; edx = STATUS/COMMAND
   240                                  	; 	SSSSSSSSSSSSSSSSCCCCCCCCCCCCCCCC
   241 00000143 668916[4611]            	mov	[stats_cmd], edx
   242                                  
   243 00000148 B010                    	mov	al, PCI_IO_BASE ; IO base address register (10h)
   244 0000014A E81601                  	call	pciRegRead32
   245                                  
   246 0000014D 83E2C0                  	and     dx, 0FFC0h	; IO_ADDR_MASK (0FFFE) ?
   247 00000150 8916[4A11]                      mov     [ac97_io_base], dx
   248                                  
   249 00000154 B03C                    	mov	al, AC97_INT_LINE ; Interrupt line register (3Ch)
   250 00000156 E80A01                  	call	pciRegRead32
   251                                  
   252 00000159 6681E2FF000000          	and 	edx, 0FFh
   253 00000160 8816[3C11]                	mov     [ac97_int_ln_reg], dl
   254                                  
   255                                  	; 28/11/2016
   256 00000164 BB0100                  	mov	bx, 1
   257 00000167 89D1                    	mov	cx, dx
   258 00000169 D3E3                    	shl	bx, cl
   259                                  
   260                                  	;not	bx
   261 0000016B E4A1                    	in	al, 0A1h ; irq 8-15
   262 0000016D 88C4                            mov	ah, al
   263 0000016F E421                            in	al, 21h  ; irq 0-7 
   264                                  	;and	ax, bx   ; unmask
   265 00000171 0FB3D0                   	btr	ax, dx	 ; unmask
   266 00000174 E621                    	out	21h, al  ; enable interrupt (if irq <= 7)
   267 00000176 88E0                    	mov	al, ah
   268 00000178 E6A1                    	out	0A1h, al ; enable interrupt (if irq > 7)
   269                                  	;not	bx
   270                                  
   271 0000017A BAD104                  	mov	dx, 4D1h			;8259 ELCR1
   272 0000017D EC                              in	al, dx
   273 0000017E 88C4                    	mov	ah, al
   274 00000180 BAD004                  	mov	dx, 4D0h 
   275 00000183 EC                              in	al, dx
   276                                  	;or	ax, bx        
   277 00000184 0FABC8                  	bts	ax, cx
   278 00000187 BAD004                  	mov	dx, 4D0h
   279 0000018A EE                      	out	dx, al                          ;set level-triggered mode
   280 0000018B 88E0                    	mov	al, ah
   281 0000018D BAD104                  	mov	dx, 4D1h
   282 00000190 EE                      	out	dx, al                          ;set level-triggered mode
   283                                  
   284                                  	; 24/11/2016 - Erdogan Tan
   285 00000191 89CB                    	mov	bx, cx
   286                                  	;mov	bx, dx
   287 00000193 8A9F[2010]              	mov	bl, [bx+irq_int]
   288 00000197 C1E302                  	shl	bx, 2 ; * 4
   289                                  
   290                                  	; set up interrupt vector
   291                                  	; 30/11/2016
   292 0000019A 06                      	push	es
   293 0000019B 31C0                    	xor	ax, ax
   294 0000019D 8EC0                    	mov	es, ax
   295 0000019F 26C707[AC01]            	mov	word [es:bx], ac97_int_handler
   296 000001A4 8CC8                    	mov	ax, cs
   297 000001A6 26894702                	mov	[es:bx+2], ax
   298 000001AA 07                      	pop	es
   299                                  		
   300 000001AB C3                      	retn
   301                                  
   302                                  ac97_int_handler:
   303 000001AC 50                      	push	ax
   304 000001AD 52                      	push	dx
   305 000001AE 51                      	push	cx
   306 000001AF 53                      	push	bx
   307 000001B0 56                      	push	si
   308 000001B1 57                      	push	di
   309                                  
   310                                  	; 15/02/2017
   311 000001B2 1E                      	push	ds
   312 000001B3 8CCA                    	mov	dx, cs
   313 000001B5 8EDA                    	mov	ds, dx	
   314                                  
   315                                  	; 28/11/2016
   316 000001B7 803E[3411]01            	cmp	byte [uLVI], 1
   317 000001BC 7338                    	jnb	short _busy
   318                                  
   319 000001BE C606[3411]01            	mov	byte [uLVI], 1
   320                                  
   321 000001C3 C606[3311]00            	mov	byte [irq_status], 0
   322                                  
   323 000001C8 BA0000                          mov     dx, VIADEV_PLAYBACK + VIA_REG_OFFSET_STATUS
   324 000001CB E88B02                          call    ctrl_io_r8
   325                                  
   326 000001CE A880                    	test    al, VIA_REG_STAT_ACTIVE
   327 000001D0 740A                            jz      short _ih0
   328                                  
   329 000001D2 2407                            and     al, VIA_REG_STAT_EOL + VIA_REG_STAT_FLAG + VIA_REG_STAT_STOPPED
   330 000001D4 A2[3311]                	mov	[irq_status], al
   331 000001D7 7403                            jz	short _ih0
   332                                  
   333                                  	; 28/11/2016 - Erdogan Tan
   334 000001D9 E85D04                  	call	tuneLoop
   335                                  _ih0:
   336 000001DC C606[3411]00            	mov	byte [uLVI], 0
   337                                  _p_i_retn:
   338 000001E1 B020                    	mov	al, 20h
   339 000001E3 F606[3C11]08            	test	byte [ac97_int_ln_reg], 8
   340 000001E8 7402                    	jz	short _ih_1
   341 000001EA E6A0                    	out 	0A0h, al ; 20h ; EOI
   342                                  _ih_1:
   343 000001EC E620                    	out	20h, al  ; 20h ; EOI
   344                                  _ih_2:
   345 000001EE 1F                      	pop	ds ; 15/02/2017
   346                                  
   347 000001EF 5F                      	pop	di
   348 000001F0 5E                      	pop	si
   349 000001F1 5B                      	pop	bx
   350 000001F2 59                      	pop	cx
   351 000001F3 5A                      	pop	dx
   352 000001F4 58                      	pop	ax
   353 000001F5 CF                      	iret
   354                                  
   355                                  _busy:
   356                                  	; 28/11/2016 - Erdogan Tan
   357 000001F6 A0[3311]                        mov     al, [irq_status]   ;; ack ;;
   358 000001F9 BA0000                          mov     dx, VIADEV_PLAYBACK + VIA_REG_OFFSET_STATUS
   359 000001FC E85402                          call    ctrl_io_w8
   360                                  
   361 000001FF EBDB                    	jmp	short _ih0
   362                                  
   363                                  
   364                                  ;=============================================================================
   365                                  ;               PCI.ASM
   366                                  ;=============================================================================
   367                                  
   368                                  ; EQUATES
   369                                  
   370                                  ;constants of stuff that seem hard to remember at times.
   371                                  
   372                                  TRUE  EQU 1
   373                                  FALSE EQU 0
   374                                  
   375                                  ENABLED  EQU 1
   376                                  DISABLED EQU 0
   377                                  
   378                                  BIT0  EQU 1
   379                                  BIT1  EQU 2
   380                                  BIT2  EQU 4
   381                                  BIT3  EQU 8
   382                                  BIT4  EQU 10h
   383                                  BIT5  EQU 20h
   384                                  BIT6  EQU 40h
   385                                  BIT7  EQU 80h
   386                                  BIT8  EQU 100h
   387                                  BIT9  EQU 200h
   388                                  BIT10 EQU 400h
   389                                  BIT11 EQU 800h
   390                                  BIT12 EQU 1000h
   391                                  BIT13 EQU 2000h
   392                                  BIT14 EQU 4000h
   393                                  BIT15 EQU 8000h
   394                                  BIT16 EQU 10000h
   395                                  BIT17 EQU 20000h
   396                                  BIT18 EQU 40000h
   397                                  BIT19 EQU 80000h
   398                                  BIT20 EQU 100000h
   399                                  BIT21 EQU 200000h
   400                                  BIT22 EQU 400000h
   401                                  BIT23 EQU 800000h
   402                                  BIT24 EQU 1000000h
   403                                  BIT25 EQU 2000000h
   404                                  BIT26 EQU 4000000h
   405                                  BIT27 EQU 8000000h
   406                                  BIT28 EQU 10000000h
   407                                  BIT29 EQU 20000000h
   408                                  BIT30 EQU 40000000h
   409                                  BIT31 EQU 80000000h
   410                                  
   411                                  ;special characters
   412                                  NUL     EQU 0
   413                                  NULL    EQU 0
   414                                  BELL    EQU 07
   415                                  BS      EQU 08
   416                                  TAB     EQU 09
   417                                  LF      EQU 10
   418                                  CR      EQU 13
   419                                  ESCAPE  EQU 27           ;ESC is a reserved word....
   420                                  
   421                                  
   422                                  ;file stuff
   423                                  READONLY  EQU   BIT0
   424                                  HIDDEN    EQU   BIT1
   425                                  SYSTEM    EQU   BIT2
   426                                  VOLUME    EQU   BIT3         ;ignored for file access
   427                                  DIRECTORY EQU   BIT4         ;must be 0 for file access
   428                                  ARCHIVE   EQU   BIT5
   429                                  SHAREABLE EQU   BIT7         ;for novell networks
   430                                  OPEN	EQU	2		; open existing file
   431                                  CREATE	EQU	1		; create new file
   432                                  
   433                                  
   434                                  ; PCI equates
   435                                  ; PCI function address (PFA)
   436                                  ; bit 31 = 1
   437                                  ; bit 23:16 = bus number     (0-255)
   438                                  ; bit 15:11 = device number  (0-31)
   439                                  ; bit 10:8 = function number (0-7)
   440                                  ; bit 7:0 = register number  (0-255)
   441                                  
   442                                  IO_ADDR_MASK    EQU     0FFFEh          ; mask off bit 0 for reading BARs
   443                                  PCI_INDEX_PORT  EQU     0CF8h
   444                                  PCI_DATA_PORT   EQU     0CFCh
   445                                  PCI32           EQU     BIT31           ; bitflag to signal 32bit access
   446                                  PCI16           EQU     BIT30           ; bitflag for 16bit access
   447                                  
   448                                  PCI_FN0         EQU     0 << 8
   449                                  PCI_FN1         EQU     1 << 8
   450                                  PCI_FN2         EQU     2 << 8
   451                                  PCI_FN3         EQU     3 << 8
   452                                  PCI_FN4         EQU     4 << 8
   453                                  PCI_FN5         EQU     5 << 8
   454                                  PCI_FN6         EQU     6 << 8
   455                                  PCI_FN7         EQU     7 << 8
   456                                  
   457                                  PCI_CMD_REG		EQU	04h		; reg 04, command reg
   458                                   IO_ENA			EQU	BIT0		; i/o decode enable
   459                                   MEM_ENA		EQU	BIT1		; memory decode enable
   460                                   BM_ENA                 EQU     BIT2		; bus master enable
   461                                  
   462                                  ; CODE
   463                                  
   464                                  ; PCI device register reader/writers.
   465                                  ; NASM version: Erdogan Tan (29/11/2016)
   466                                  
   467                                  ;===============================================================
   468                                  ; 8/16/32bit PCI reader
   469                                  ;
   470                                  ; Entry: EAX=PCI Bus/Device/fn/register number
   471                                  ;           BIT30 set if 32 bit access requested
   472                                  ;           BIT29 set if 16 bit access requested
   473                                  ;           otherwise defaults to 8bit read
   474                                  ;
   475                                  ; Exit:  DL,DX,EDX register data depending on requested read size
   476                                  ;
   477                                  ; Note: this routine is meant to be called via pciRegRead8, pciRegread16,
   478                                  ;	or pciRegRead32, listed below.
   479                                  ;
   480                                  ; Note2: don't attempt to read 32bits of data from a non dword aligned reg
   481                                  ;	 number.  Likewise, don't do 16bit reads from non word aligned reg #
   482                                  ; 
   483                                  pciRegRead:
   484 00000201 6653                    	push	ebx
   485 00000203 51                      	push	cx
   486 00000204 6689C3                          mov     ebx, eax                        ; save eax, dh
   487 00000207 88F1                            mov     cl, dh
   488 00000209 6625FFFFFFBF                    and     eax, (~PCI32)+PCI16             ; clear out data size request
   489 0000020F 660D00000080                    or      eax, BIT31                      ; make a PCI access request
   490 00000215 24FC                            and     al, ~3 ; NOT 3                  ; force index to be dword
   491                                  
   492 00000217 BAF80C                          mov     dx, PCI_INDEX_PORT
   493 0000021A 66EF                            out     dx, eax                         ; write PCI selector
   494                                  
   495 0000021C BAFC0C                          mov     dx, PCI_DATA_PORT
   496 0000021F 88D8                            mov     al, bl
   497 00000221 2403                            and     al, 3                           ; figure out which port to
   498 00000223 00C2                            add     dl, al                          ; read to
   499                                  
   500 00000225 66ED                    	in      eax, dx                         ; do 32bit read
   501 00000227 66F7C300000080                  test    ebx, PCI32
   502 0000022E 7403                            jz      short _pregr1
   503                                  
   504 00000230 6689C2                          mov     edx, eax                        ; return 32bits of data
   505                                  _pregr1:
   506 00000233 89C2                    	mov     dx, ax                          ; return 16bits of data
   507 00000235 66F7C3000000C0                  test    ebx, PCI32+PCI16
   508 0000023C 7502                            jnz     short _pregr2
   509 0000023E 88CE                            mov     dh, cl                          ; restore dh for 8 bit read
   510                                  _pregr2:
   511 00000240 6689D8                          mov     eax, ebx                        ; restore eax
   512 00000243 6625FFFFFFBF                    and     eax, (~PCI32)+PCI16             ; clear out data size request
   513 00000249 59                      	pop	cx
   514 0000024A 665B                    	pop	ebx
   515 0000024C C3                      	retn
   516                                  
   517                                  pciRegRead8:
   518 0000024D 6625FFFFFF3F                    and     eax, (~PCI16)+PCI32             ; set up 8 bit read size
   519 00000253 EBAC                            jmp     short pciRegRead		; call generic PCI access
   520                                  
   521                                  pciRegRead16:
   522 00000255 6625FFFFFF3F                    and     eax, (~PCI16)+PCI32		; set up 16 bit read size
   523 0000025B 660D00000040                    or      eax, PCI16			; call generic PCI access
   524 00000261 EB9E                            jmp     short pciRegRead
   525                                  
   526                                  pciRegRead32:
   527 00000263 6625FFFFFF3F                    and     eax, (~PCI16)+PCI32		; set up 32 bit read size
   528 00000269 660D00000080                    or      eax, PCI32			; call generic PCI access
   529 0000026F EB90                            jmp     short pciRegRead
   530                                  
   531                                  ;===============================================================
   532                                  ; 8/16/32bit PCI writer
   533                                  ;
   534                                  ; Entry: EAX=PCI Bus/Device/fn/register number
   535                                  ;           BIT31 set if 32 bit access requested
   536                                  ;           BIT30 set if 16 bit access requested
   537                                  ;           otherwise defaults to 8bit read
   538                                  ;        DL/DX/EDX data to write depending on size
   539                                  ;
   540                                  ;
   541                                  ; note: this routine is meant to be called via pciRegWrite8, pciRegWrite16,
   542                                  ; 	or pciRegWrite32 as detailed below.
   543                                  ;
   544                                  ; Note2: don't attempt to write 32bits of data from a non dword aligned reg
   545                                  ;	 number.  Likewise, don't do 16bit writes from non word aligned reg #
   546                                  ;
   547                                  pciRegWrite:
   548 00000271 6653                    	push	ebx
   549 00000273 51                      	push	cx
   550 00000274 6689C3                          mov     ebx, eax                        ; save eax, dx
   551 00000277 89D1                            mov     cx, dx
   552 00000279 660D00000080                    or      eax, BIT31                      ; make a PCI access request
   553 0000027F 6625FFFFFFBF                    and     eax, ~PCI16 ; NOT PCI16         ; clear out data size request
   554 00000285 24FC                            and     al, ~3 ; NOT 3                  ; force index to be dword
   555                                  
   556 00000287 BAF80C                          mov     dx, PCI_INDEX_PORT
   557 0000028A 66EF                            out     dx, eax                         ; write PCI selector
   558                                  
   559 0000028C BAFC0C                          mov     dx, PCI_DATA_PORT
   560 0000028F 88D8                            mov     al, bl
   561 00000291 2403                            and     al, 3                           ; figure out which port to
   562 00000293 00C2                            add     dl, al                          ; write to
   563                                  
   564 00000295 6689D0                          mov     eax, edx                        ; put data into eax
   565 00000298 89C8                            mov     ax, cx
   566                                  
   567 0000029A EE                              out     dx, al
   568 0000029B 66F7C3000000C0                  test    ebx, PCI16+PCI32                ; only 8bit access? bail
   569 000002A2 740C                            jz      short _pregw1
   570                                  
   571 000002A4 EF                              out     dx, ax                          ; write 16 bit value
   572 000002A5 66F7C300000040                  test    ebx, PCI16                      ; 16bit requested?  bail
   573 000002AC 7502                            jnz     short _pregw1
   574                                  
   575 000002AE 66EF                            out     dx, eax                         ; write full 32bit
   576                                  _pregw1:
   577 000002B0 6689D8                          mov     eax, ebx                        ; restore eax
   578 000002B3 6625FFFFFFBF                    and     eax, (~PCI32)+PCI16             ; clear out data size request
   579 000002B9 89CA                            mov     dx, cx                          ; restore dx
   580 000002BB 59                      	pop	cx
   581 000002BC 665B                    	pop	ebx
   582 000002BE C3                      	ret
   583                                  
   584                                  pciRegWrite8:
   585 000002BF 6625FFFFFF3F                    and     eax, (~PCI16)+PCI32		; set up 8 bit write size
   586 000002C5 EBAA                            jmp     short pciRegWrite		; call generic PCI access
   587                                  
   588                                  pciRegWrite16:
   589 000002C7 6625FFFFFF3F                    and     eax, (~PCI16)+PCI32		; set up 16 bit write size
   590 000002CD 660D00000040                    or      eax, PCI16			; call generic PCI access
   591 000002D3 EB9C                            jmp     short pciRegWrite
   592                                  
   593                                  pciRegWrite32:
   594 000002D5 6625FFFFFF3F                    and     eax, (~PCI16)+PCI32		; set up 32 bit write size
   595 000002DB 660D00000080                    or      eax, PCI32			; call generic PCI access
   596 000002E1 EB8E                            jmp     short pciRegWrite
   597                                  
   598                                  ;===============================================================
   599                                  ; PCIFindDevice: scan through PCI space looking for a device+vendor ID
   600                                  ;
   601                                  ; Entry: EAX=Device+Vendor ID
   602                                  ;
   603                                  ;  Exit: EAX=PCI address if device found
   604                                  ;	 EDX=Device+Vendor ID
   605                                  ;        CY clear if found, set if not found. EAX invalid if CY set.
   606                                  ;
   607                                  ; [old stackless] Destroys: ebx, esi, edi, cl
   608                                  ;
   609                                  pciFindDevice:
   610                                  	;push	cx
   611 000002E3 6650                    	push	eax
   612                                  	;push	esi
   613                                  	;push	edi
   614                                  
   615 000002E5 6689C6                          mov     esi, eax                ; save off vend+device ID
   616 000002E8 66BF00FFFF7F                    mov     edi, (80000000h - 100h) ; start with bus 0, dev 0 func 0
   617                                  
   618                                  nextPCIdevice:
   619 000002EE 6681C700010000                  add     edi, 100h
   620 000002F5 6681FF00F8FF80                  cmp     edi, 80FFF800h		; scanned all devices?
   621 000002FC F9                              stc
   622 000002FD 740C                            je      short PCIScanExit       ; not found
   623                                  
   624 000002FF 6689F8                          mov     eax, edi                ; read PCI registers
   625 00000302 E85EFF                          call    pciRegRead32
   626 00000305 6639F2                          cmp     edx, esi                ; found device?
   627 00000308 75E4                            jne     short nextPCIdevice
   628 0000030A F8                              clc
   629                                  
   630                                  PCIScanExit:
   631 0000030B 9C                      	pushf
   632 0000030C 66B800000080            	mov	eax, BIT31
   633 00000312 66F7D0                  	not	eax
   634 00000315 6621F8                  	and	eax, edi		; return only bus/dev/fn #
   635 00000318 9D                      	popf
   636                                  
   637                                  	;pop	edi
   638                                  	;pop	esi
   639 00000319 665A                    	pop	edx
   640                                  	;pop	cx
   641 0000031B C3                      	retn
   642                                  
   643                                  ;=============================================================================
   644                                  ;               CODEC.ASM
   645                                  ;=============================================================================
   646                                  
   647                                  ; EQUATES
   648                                  
   649                                  ;Codec registers.
   650                                  ;
   651                                  ;Not all codecs are created equal. Refer to the spec for your specific codec.
   652                                  ;
   653                                  ;All registers are 16bits wide.  Access to codec registers over the AC97 link
   654                                  ;is defined by the OEM.  
   655                                  ;
   656                                  ;Secondary codec's are accessed by ORing in BIT7 of all register accesses.
   657                                  ;
   658                                  
   659                                  ; each codec/mixer register is 16bits
   660                                  
   661                                  CODEC_RESET_REG                 equ     00      ; reset codec
   662                                  CODEC_MASTER_VOL_REG            equ     02      ; master volume
   663                                  CODEC_HP_VOL_REG                equ     04      ; headphone volume
   664                                  CODEC_MASTER_MONO_VOL_REG       equ     06      ; master mono volume
   665                                  CODEC_MASTER_TONE_REG           equ     08      ; master tone (R+L)
   666                                  CODEC_PCBEEP_VOL_REG            equ     0ah     ; PC beep volume
   667                                  CODEC_PHONE_VOL_REG             equ     0bh     ; phone volume
   668                                  CODEC_MIC_VOL_REG               equ     0eh     ; MIC volume
   669                                  CODEC_LINE_IN_VOL_REG           equ     10h     ; line input volume
   670                                  CODEC_CD_VOL_REG                equ     12h     ; CD volume
   671                                  CODEC_VID_VOL_REG               equ     14h     ; video volume
   672                                  CODEC_AUX_VOL_REG               equ     16h     ; aux volume
   673                                  CODEC_PCM_OUT_REG               equ     18h     ; PCM output volume
   674                                  CODEC_RECORD_SELECT_REG         equ     1ah     ; record select input
   675                                  CODEC_RECORD_VOL_REG            equ     1ch     ; record volume
   676                                  CODEC_RECORD_MIC_VOL_REG        equ     1eh     ; record mic volume
   677                                  CODEC_GP_REG                    equ     20h     ; general purpose
   678                                  CODEC_3D_CONTROL_REG            equ     22h     ; 3D control
   679                                  ; 24h is reserved
   680                                  CODEC_POWER_CTRL_REG            equ     26h     ; powerdown control
   681                                  CODEC_EXT_AUDIO_REG             equ     28h     ; extended audio
   682                                  CODEC_EXT_AUDIO_CTRL_REG        equ     2ah     ; extended audio control
   683                                  CODEC_PCM_FRONT_DACRATE_REG     equ     2ch     ; PCM out sample rate
   684                                  CODEC_PCM_SURND_DACRATE_REG     equ     2eh     ; surround sound sample rate
   685                                  CODEC_PCM_LFE_DACRATE_REG       equ     30h     ; LFE sample rate
   686                                  CODEC_LR_ADCRATE_REG            equ     32h     ; PCM in sample rate
   687                                  CODEC_MIC_ADCRATE_REG           equ     34h     ; mic in sample rate
   688                                  
   689                                  ; registers 36-7a are reserved on the ICH
   690                                  
   691                                  CODEC_VENDORID1_REG             equ     7ch     ; codec vendor ID 1
   692                                  CODEC_VENDORID2_REG             equ     7eh     ; codec vendor ID 2
   693                                  
   694                                  ; Mixer registers 0 through 51h reside in the ICH and are not forwarded over
   695                                  ; the AC97 link to the codec, which I think is a little weird.  Looks like
   696                                  ; the ICH makes it so you don't need a fully functional codec to play audio?
   697                                  ;
   698                                  ; whenever 2 codecs are present in the system, use BIT7 to access the 2nd
   699                                  ; set of registers, ie 80h-feh
   700                                  
   701                                  PRIMARY_CODEC                   equ     0       ; 0-7F for primary codec
   702                                  SECONDARY_CODEC                 equ     BIT7    ; 80-8f registers for 2ndary
   703                                  
   704                                  SAMPLE_RATE_441khz	equ     44100   ; 44.1Khz (cd quality) rate
   705                                  
   706                                  ; each buffer descriptor BAR holds a pointer which has entries to the buffer
   707                                  ; contents of the .WAV file we're going to play.  Each entry is 8 bytes long
   708                                  ; (more on that later) and can contain 32 entries total, so each BAR is
   709                                  ; 256 bytes in length, thus:
   710                                  
   711                                  BDL_SIZE                equ     32*8    ; Buffer Descriptor List size
   712                                  INDEX_MASK              equ     31      ; indexes must be 0-31
   713                                  
   714                                  ;
   715                                  ; Buffer Descriptors List
   716                                  ; As stated earlier, each buffer descriptor list is a set of (up to) 32 
   717                                  ; descriptors, each 8 bytes in length.  Bytes 0-3 of a descriptor entry point
   718                                  ; to a chunk of memory to either play from or record to.  Bytes 4-7 of an
   719                                  ; entry describe various control things detailed below.
   720                                  ; 
   721                                  ; Buffer pointers must always be aligned on a Dword boundry.
   722                                  ;
   723                                  ;
   724                                  
   725                                  IOC                     equ     BIT31   ; Fire an interrupt whenever this
   726                                                                          ; buffer is complete.
   727                                  
   728                                  BUP                     equ     BIT30   ; Buffer Underrun Policy.
   729                                                                          ; if this buffer is the last buffer
   730                                                                          ; in a playback, fill the remaining
   731                                                                          ; samples with 0 (silence) or not.
   732                                                                          ; It's a good idea to set this to 1
   733                                                                          ; for the last buffer in playback,
   734                                                                          ; otherwise you're likely to get a lot
   735                                                                          ; of noise at the end of the sound.
   736                                  
   737                                  ;
   738                                  ; Bits 15:0 contain the length of the buffer, in number of samples, which
   739                                  ; are 16 bits each, coupled in left and right pairs, or 32bits each.
   740                                  ; Luckily for us, that's the same format as .wav files.
   741                                  ;
   742                                  ; A value of FFFF is 65536 samples.  Running at 44.1Khz, that's just about
   743                                  ; 1.5 seconds of sample time.  FFFF * 32bits is 1FFFFh bytes or 128k of data.
   744                                  ;
   745                                  ; A value of 0 in these bits means play no samples.
   746                                  ;
   747                                  
   748                                  ;VIA VT8233 (VT8235) AC97 Codec equates 
   749                                  ;(edited by Erdogan Tan, 7/11/2016)
   750                                  
   751                                  ; PCI stuff
   752                                  
   753                                  VIA_VID		equ     1106h           ; VIA's PCI vendor ID
   754                                  VT8233_DID      equ     3059h           ; VT8233 (VT8235) device ID
   755                                  			
   756                                  PCI_IO_BASE          equ 10h
   757                                  AC97_INT_LINE        equ 3Ch
   758                                  VIA_ACLINK_CTRL      equ 41h
   759                                  VIA_ACLINK_STAT      equ 40h
   760                                  VIA_ACLINK_C00_READY equ 01h ; primary codec ready
   761                                  	
   762                                  VIA_REG_AC97	     equ 80h ; dword
   763                                  
   764                                  VIA_ACLINK_CTRL_ENABLE	equ   80h ; 0: disable, 1: enable
   765                                  VIA_ACLINK_CTRL_RESET	equ   40h ; 0: assert, 1: de-assert
   766                                  VIA_ACLINK_CTRL_SYNC	equ   20h ; 0: release SYNC, 1: force SYNC hi
   767                                  VIA_ACLINK_CTRL_VRA	equ   08h ; 0: disable VRA, 1: enable VRA
   768                                  VIA_ACLINK_CTRL_PCM	equ   04h ; 0: disable PCM, 1: enable PCM
   772                                  VIA_ACLINK_CTRL_INIT	equ  (VIA_ACLINK_CTRL_ENABLE +                               VIA_ACLINK_CTRL_RESET +                               VIA_ACLINK_CTRL_PCM +                               VIA_ACLINK_CTRL_VRA)
   773                                  
   774                                  CODEC_AUX_VOL		equ   04h
   775                                  VIA_REG_AC97_BUSY	equ   01000000h ;(1<<24) 
   776                                  VIA_REG_AC97_CMD_SHIFT	equ   10h ; 16
   777                                  VIA_REG_AC97_PRIMARY_VALID equ 02000000h ;(1<<25)
   778                                  VIA_REG_AC97_READ	equ   00800000h ;(1<<23)
   779                                  VIA_REG_AC97_CODEC_ID_SHIFT   equ  1Eh ; 30
   780                                  VIA_REG_AC97_CODEC_ID_PRIMARY equ  0
   781                                  VIA_REG_AC97_DATA_SHIFT equ   0
   782                                  VIADEV_PLAYBACK         equ   0
   783                                  VIA_REG_OFFSET_STATUS   equ   0    ;; byte - channel status
   784                                  VIA_REG_OFFSET_CONTROL  equ   01h  ;; byte - channel control
   785                                  VIA_REG_CTRL_START	equ   80h  ;; WO
   786                                  VIA_REG_CTRL_TERMINATE  equ   40h  ;; WO
   787                                  VIA_REG_CTRL_PAUSE      equ   08h  ;; RW
   788                                  VIA_REG_CTRL_RESET      equ   01h  ;; RW - probably reset? undocumented
   789                                  VIA_REG_OFFSET_STOP_IDX equ   08h  ;; dword - stop index, channel type, sample rate
   790                                  VIA8233_REG_TYPE_16BIT  equ   200000h ;; RW
   791                                  VIA8233_REG_TYPE_STEREO equ   100000h ;; RW
   792                                  VIA_REG_OFFSET_CURR_INDEX equ 0Fh ;; byte - channel current index (for via8233 only)
   793                                  VIA_REG_OFFSET_TABLE_PTR equ  04h  ;; dword - channel table pointer
   794                                  VIA_REG_OFFSET_CURR_PTR equ   04h  ;; dword - channel current pointer
   795                                  VIA_REG_OFS_PLAYBACK_VOLUME_L equ  02h ;; byte
   796                                  VIA_REG_OFS_PLAYBACK_VOLUME_R equ  03h ;; byte
   797                                  VIA_REG_CTRL_AUTOSTART	equ   20h
   798                                  VIA_REG_CTRL_INT_EOL	equ   02h
   799                                  VIA_REG_CTRL_INT_FLAG	equ   01h
   802                                  VIA_REG_CTRL_INT	equ  (VIA_REG_CTRL_INT_FLAG +                               VIA_REG_CTRL_INT_EOL +                               VIA_REG_CTRL_AUTOSTART)
   803                                  ; 24/11/2016
   804                                  VIA_REG_STAT_STOPPED	equ   04h    ;; RWC
   805                                  VIA_REG_STAT_EOL	equ   02h    ;; RWC
   806                                  VIA_REG_STAT_FLAG	equ   01h    ;; RWC
   807                                  VIA_REG_STAT_ACTIVE	equ   80h    ;; RO
   808                                  ; 28/11/2016
   809                                  VIA_REG_STAT_LAST	equ   40h    ;; RO
   810                                  VIA_REG_STAT_TRIGGER_QUEUED equ 08h  ;; RO
   811                                  VIA_REF_CTRL_INT_STOP	equ   04h  ; Interrupt on Current Index = Stop Index
   812                                  				   ; and End of Block	
   813                                  
   814                                  ; CODE
   815                                  
   816                                  ; codec configuration code.  Not much here really.
   817                                  ; NASM version: Erdogan Tan (29/11/2016)
   818                                  
   819                                  ; enable codec, unmute stuff, set output rate to 44.1
   820                                  ; entry: ax = desired sample rate
   821                                  ;
   822                                  codecConfig:
   823                                  	; 15/11/2016
   824                                  	; 14/11/2016
   825                                  	; 12/11/2016 - Erdogan Tan (Ref: KolibriOS, 'setup_codec', codec.inc)
   826                                  
   827                                  	; 14/11/2016 - Erdogan Tan	
   828                                  	; (Ref: Mpxplay, PDSoft, Attila Padar, SC_VIA82.C)
   829                                  ;;;	call	channel_reset
   830                                  
   831 0000031C C606[3D11]00            	mov	byte [err_num], 0
   832                                  
   833 00000321 66B802020000            	mov     eax, 0202h
   834 00000327 66BA02000000            	mov	edx, CODEC_MASTER_VOL_REG ; 02h ; Line Out
   835 0000032D E86901                  	call	codec_write
   836                                  	;jc	cconfig_error
   837                                  
   838 00000330 C606[3D11]01            	mov	byte [err_num], 1
   839                                  
   840 00000335 66B802020000            	mov     eax, 0202h
   841 0000033B 66BA18000000            	mov	edx, CODEC_PCM_OUT_REG ; 18h ; Wave Output (Stereo)
   842 00000341 E85501                  	call	codec_write
   843                                  	;jc	cconfig_error
   844                                        
   845 00000344 C606[3D11]02            	mov	byte [err_num], 2
   846                                  
   847                                   	;xor    eax, eax
   848 00000349 66B802020000            	mov	eax, 0202h
   849 0000034F 66BA04000000            	mov	edx, CODEC_AUX_VOL ; 04h ; CODEC_HP_VOL_REG ; HeadPhone
   850 00000355 E84101                  	call	codec_write
   851                                  	;jc	cconfig_error
   852                                  
   853 00000358 C606[3D11]03            	mov	byte [err_num], 3
   854                                  
   855 0000035D B80800                          mov     ax,  08h
   856 00000360 66BA0C000000                    mov	edx, 0Ch  ; AC97_PHONE_VOL ; TAD Input (Mono)
   857 00000366 E83001                  	call	codec_write
   858                                  	;jc	short cconfig_error
   859                                  
   860 00000369 C606[3D11]04            	mov	byte [err_num], 4
   861                                  
   862 0000036E B80808                          mov     ax,  0808h
   863 00000371 66BA10000000                    mov	edx, CODEC_LINE_IN_VOL_REG ; 10h ; Line Input (Stereo)	
   864 00000377 E81F01                  	call	codec_write
   865                                  	;jc	short cconfig_error
   866                                  
   867 0000037A C606[3D11]05            	mov	byte [err_num], 5
   868                                  
   869 0000037F B80808                  	mov     ax,  0808h
   870 00000382 66BA12000000                    mov	edx, CODEC_CD_VOL_REG ; 12h ; CR Input (Stereo)
   871 00000388 E80E01                  	call	codec_write
   872                                  	;jc	short cconfig_error
   873                                  
   874 0000038B C606[3D11]06            	mov	byte [err_num], 6
   875                                  
   876 00000390 B80808                  	mov     ax,  0808h
   877 00000393 66BA16000000                    mov	edx, CODEC_AUX_VOL_REG ; 16h ; Aux Input (Stereo)
   878 00000399 E8FD00                  	call	codec_write
   879                                  	;jc	short cconfig_error
   880                                  
   881 0000039C C606[3D11]07            	mov	byte [err_num], 7
   882                                  
   883                                  	; Extended Audio Status (2Ah)
   884 000003A1 66B82A000000            	mov	eax, CODEC_EXT_AUDIO_CTRL_REG ; 2Ah 
   885 000003A7 E8C300                  	call	codec_read
   886 000003AA 6625FDFF0000                    and     eax, 0FFFFh - 2			; clear DRA (BIT1)
   887                                          ;or     eax, 1				; set VRA (BIT0)
   888 000003B0 6683C805                	or	eax, 5  	; VRA (BIT0) & S/PDIF (BIT2) ; 14/11/2016
   889 000003B4 66BA2A000000            	mov	edx, CODEC_EXT_AUDIO_CTRL_REG
   890 000003BA E8DC00                  	call	codec_write
   891                                  	;jc	short cconfig_error
   892                                  
   893 000003BD C606[3D11]08            	mov	byte [err_num], 8
   894                                  set_sample_rate:
   895 000003C2 6631C0                          xor	eax, eax
   896 000003C5 A1[8C26]                	mov	ax, [sample_rate]
   897 000003C8 66BA2C000000            	mov	edx, CODEC_PCM_FRONT_DACRATE_REG ; 2Ch ; PCM Front DAC Rate
   898                                          ;call	codec_write
   899                                          ;retn
   900 000003CE E9C800                  	jmp	codec_write
   901                                  	
   902                                  cconfig_error:
   903 000003D1 A0[3D11]                	mov	al, [err_num]
   904 000003D4 C3                              retn
   905                                  
   906                                  reset_codec:
   907                                  	; 12/11/2016 - Erdogan Tan (Ref: KolibriOS, vt823x.asm)
   908 000003D5 66A1[3E11]              	mov	eax, [bus_dev_fn]
   909 000003D9 B041                     	mov	al, VIA_ACLINK_CTRL
   910 000003DB B2E0                           	mov	dl, VIA_ACLINK_CTRL_ENABLE + VIA_ACLINK_CTRL_RESET + VIA_ACLINK_CTRL_SYNC
   911                                  
   912 000003DD E8DFFE                  	call	pciRegWrite8
   913                                  
   914 000003E0 E84A00                  	call	delay_100ms 	; wait 100 ms
   915                                  _rc_cold:
   916 000003E3 E80C00                          call    cold_reset
   917 000003E6 7304                            jnc     short _reset_codec_ok
   918                                  
   919 000003E8 6631C0                          xor     eax, eax         ; timeout error
   920 000003EB C3                              retn
   921                                  
   922                                  _reset_codec_ok:
   923 000003EC 6631C0                          xor     eax, eax
   924                                          ;mov	al, VIA_ACLINK_C00_READY ; 1
   925 000003EF FEC0                            inc	al
   926 000003F1 C3                      	retn
   927                                  
   928                                  cold_reset:
   929                                  	; 12/11/2016 - Erdogan Tan (Ref: KolibriOS, vt823x.asm)
   930                                  	;mov	eax, [bus_dev_fn]
   931                                  	;mov	al, VIA_ACLINK_CTRL
   932 000003F2 30D2                    	xor	dl, dl ; 0
   933 000003F4 E8C8FE                  	call	pciRegWrite8
   934                                  
   935 000003F7 E83300                  	call	delay_100ms 	; wait 100 ms
   936                                  
   937                                  	;; ACLink on, deassert ACLink reset, VSR, SGD data out
   938                                          ;; note - FM data out has trouble with non VRA codecs !!
   939                                          
   940                                  	;mov	eax, [bus_dev_fn]
   941                                  	;mov	al, VIA_ACLINK_CTRL
   942                                  
   943 000003FA B2CC                    	mov	dl, VIA_ACLINK_CTRL_INIT
   944                                  
   945 000003FC E8C0FE                  	call	pciRegWrite8
   946                                  
   947 000003FF 66B910000000            	mov	ecx, 16	; total 2s
   948                                  
   949                                  _crst_wait:
   950 00000405 6651                    	push	ecx
   951                                  
   952                                  	;mov	eax, [bus_dev_fn]
   953 00000407 B040                    	mov	al, VIA_ACLINK_STAT
   954 00000409 E841FE                  	call	pciRegRead8	
   955                                  
   956 0000040C F6C201                          test    dl, VIA_ACLINK_C00_READY
   957 0000040F 750B                            jnz     short _crst_ok
   958                                  
   959 00000411 E81900                  	call	delay_100ms
   960                                  
   961 00000414 6659                    	pop	ecx
   962                                  
   963 00000416 6649                            dec     ecx
   964 00000418 75EB                            jnz     short _crst_wait
   965                                  
   966                                  _crst_fail:
   967 0000041A F9                              stc
   968 0000041B C3                              retn
   969                                  
   970                                  _crst_ok:
   971 0000041C 6659                    	pop	ecx
   972                                  
   973                                  	; are these necessary ? - 14/11/2016 - Erdogan Tan
   974                                  
   975                                  	;mov	eax, [bus_dev_fn]
   976                                  	;mov	al, VIA_ACLINK_CTRL
   977 0000041E E82CFE                  	call	pciRegRead8
   978                                  
   979                                  	;mov	eax, [bus_dev_fn]
   980                                  	;mov	al, VIA_ACLINK_STAT
   981 00000421 E829FE                  	call	pciRegRead8
   982                                  
   983 00000424 660FB6C2                	movzx	eax, dl
   984 00000428 2401                    	and     al, VIA_ACLINK_C00_READY ; 1
   985 0000042A 74EE                    	jz	short _crst_fail
   986                                  
   987 0000042C C3                      	retn
   988                                  
   989                                  delay_100ms:
   990                                  	; wait 100 ms
   991 0000042D 66B919000000            	mov	ecx, 25
   992                                  _delay_x_ms:
   993 00000433 6651                    	push	ecx
   994 00000435 E8D908                  	call	delay1_4ms
   995 00000438 6659                    	pop	ecx
   996 0000043A E2F7                            loop	_delay_x_ms
   997 0000043C C3                      	retn
   998                                  
   999                                  codec_io_w16: ;w32
  1000 0000043D 8B16[4A11]                      mov	dx, [ac97_io_base]
  1001 00000441 81C28000                        add     dx, VIA_REG_AC97
  1002 00000445 66EF                            out     dx, eax
  1003 00000447 C3                              retn
  1004                                  
  1005                                  codec_io_r16: ;r32
  1006 00000448 8B16[4A11]                      mov     dx, [ac97_io_base]
  1007 0000044C 81C28000                        add     dx, VIA_REG_AC97
  1008 00000450 66ED                            in      eax, dx
  1009 00000452 C3                              retn
  1010                                  
  1011                                  ctrl_io_w8:
  1012 00000453 0316[4A11]                      add     dx, [ac97_io_base]
  1013 00000457 EE                              out     dx, al
  1014 00000458 C3                              retn
  1015                                  
  1016                                  ctrl_io_r8:
  1017 00000459 0316[4A11]                      add     dx, [ac97_io_base]
  1018 0000045D EC                              in      al, dx
  1019 0000045E C3                              retn
  1020                                  
  1021                                  ctrl_io_w32:
  1022 0000045F 0316[4A11]                      add     dx, [ac97_io_base]
  1023 00000463 66EF                            out     dx, eax
  1024 00000465 C3                              retn
  1025                                  
  1026                                  ctrl_io_r32:
  1027 00000466 0316[4A11]                      add	dx, [ac97_io_base]
  1028 0000046A 66ED                            in	eax, dx
  1029 0000046C C3                              retn
  1030                                  
  1031                                  codec_read:
  1032                                  	; 12/11/2016 - Erdogan Tan (Ref: KolibriOS, vt823x.asm)
  1033                                          ; Use only primary codec.
  1034                                          ; eax = register
  1035 0000046D 66C1E010                        shl     eax, VIA_REG_AC97_CMD_SHIFT
  1036 00000471 660D00008002                    or      eax, VIA_REG_AC97_PRIMARY_VALID + VIA_REG_AC97_READ
  1037                                  
  1038 00000477 E8C3FF                  	call    codec_io_w16
  1039                                  
  1040                                        	; codec_valid
  1041 0000047A E83700                  	call	codec_check_ready
  1042 0000047D 7301                            jnc	short _cr_ok
  1043                                  
  1044 0000047F C3                      	retn
  1045                                  
  1046                                  _cr_ok:
  1047                                  	; wait 25 ms
  1048 00000480 E88E08                  	call	delay1_4ms
  1049 00000483 E88B08                  	call	delay1_4ms
  1050 00000486 E88808                  	call	delay1_4ms
  1051 00000489 E88508                  	call	delay1_4ms
  1052 0000048C E88208                  	call	delay1_4ms
  1053                                  
  1054 0000048F E8B6FF                          call    codec_io_r16
  1055 00000492 6625FFFF0000                    and     eax, 0FFFFh
  1056 00000498 C3                              retn
  1057                                  
  1058                                  codec_write:
  1059                                  	; 12/11/2016 - Erdogan Tan (Ref: KolibriOS, vt823x.asm)
  1060                                          ; Use only primary codec.
  1061                                          
  1062                                  	; eax = data (volume)
  1063                                  	; edx = register (mixer register)
  1064                                  	
  1065 00000499 66C1E210                	shl     edx, VIA_REG_AC97_CMD_SHIFT
  1066                                  
  1067 0000049D 66C1E000                        shl     eax, VIA_REG_AC97_DATA_SHIFT ; shl eax, 0
  1068 000004A1 6609C2                          or      edx, eax
  1069                                  
  1070 000004A4 66B800000000                    mov     eax, VIA_REG_AC97_CODEC_ID_PRIMARY
  1071 000004AA 66C1E01E                        shl     eax, VIA_REG_AC97_CODEC_ID_SHIFT
  1072 000004AE 6609D0                          or      eax, edx
  1073                                  
  1074 000004B1 E889FF                          call    codec_io_w16
  1075                                          ;mov    [codec.regs+esi], ax
  1076                                  
  1077                                          ;call	codec_check_ready
  1078                                         	;retn
  1079                                  	;jmp	short _codec_check_ready	
  1080                                  
  1081                                  codec_check_ready:
  1082                                  	; 12/11/2016 - Erdogan Tan (Ref: KolibriOS, vt823x.asm)
  1083                                  
  1084                                  _codec_check_ready:
  1085 000004B4 66B914000000            	mov	ecx, 20	; total 2s
  1086                                  _ccr_wait:
  1087 000004BA 6651                    	push	ecx
  1088                                  
  1089 000004BC E889FF                          call    codec_io_r16
  1090 000004BF 66A900000001                    test    eax, VIA_REG_AC97_BUSY
  1091 000004C5 740B                            jz      short _ccr_ok
  1092                                  
  1093 000004C7 E863FF                  	call	delay_100ms
  1094                                  
  1095 000004CA 6659                    	pop	ecx
  1096                                  
  1097 000004CC 6649                    	dec     ecx
  1098 000004CE 75EA                            jnz     short _ccr_wait
  1099                                  
  1100 000004D0 F9                              stc
  1101 000004D1 C3                              retn
  1102                                  
  1103                                  _ccr_ok:
  1104 000004D2 6659                    	pop	ecx
  1105 000004D4 6625FFFF0000            	and     eax, 0FFFFh
  1106 000004DA C3                              retn
  1107                                  
  1108                                  channel_reset:
  1109                                  	; 14/11/2016 - Erdogan Tan
  1110                                  	; 12/11/2016 - Erdogan Tan (Ref: KolibriOS, vt823x.asm)
  1111 000004DB 66BA01000000                    mov	edx, VIA_REG_OFFSET_CONTROL
  1112 000004E1 66B849000000                    mov     eax, VIA_REG_CTRL_PAUSE + VIA_REG_CTRL_TERMINATE + VIA_REG_CTRL_RESET
  1113 000004E7 E869FF                          call    ctrl_io_w8
  1114                                  
  1115                                          ;mov	edx, VIA_REG_OFFSET_CONTROL
  1116                                          ;call   ctrl_io_r8
  1117                                  
  1118 000004EA 66B90C000000            	mov	ecx, 12 ; 50 ms	
  1119                                  _ch_rst_wait:
  1120 000004F0 6651                    	push	ecx
  1121 000004F2 E81C08                  	call	delay1_4ms
  1122 000004F5 6659                    	pop	ecx
  1123 000004F7 6649                    	dec	ecx
  1124 000004F9 75F5                    	jnz	short _ch_rst_wait     
  1125                                  
  1126                                          ; disable interrupts
  1127 000004FB 66BA01000000                    mov	edx, VIA_REG_OFFSET_CONTROL
  1128 00000501 6631C0                          xor     eax, eax
  1129 00000504 E84CFF                          call    ctrl_io_w8
  1130                                  
  1131                                          ; clear interrupts
  1132 00000507 66BA00000000                    mov	edx, VIA_REG_OFFSET_STATUS
  1133                                  	;mov	eax, 3
  1134 0000050D 66B8FF000000                    mov     eax, 0FFh ; 14/11/2016 - SC_VIA82.C (Attila Padar)
  1135 00000513 E83DFF                          call	ctrl_io_w8
  1136                                  
  1137                                  	; 14/11/2016 (Ref: Attila Padar, Mpxplay, SC_VIA82.C)
  1138 00000516 66BA04000000            	mov	edx, VIA_REG_OFFSET_CURR_PTR
  1139 0000051C 6631C0                  	xor	eax, eax
  1140 0000051F E83DFF                  	call	ctrl_io_w32
  1141                                  
  1142 00000522 C3                              retn
  1143                                  
  1144                                  ;=============================================================================
  1145                                  ;               VIA_WAV.ASM
  1146                                  ;=============================================================================
  1147                                  
  1148                                  ; DOS based .WAV player using AC'97 and codec interface.
  1149                                  ; ---------------------------------------------------------------
  1150                                  ; VIA VT8233 Modification & NASM version: Erdogan Tan (29/11/2016)
  1151                                  ; Last Update: 08/12/2016 (by Erdogan Tan)
  1152                                  
  1153                                  ; player internal variables and other equates.
  1154                                  BUFFERSIZE      equ     2048		; 2K half buffer size. ; 13/02/2017
  1155                                  ENDOFFILE       equ     BIT0            ; flag for knowing end of file
  1156                                  
  1157                                  ;===========================================================================
  1158                                  ; entry: none.  File is already open and [filehandle] filled.
  1159                                  ; exit:  not until the song is finished or the user aborts.
  1160                                  ;
  1161                                  ModPlay: ; 13/02/2017  ; ModPlay Polling!
  1162                                  	;cld
  1163                                  	; clear (half) buffer 2
  1164 00000523 8B3E[3A11]                     	mov     di, [DMA_BUFFER2]
  1165 00000527 29C0                    	sub	ax, ax
  1166 00000529 B90004                  	mov	cx, (BUFFERSIZE/2)
  1167 0000052C F3AB                    	rep	stosw
  1168                                  	
  1169                                         ; load 2048 bytes into buffer 1
  1170                                  
  1171 0000052E 8B36[3811]                      mov     si, [DMA_BUFFER1]
  1172 00000532 B90008                  	mov	cx, BUFFERSIZE
  1173                                  
  1174 00000535 1E                      	push	ds ; segment
  1175 00000536 56                      	push	si ; offset
  1176 00000537 51                      	push	cx ; count
  1177 00000538 E8E406                  	call    GetSamples
  1178                                  
  1179                                         ; load 2048 bytes into buffer 1
  1180                                  
  1181                                  	;mov	si, [DMA_BUFFER2]
  1182                                  	;mov	cx, BUFFERSIZE
  1183                                  	;push	ds ; segment
  1184                                  	;push	si ; offset
  1185                                  	;push	cx ; count
  1186                                  	;call	GetSamples
  1187                                  
  1188                                  ; write last valid index to 31 to start with.
  1189                                  ; The Last Valid Index register tells the DMA engine when to stop playing.
  1190                                  ; 
  1191                                  ; As we progress through the song we change the last valid index to always be
  1192                                  ; something other than the index we're currently playing.  
  1193                                  ;
  1194                                          ;;mov   al, 1
  1195                                          ;mov	al, 31
  1196                                  	;call   setLastValidIndex
  1197                                  
  1198                                  ; create Buffer Descriptor List
  1199                                  ;
  1200                                  ; A buffer descriptor list is a list of pointers and control bits that the
  1201                                  ; DMA engine uses to know where to get the .wav data and how to play it.
  1202                                  ;
  1203                                  ; I set it up to use only 2 buffers of .wav data, and whenever 1 buffer is
  1204                                  ; playing, I refresh the other one with good data.
  1205                                  ;
  1206                                  ;
  1207                                  ; For the control bits, you can specify that the DMA engine fire an interrupt
  1208                                  ; after a buffer has been processed, but I poll the current index register
  1209                                  ; to know when it's safe to update the other buffer.
  1210                                  ;
  1211                                  ; I set the BUP bit, which tells the DMA engine to just play 0's (silence)
  1212                                  ; if it ever runs out of data to play.  Good for safety.
  1213                                  ;
  1214                                  	; 14/02/2017
  1215 0000053B 8B3E[3611]                      mov     di, [BDL_BUFFER]		; get BDL address
  1216 0000053F B91000                          mov     cx, 32 / 2                      ; make 32 entries in BDL
  1217 00000542 6631D2                  	xor	edx, edx
  1218 00000545 8CDA                    	mov	dx, ds
  1219 00000547 66C1E204                	shl	edx, 4 ; segment*16 (linear/physical address of the segment)
  1220                                  _0:
  1221                                  
  1222                                  ; set buffer descriptor 0 to start of data file in memory
  1223                                  	; 14/02/2017
  1224 0000054B 660FB706[3811]                  movzx   eax, word [DMA_BUFFER1]
  1225 00000551 6601D0                  	add	eax, edx ; linear/physical address of the buffer (seg*16+off)
  1226 00000554 66AB                            stosd					; store dmabuffer1 address
  1227                                  
  1228                                  ;
  1229                                  ; set length to 32k samples.  1 sample is 16bits or 2bytes.
  1230                                  ; Set control (bits 31:16) to BUP, bits 15:0=number of samples.
  1231                                  ; 
  1232                                  
  1233                                  ; VIA VT8235.PDF: (Page 110) (Erdogan Tan, 29/11/2016)
  1234                                  	;
  1235                                  	; 	Audio SGD Table Format
  1236                                  	;	-------------------------------
  1237                                  	;	63   62    61-56    55-32  31-0
  1238                                  	;	--   --   --------  -----  ----
  1239                                  	;	EOL FLAG -reserved- Base   Base
  1240                                  	;			    Count  Address
  1241                                  	;			    [23:0] [31:0]
  1242                                  	;	EOL: End Of Link. 
  1243                                  	;	     1 indicates this block is the last of the link.
  1244                                  	;	     If the channel “Interrupt on EOL” bit is set, then
  1245                                  	;	     an interrupt is generated at the end of the transfer.
  1246                                  	;
  1247                                  	;	FLAG: Block Flag. If set, transfer pauses at the end of this
  1248                                  	;	      block. If the channel “Interrupt on FLAG” bit is set,
  1249                                  	;	      then an interrupt is generated at the end of this block.
  1250                                  
  1251                                  	FLAG	EQU BIT30
  1252                                  	EOL	EQU BIT31
  1253                                  
  1254                                  	; 08/12/2016 - Erdogan Tan
  1255 00000556 66B800080000            	mov	eax, BUFFERSIZE
  1256 0000055C 660D00000040            	or	eax, FLAG
  1257                                  	;or	eax, EOL
  1258 00000562 66AB                    	stosd
  1259                                  
  1260                                  ; 2nd buffer:
  1261                                  	; 14/02/2017
  1262 00000564 660FB706[3A11]                  movzx   eax, word [DMA_BUFFER2]
  1263 0000056A 6601D0                  	add	eax, edx ; linear/physical address of the buffer (seg*16+off)
  1264 0000056D 66AB                            stosd					; store dmabuffer2 address
  1265                                  
  1266                                  ; set length to 64k (32k of two 16 bit samples)
  1267                                  ; Set control (bits 31:16) to BUP, bits 15:0=number of samples
  1268                                  ; 
  1269                                  	; 08/12/2016 - Erdogan Tan
  1270 0000056F 66B800080000            	mov	eax, BUFFERSIZE
  1271 00000575 660D00000080            	or	eax, EOL
  1272                                  	;or	eax, FLAG
  1273 0000057B 66AB                    	stosd
  1274                                  
  1275 0000057D E2CC                            loop    _0
  1276                                  
  1277                                  ;
  1278                                  ; tell the DMA engine where to find our list of Buffer Descriptors.
  1279                                  ; this 32bit value is a flat mode memory offset (ie no segment:offset)
  1280                                  ;
  1281                                  ; write buffer descriptor list address
  1282                                  ;
  1283 0000057F 660FB706[3611]                  movzx   eax, word [BDL_BUFFER]
  1284                                  	; 14/02/2017
  1285 00000585 6601D0                  	add	eax, edx ; linear/physical address of the BDL
  1286                                    
  1287                                  	; 12/11/2016 - Erdogan Tan 
  1288                                  	; (Ref: KolibriOS, vt823x.asm, 'create_primary_buff')
  1289 00000588 66BA04000000            	mov     edx, VIADEV_PLAYBACK + VIA_REG_OFFSET_TABLE_PTR
  1290 0000058E E8CEFE                          call    ctrl_io_w32
  1291                                  
  1292 00000591 E820FF                  	call	codec_check_ready
  1293                                  
  1294 00000594 BA0200                    	mov     dx, VIADEV_PLAYBACK + VIA_REG_OFS_PLAYBACK_VOLUME_L
  1295 00000597 66B802000000                    mov     eax, 2   ;31
  1296 0000059D E8B3FE                          call    ctrl_io_w8
  1297                                  
  1298 000005A0 E811FF                  	call	codec_check_ready
  1299                                  
  1300 000005A3 BA0300                          mov     dx, VIADEV_PLAYBACK + VIA_REG_OFS_PLAYBACK_VOLUME_R
  1301 000005A6 B80200                          mov     ax, 2   ;31
  1302 000005A9 E8A7FE                          call    ctrl_io_w8
  1303                                  
  1304 000005AC E805FF                  	call	codec_check_ready
  1305                                  ;
  1306                                  ;
  1307                                  ; All set.  Let's play some music.
  1308                                  ;
  1309                                  ;
  1310                                         	;mov    dx, VIADEV_PLAYBACK + VIA_REG_OFFSET_STOP_IDX
  1311                                          ;mov    ax, VIA8233_REG_TYPE_16BIT or VIA8233_REG_TYPE_STEREO or 0xfffff or 0xff000000
  1312                                          ;call   ctrl_io_w32
  1313                                  
  1314                                  	;call	codec_check_ready
  1315                                  
  1316                                  	; 08/12/2016
  1317                                  	; 07/10/2016
  1318                                          ;mov    al, 1
  1319 000005AF B01F                            mov	al, 31
  1320 000005B1 E8D300                  	call    setLastValidIndex
  1321                                  
  1322 000005B4 C606[3511]01            	mov	byte [tLoop], 1 ; 30/11/2016
  1323                                  
  1324 000005B9 B82300                          mov	ax, VIA_REG_CTRL_INT
  1325 000005BC 660D80000000                   	or	eax, VIA_REG_CTRL_START
  1326                                          ;mov	ax, VIA_REG_CTRL_AUTOSTART + VIA_REG_CTRL_START
  1327                                  	; 28/11/2016
  1328                                  	;mov	ax, VIA_REG_CTRL_AUTOSTART + VIA_REG_CTRL_START + VIA_REG_CTRL_INT_FLAG
  1329 000005C2 BA0100                  	mov     dx, VIADEV_PLAYBACK + VIA_REG_OFFSET_CONTROL
  1330 000005C5 E88BFE                          call    ctrl_io_w8
  1331                                  
  1332 000005C8 E8E9FE                  	call	codec_check_ready
  1333                                  
  1334                                  ; while DMA engine is running, examine current index and wait until it hits 1
  1335                                  ; as soon as it's 1, we need to refresh the data in wavbuffer1 with another
  1336                                  ; 64k.  Likewise when it's playing buffer 2, refresh buffer 1 and repeat.
  1337                                     
  1338                                  	; 14/02/2017
  1339                                  	; 13/02/2017
  1340                                  	; 08/12/2016
  1341                                  	; 28/11/2016
  1342                                  
  1343 000005CB 06                      	push	es
  1344 000005CC B800A0                  	mov	ax, 0A000h
  1345 000005CF 8EC0                    	mov	es, ax
  1346 000005D1 BD[4C12]                	mov	bp, DmaBuffer ; 14/02/2017
  1347                                  p_loop:
  1348 000005D4 B401                    	mov     ah, 1			; any key pressed?
  1349 000005D6 CD16                    	int     16h			; no, Loop.
  1350 000005D8 740B                    	jz	short q_loop
  1351                                  
  1352 000005DA B400                    	mov     ah, 0			; flush key buffer...
  1353 000005DC CD16                    	int     16h
  1354                                  p_return:
  1355 000005DE C606[3511]00            	mov	byte [tLoop], 0	; 13/02/2017
  1356 000005E3 07                      	pop	es
  1357 000005E4 C3                      	retn
  1358                                  q_loop:
  1359 000005E5 31C0                    	xor	ax, ax
  1360 000005E7 8606[1F10]              	xchg	al, [tBuff] ; AL = [tBuff], [tBuff] = 0
  1361 000005EB 3C01                    	cmp	al, 1
  1362 000005ED 7708                    	ja	short r_loop
  1363 000005EF 7215                    	jb	short ScopeLoop
  1364                                  	;
  1365 000005F1 8B36[3811]                   	mov	si, [DMA_BUFFER1] ; [tBuff]=1 (from tuneLoop)
  1366 000005F5 EB04                           	jmp	short s_loop 
  1367                                  r_loop:
  1368                                  	; 13/02/2017
  1369 000005F7 8B36[3A11]                      mov     si, [DMA_BUFFER2] ; [tBuff]=2 (from tuneLoop)
  1370                                  s_loop:
  1371                                  	; 14/02/2017
  1372 000005FB 89F5                    	mov	bp, si ; save current buffer addres in bp register
  1373 000005FD B90008                  	mov	cx, BUFFERSIZE ; 2048 byte
  1374 00000600 1E                      	push	ds ; segment
  1375 00000601 56                      	push	si ; offset
  1376 00000602 51                      	push	cx ; count
  1377 00000603 E81906                  	call    GetSamples
  1378                                  	;
  1379                                  ScopeLoop:
  1380 00000606 89EE                    	mov     si, bp			; get current samples
  1381 00000608 31C9                    	xor     cx, cx			; to be drawed ...
  1382 0000060A 31D2                    	xor     dx, dx
  1383                                  DrawLoop:       
  1384 0000060C 89D3                    	mov     bx, dx			; (save Index)
  1385 0000060E 8BBF[E080]              	mov     di, [Scope+bx]		; get old SCOPE pixel address
  1386 00000612 26C60500                	mov     byte [es:di], 0		; erase it!
  1387 00000616 AC                      	lodsb				; get a sample (8-bit)
  1388 00000617 88C3                    	mov     bl, al			; calc new pixel address...
  1389 00000619 30FF                    	xor     bh, bh
  1390 0000061B D1E3                    	shl     bx, 1
  1391 0000061D 8BBF[6083]              	mov     di, [RowOfs+bx]
  1392 00000621 01CF                    	add     di, cx
  1393 00000623 89D3                    	mov     bx, dx			; (restore Index)
  1394 00000625 89BF[E080]              	mov     [Scope+bx], di		; save new address...
  1395 00000629 26C6050A                	mov     byte [es:di], 10	; and DRAW.
  1396 0000062D 83C202                  	add     dx, 2			; the next pixel...
  1397 00000630 41                      	inc     cx
  1398 00000631 81F94001                	cmp     cx, 320			; 320 pixels drawed?
  1399 00000635 72D5                    	jb      short DrawLoop
  1400 00000637 EB9B                    	jmp	short p_loop
  1401                                  
  1402                                  tuneLoop:
  1403                                  	; 08/12/2016
  1404                                  	; 28/11/2016 - Erdogan Tan
  1405                                  	
  1406 00000639 803E[3511]01            	cmp	byte [tLoop], 1
  1407 0000063E 7237                    	jb	short _exit
  1408                                  
  1409 00000640 C606[1F10]01            	mov	byte [tBuff], 1 ; Buffer 1
  1410                                  
  1411 00000645 F606[3311]02            	test	byte [irq_status], VIA_REG_STAT_EOL 
  1412 0000064A 7406                    	jz	short _tlp1 ; FLAG
  1413                                  	
  1414                                  	; EOL
  1415 0000064C FE06[1F10]              	inc	byte [tBuff] ; Buffer 2
  1416 00000650 FEC0                    	inc	al
  1417                                  _tlp1: 
  1418 00000652 F606[3311]01            	test	byte [irq_status], VIA_REG_STAT_FLAG 
  1419 00000657 740F                    	jz	short _tlp2
  1420                                  
  1421 00000659 B82300                  	mov	ax, VIA_REG_CTRL_INT
  1422 0000065C 0D8000                         	or	ax, VIA_REG_CTRL_START
  1423 0000065F BA0100                         	mov     dx, VIADEV_PLAYBACK + VIA_REG_OFFSET_CONTROL
  1424 00000662 E8EEFD                          call    ctrl_io_w8
  1425                                  
  1426 00000665 E84CFE                  	call	codec_check_ready
  1427                                  _tlp2:	
  1428 00000668 A0[3311]                        mov     al, [irq_status]   ;; ack ;;
  1429 0000066B BA0000                          mov     dx, VIADEV_PLAYBACK + VIA_REG_OFFSET_STATUS
  1430 0000066E E8E2FD                          call    ctrl_io_w8
  1431                                  
  1432 00000671 C3                      	retn
  1433                                  
  1434                                  _exit_:
  1435 00000672 C606[3511]00            	mov	byte [tLoop], 0
  1436                                  _exit:
  1437                                          ; finished with song, stop everything
  1438 00000677 B82300                  	mov     ax, VIA_REG_CTRL_INT
  1439 0000067A 83C840                          or      ax, VIA_REG_CTRL_TERMINATE
  1440 0000067D BA0100                  	mov     dx, VIADEV_PLAYBACK + VIA_REG_OFFSET_CONTROL
  1441 00000680 E8D0FD                          call    ctrl_io_w8
  1442                                  
  1443 00000683 E855FE                          call	channel_reset
  1444                                  _return:
  1445 00000686 C3                      	retn
  1446                                  
  1447                                  ;input AL = index # to stop on
  1448                                  setLastValidIndex:
  1449                                  	; 19/11/2016
  1450                                  	; 14/11/2016 - Erdogan Tan (Ref: VIA VT8235.PDF, Page 110)
  1451                                  	; 12/11/2016 - Erdogan Tan
  1452                                  	; (Ref: KolibriOS, vt823x.asm, 'create_primary_buff')
  1453                                  	;push	edx
  1454 00000687 50                      	push	ax
  1455                                  	;push	ecx
  1456 00000688 660FB706[8C26]          	movzx	eax, word [sample_rate] ; Hertz
  1457 0000068E 66BA00001000            	mov	edx, 100000h ; 2^20 = 1048576
  1458 00000694 66F7E2                  	mul	edx
  1459 00000697 66B980BB0000            	mov	ecx, 48000	
  1460 0000069D 66F7F1                  	div	ecx
  1461                                  	;and	eax, 0FFFFFh
  1462                                  	;pop	ecx
  1463 000006A0 5A                      	pop	dx 
  1464 000006A1 66C1E218                	shl	edx, 24  ; STOP Index Setting: Bit 24 to 31
  1465 000006A5 6609D0                  	or	eax, edx
  1466                                  	; 19/11/2016
  1467 000006A8 803E[1511]10            	cmp	byte [bps], 16
  1468 000006AD 7506                    	jne	short sLVI_1
  1469 000006AF 660D00002000            	or	eax, VIA8233_REG_TYPE_16BIT
  1470                                  sLVI_1:
  1471 000006B5 803E[1411]02            	cmp	byte [stmo], 2
  1472 000006BA 7506                    	jne	short sLVI_2
  1473 000006BC 660D00001000            	or	eax, VIA8233_REG_TYPE_STEREO
  1474                                  sLVI_2:
  1475 000006C2 66BA08000000            	mov     edx, VIADEV_PLAYBACK + VIA_REG_OFFSET_STOP_IDX
  1476 000006C8 E894FD                          call    ctrl_io_w32
  1477 000006CB E8E6FD                  	call	codec_check_ready
  1478                                  	;pop	edx
  1479 000006CE C3                      	retn
  1480                                  
  1481                                  ;=============================================================================
  1482                                  ;               MODLOAD.ASM
  1483                                  ;=============================================================================
  1484                                  
  1485                                  ; Amiga Module Loader v0.1b by Carlos Hasan.
  1486                                  ;		July 10th, 1993.
  1487                                  
  1488                                  ; STRUCTURES
  1489                                  
  1490                                  struc ModSample
  1491 00000000 <res 00000016>          .msName:	resb 22
  1492 00000016 <res 00000002>          .msLength:	resw 1
  1493 00000018 <res 00000001>          .msFinetune:	resb 1
  1494 00000019 <res 00000001>          .msVolume:	resb 1
  1495 0000001A <res 00000002>          .msRepeat:	resw 1
  1496 0000001C <res 00000002>          .msRepLen:	resw 1
  1497                                  .size:
  1498                                  endstruc
  1499                                  
  1500                                  struc ModHeader
  1501 00000000 <res 00000014>          .mhName:	resb 20
  1502 00000014 <res 000003A2>          .mhSamples:	resb ModSample.size*31
  1503 000003B6 <res 00000001>          .mhOrderLen:	resb 1
  1504 000003B7 <res 00000001>          .mhReStart:	resb 1
  1505 000003B8 <res 00000080>          .mhOrder:	resb 128
  1506 00000438 <res 00000004>          .mhSign:	resw 2
  1507                                  .size:	
  1508                                  endstruc
  1509                                  
  1510                                  struc ModInfoRec
  1511 00000000 <res 00000001>          .OrderLen:	resb 1
  1512 00000001 <res 00000001>          .ReStart:	resb 1
  1513 00000002 <res 00000080>          .Order:		resb 128
  1514 00000082 <res 00000004>          .Patterns:	resd 1
  1515 00000086 <res 0000003E>          .SampOfs:	resw 31
  1516 000000C4 <res 0000003E>          .SampSeg:	resw 31
  1517 00000102 <res 0000003E>          .SampLen:	resw 31
  1518 00000140 <res 0000003E>          .SampRep:	resw 31
  1519 0000017E <res 0000003E>          .SampRepLen:	resw 31
  1520 000001BC <res 0000003E>          .SampVol:	resw 31
  1521                                  .size:	
  1522                                  endstruc
  1523                                  
  1524                                  ; CODE
  1525                                  
  1526                                  LoadModule:
  1527                                  		;es:di = filename
  1528                                  
  1529                                  		;[sp+4] = es
  1530                                  		;[sp+2] = di
  1531                                  
  1532                                  		FileName equ 4		
  1533                                  
  1534 000006CF 55                      		push    bp
  1535 000006D0 89E5                    		mov     bp, sp
  1536 000006D2 60                      		pusha
  1537 000006D3 1E                      		push    ds
  1538 000006D4 06                      		push    es
  1539                                  
  1540 000006D5 C706[4E22]0100          		mov	word [ErrorInfo], 1
  1541                                  
  1542 000006DB E85101                  		call    ClearModInfo
  1543                                  OpenFile:       
  1544 000006DE 1E                      		push    ds
  1545 000006DF B8003D                  		mov     ax, 3D00h
  1546 000006E2 C55604                  		lds     dx, [bp+FileName]
  1547 000006E5 CD21                    		int     21h
  1548 000006E7 1F                      		pop     ds
  1549 000006E8 0F823C01                		jc      Failed
  1550 000006EC A3[4C22]                		mov     [FileHandle], ax
  1551                                  
  1552                                  ReadHeader:     
  1553 000006EF B8003F                  		mov     ax, 3F00h
  1554 000006F2 8B1E[4C22]              		mov     bx, [FileHandle]
  1555 000006F6 B93C04                  		mov     cx, ModHeader.size
  1556                                  		;lea    dx, [Header]
  1557 000006F9 BA[5022]                		mov	dx, Header
  1558 000006FC CD21                    		int     21h
  1559 000006FE 0F821D01                		jc      CloseFile
  1560                                  CheckMK:        
  1561 00000702 813E[8826]4D2E          		cmp     word [Header+ModHeader.mhSign], 'M.'
  1562 00000708 7508                    		jne     short CheckFLT4
  1563 0000070A 813E[8A26]4B2E          		cmp     word [Header+ModHeader.mhSign+2], 'K.'
  1564 00000710 7439                    		je      short IsModFile
  1565                                  CheckFLT4:
  1566 00000712 813E[8826]464C          		cmp     word [Header+ModHeader.mhSign], 'FL'
  1567 00000718 7508                    		jne     short Is15Inst
  1568 0000071A 813E[8A26]5434          		cmp     word [Header+ModHeader.mhSign+2], 'T4'
  1569 00000720 7429                    		je      short IsModFile
  1570                                  Is15Inst:
  1571 00000722 BE[2624]                		mov     si, (Header+ModHeader.mhSamples) + (15*ModSample.size)
  1572 00000725 BF[0626]                		mov     di, Header+ModHeader.mhOrderLen
  1573 00000728 8CD8                    		mov     ax, ds
  1574 0000072A 8EC0                    		mov     es, ax
  1575 0000072C FC                      		cld
  1576 0000072D B98200                  		mov     cx, 130
  1577 00000730 F3A4                    		rep     movsb
  1578 00000732 BF[2624]                		mov     di, Header+ModHeader.mhSamples + (15*ModSample.size)
  1579 00000735 31C0                    		xor     ax, ax
  1580 00000737 B9E001                  		mov     cx, 16*ModSample.size
  1581 0000073A F3AA                    		rep     stosb
  1582                                  SeekPatterns:   
  1583 0000073C B80042                  		mov     ax, 4200h
  1584 0000073F 8B1E[4C22]              		mov     bx, [FileHandle]
  1585 00000743 B90000                  		mov     cx, 0
  1586 00000746 BA5802                  		mov     dx, 600
  1587 00000749 CD21                    		int     21h
  1588                                  IsModFile:  
  1589 0000074B A0[0626]                		mov     al, [Header+ModHeader.mhOrderLen]
  1590 0000074E A2[8E26]                		mov     [ModInfo.OrderLen], al
  1591                                  
  1592 00000751 A0[0726]                		mov     al, [Header+ModHeader.mhReStart]
  1593 00000754 3A06[0626]              		cmp     al, [Header+ModHeader.mhOrderLen]
  1594 00000758 7202                    		jb      short SetReStart
  1595 0000075A B07F                    		mov     al, 7Fh
  1596                                  SetReStart:
  1597 0000075C A2[8F26]                		mov     [ModInfo.ReStart], al
  1598                                  
  1599 0000075F B98000                  		mov     cx, 128
  1600 00000762 31C0                    		xor     ax, ax
  1601 00000764 31DB                    		xor     bx, bx
  1602                                  CopyOrder:
  1603 00000766 8AA7[0826]              		mov     ah, [Header+ModHeader.mhOrder+bx]
  1604 0000076A 88A7[9026]              		mov     [ModInfo.Order+bx], ah
  1605 0000076E 38C4                    		cmp     ah, al
  1606 00000770 7202                    		jb      short NextOrder
  1607 00000772 88E0                    		mov     al, ah
  1608                                  NextOrder:
  1609 00000774 43                      		inc     bx
  1610 00000775 E2EF                    		loop    CopyOrder
  1611                                  AllocPatterns:  
  1612                                  		; Erdogan Tan (13/02/2017)
  1613 00000777 30E4                    		xor	ah, ah
  1614 00000779 FEC0                    		inc	al
  1615                                  		; al = count of 1024 bytes
  1616 0000077B 89C3                    		mov	bx, ax
  1617                                  		; count of paragraphs = al*64 
  1618 0000077D C1E006                  		shl	ax, 6 ; *64
  1619 00000780 89C5                    		mov	bp, ax
  1620 00000782 8CCA                    		mov	dx, cs ; current (code) segment
  1621 00000784 81C20010                		add	dx, 1000h ; next 64K (4096*16)
  1622                                  		;
  1623 00000788 C706[1027]0000          		mov	word [ModInfo.Patterns], 0
  1624 0000078E 8916[1227]              		mov	[ModInfo.Patterns+2], dx
  1625                                  		;
  1626 00000792 01D5                    		add	bp, dx ; next segment for samples
  1627                                  ReadPatterns:   
  1628 00000794 1E                      		push    ds
  1629 00000795 B8003F                  		mov     ax, 3F00h
  1630 00000798 89D9                    		mov     cx, bx ; count of 1024 bytes
  1631 0000079A C1E10A                  		shl     cx, 10 ; byte count (cx*1024)
  1632 0000079D 8B1E[4C22]              		mov     bx, [FileHandle]
  1633                                  		;lds    dx, [ModInfo.Patterns]
  1634 000007A1 8EDA                    		mov	ds, dx
  1635 000007A3 31D2                    		xor	dx, dx
  1636 000007A5 CD21                    		int     21h
  1637 000007A7 1F                      		pop     ds
  1638 000007A8 7275                    		jc      CloseFile
  1639                                  
  1640                                  		;lea	si, [Header+ModHeader.mhSamples]
  1641 000007AA BE[6422]                		mov	si, Header+ModHeader.mhSamples
  1642 000007AD 31FF                    		xor     di, di
  1643                                  CopySamples:
  1644 000007AF 8B4416                  		mov     ax, [si+ModSample.msLength]
  1645 000007B2 86C4                    		xchg    al, ah
  1646 000007B4 D1E0                    		shl     ax, 1
  1647 000007B6 8985[9027]              		mov     [ModInfo.SampLen+di], ax
  1648 000007BA 8A4419                  		mov     al, [si+ModSample.msVolume]
  1649 000007BD 30E4                    		xor     ah, ah
  1650 000007BF 8985[4A28]              		mov     [ModInfo.SampVol+di], ax
  1651 000007C3 8B441A                  		mov     ax, [si+ModSample.msRepeat]
  1652 000007C6 86C4                    		xchg    al, ah
  1653 000007C8 D1E0                    		shl     ax, 1
  1654 000007CA 8985[CE27]              		mov     [ModInfo.SampRep+di], ax
  1655 000007CE 8B441C                  		mov     ax, [si+ModSample.msRepLen]
  1656 000007D1 86C4                    		xchg    al, ah
  1657 000007D3 D1E0                    		shl     ax, 1
  1658 000007D5 8985[0C28]              		mov     [ModInfo.SampRepLen+di], ax
  1659 000007D9 83C61E                  		add     si, ModSample.size
  1660 000007DC 83C702                  		add     di, 2
  1661 000007DF 83FF3E                  		cmp     di, 2*31
  1662 000007E2 72CB                    		jb      short CopySamples
  1663                                  
  1664 000007E4 31F6                    		xor     si, si
  1665                                  AllocSamples:
  1666                                  		; Erdogan Tan (13/02/2017)
  1667                                  		;mov	bx, [ModInfo.SampLen+si]
  1668 000007E6 8B8C[9027]              		mov	cx, [ModInfo.SampLen+si]
  1669 000007EA 89CB                    		mov	bx, cx
  1670 000007EC C1EB04                  		shr     bx, 4 ; byte count / 16
  1671 000007EF 7420                    		jz      short NextSample
  1672 000007F1 43                      		inc	bx ; number of paragraphs
  1673 000007F2 C784[1427]0000          		mov	word [ModInfo.SampOfs+si], 0
  1674 000007F8 89AC[5227]              		mov     [ModInfo.SampSeg+si], bp
  1675 000007FC 89EA                    		mov	dx, bp
  1676 000007FE 01DD                    		add	bp, bx ; next segment for sample 
  1677                                  ReadSample:
  1678 00000800 1E                      		push    ds
  1679 00000801 B8003F                  		mov     ax, 3F00h
  1680 00000804 8B1E[4C22]              		mov     bx, [FileHandle]
  1681                                  		;mov    cx, [ModInfo.SampLen+si]
  1682                                  		;mov    dx, [ModInfo.SampOfs+si]
  1683                                  		;mov    ds, [ModInfo.SampSeg+si]
  1684 00000808 8EDA                    		mov	ds, dx
  1685 0000080A 31D2                    		xor	dx, dx	
  1686 0000080C CD21                    		int     21h
  1687 0000080E 1F                      		pop     ds
  1688 0000080F 720E                    		jc      short CloseFile
  1689                                  NextSample:
  1690 00000811 83C602                  		add     si, 2
  1691 00000814 83FE3E                  		cmp     si, 2*31
  1692 00000817 72CD                    		jb      short AllocSamples
  1693                                  
  1694 00000819 C706[4E22]0000          		mov     word [ErrorInfo], 0
  1695                                  CloseFile:      
  1696 0000081F B8003E                  		mov     ax, 3E00h
  1697 00000822 8B1E[4C22]              		mov     bx, [FileHandle]
  1698 00000826 CD21                    		int     21h
  1699                                  Failed:         
  1700 00000828 07                      		pop     es
  1701 00000829 1F                      		pop     ds
  1702 0000082A 61                      		popa
  1703 0000082B 5D                      		pop     bp
  1704 0000082C C20400                  		ret	4
  1705                                  
  1706                                  FreeModule:
  1707                                  		; Erdogan Tan (13/02/2017)
  1708                                  		; nothing to do here for memory de-allocation
  1709                                  ClearModInfo:
  1710 0000082F 60                      		pusha
  1711 00000830 06                      		push    es
  1712 00000831 8CD8                    		mov     ax, ds
  1713 00000833 8EC0                    		mov     es, ax
  1714                                  		;lea    di, [ModInfo]
  1715 00000835 BF[8E26]                		mov	di, ModInfo
  1716 00000838 B9FA01                  		mov     cx, ModInfoRec.size
  1717 0000083B FC                      		cld
  1718 0000083C 31C0                    		xor     ax, ax
  1719 0000083E F3AA                    		rep     stosb
  1720 00000840 07                      		pop     es
  1721 00000841 61                      		popa
  1722 00000842 C3                      		retn
  1723                                  
  1724                                  ;=============================================================================
  1725                                  ;               MODPLAY.ASM
  1726                                  ;=============================================================================
  1727                                  
  1728                                  ; Amiga Module Loader v0.3b by Carlos Hasan.
  1729                                  ;		July 23th, 1993.
  1730                                  
  1731                                  ; EQUATES
  1732                                  
  1733                                  NumTracks       equ 4
  1734                                  DefTempo        equ 6
  1735                                  DefBpm          equ 125
  1736                                  MidCRate        equ 8448
  1737                                  MixBufSize      equ 4096
  1738                                  
  1739                                  ; STRUCTURES
  1740                                  
  1741                                  struc TrackInfo
  1742 00000000 <res 00000004>          .Samples:	resd 1
  1743 00000004 <res 00000002>          .Position:	resw 1
  1744 00000006 <res 00000002>          .Len:		resw 1
  1745 00000008 <res 00000002>          .Repeat:	resw 1
  1746 0000000A <res 00000002>          .RepLen:	resw 1
  1747 0000000C <res 00000001>          .Volume: 	resb 1
  1748 0000000D <res 00000001>          .Error:		resb 1
  1749 0000000E <res 00000002>          .Period:	resw 1
  1750 00000010 <res 00000002>          .Pitch:		resw 1
  1751 00000012 <res 00000002>          .Effect:	resw 1
  1752 00000014 <res 00000002>          .PortTo:	resw 1
  1753 00000016 <res 00000001>          .PortParm:	resb 1
  1754 00000017 <res 00000001>          .VibPos:	resb 1
  1755 00000018 <res 00000001>          .VibParm:	resb 1
  1756 00000019 <res 00000001>          .OldSampOfs:	resb 1
  1757 0000001A <res 00000006>          .Arp:		resw 3
  1758 00000020 <res 00000002>          .ArpIndex:	resw 1
  1759                                  .size:
  1760                                  endstruc
  1761                                  
  1762                                  ; CODE
  1763                                  
  1764                                  ;--------------------------------------------------------------------------
  1765                                  ; BeatTrack:  Process the next beat in one track.
  1766                                  ;  In:
  1767                                  ;    ds:di -  Track info Address.
  1768                                  ;--------------------------------------------------------------------------
  1769                                  
  1770                                  BeatTrack:
  1771 00000843 8B5512                  		mov     dx, [di+TrackInfo.Effect]
  1772 00000846 85D2                    		test    dx, dx
  1773 00000848 7430                    		je      short None
  1774 0000084A 80FE00                  		cmp     dh, 00h
  1775 0000084D 742C                    		je      short Arpeggio
  1776 0000084F 80FE01                  		cmp     dh, 01h
  1777 00000852 743E                    		je      short PortUp
  1778 00000854 80FE02                  		cmp     dh, 02h
  1779 00000857 7455                    		je      short PortDown
  1780 00000859 80FE03                  		cmp     dh, 03h
  1781 0000085C 746D                    		je      short TonePort
  1782 0000085E 80FE04                  		cmp     dh, 04h
  1783 00000861 0F849100                		je      Vibrato
  1784 00000865 80FE05                  		cmp     dh, 05h
  1785 00000868 0F84D600                		je      PortSlide
  1786 0000086C 80FE06                  		cmp     dh, 06h
  1787 0000086F 0F84D700                		je      VibSlide
  1788 00000873 80FE0A                  		cmp     dh, 0Ah
  1789 00000876 0F84D800                		je      VolSlide
  1790                                  None:           
  1791 0000087A C3                      		retn
  1792                                  Arpeggio:
  1793 0000087B 8B5D20                  		mov     bx, [di+TrackInfo.ArpIndex]
  1794 0000087E 8B411A                  		mov     ax, [di+TrackInfo.Arp+bx]
  1795 00000881 894510                  		mov     [di+TrackInfo.Pitch], ax
  1796 00000884 83C302                  		add     bx, 2
  1797 00000887 83FB06                  		cmp     bx, 6
  1798 0000088A 7202                    		jb      short SetArpIndex
  1799 0000088C 31DB                    		xor     bx,bx
  1800                                  SetArpIndex:
  1801 0000088E 895D20                  		mov     [di+TrackInfo.ArpIndex], bx
  1802 00000891 C3                      		retn
  1803                                  PortUp:
  1804 00000892 30F6                    		xor     dh, dh
  1805 00000894 8B5D0E                  		mov     bx, [di+TrackInfo.Period]
  1806 00000897 29D3                    		sub     bx, dx
  1807 00000899 83FB71                  		cmp     bx, 113
  1808 0000089C 7D03                    		jge     short NotSmall
  1809 0000089E BB7100                  		mov     bx, 113
  1810                                  NotSmall:
  1811 000008A1 895D0E                  		mov     [di+TrackInfo.Period], bx
  1812 000008A4 01DB                    		add     bx, bx
  1813 000008A6 8B87[8828]              		mov     ax, [PitchTable+bx]
  1814 000008AA 894510                  		mov     [di+TrackInfo.Pitch], ax
  1815 000008AD C3                      		retn
  1816                                  PortDown:
  1817 000008AE 30F6                    		xor     dh, dh
  1818 000008B0 8B5D0E                  		mov     bx, [di+TrackInfo.Period]
  1819 000008B3 01D3                    		add     bx, dx
  1820 000008B5 81FB5803                		cmp     bx, 856
  1821 000008B9 7E03                    		jle     short NotBig
  1822 000008BB BB5803                  		mov     bx, 856
  1823 000008BE 895D0E                  NotBig:         mov     [di+TrackInfo.Period], bx
  1824 000008C1 01DB                    		add     bx, bx
  1825 000008C3 8B87[8828]              		mov     ax, [PitchTable+bx]
  1826 000008C7 894510                  		mov     [di+TrackInfo.Pitch], ax
  1827 000008CA C3                      		retn
  1828                                  TonePort:
  1829 000008CB 30F6                    		xor     dh, dh
  1830 000008CD 8B4514                  		mov     ax, [di+TrackInfo.PortTo]
  1831 000008D0 8B5D0E                  		mov     bx, [di+TrackInfo.Period]
  1832 000008D3 39C3                    		cmp     bx, ax
  1833 000008D5 741E                    		je      short NoPort
  1834 000008D7 7F0A                    		jg      short PortToUp
  1835                                  PortToDown:     
  1836 000008D9 01D3                    		add     bx, dx
  1837 000008DB 39C3                    		cmp     bx, ax
  1838 000008DD 7E0A                    		jle     short SetPort
  1839                                  FixPort:        
  1840 000008DF 89C3                    		mov     bx, ax
  1841 000008E1 EB06                    		jmp     short SetPort
  1842                                  PortToUp:
  1843 000008E3 29D3                    		sub     bx, dx
  1844 000008E5 39C3                    		cmp     bx, ax
  1845 000008E7 7CF6                    		jl      short FixPort
  1846                                  SetPort:        
  1847 000008E9 895D0E                  		mov     [di+TrackInfo.Period], bx
  1848 000008EC 01DB                    		add     bx, bx
  1849 000008EE 8B87[8828]              		mov     ax, [PitchTable+bx]
  1850 000008F2 894510                  		mov     [di+TrackInfo.Pitch], ax
  1851                                  NoPort:         
  1852 000008F5 C3                      		retn
  1853                                  Vibrato:
  1854 000008F6 88D6                    		mov     dh, dl
  1855 000008F8 80E20F                  		and     dl, 0Fh
  1856 000008FB C0EE04                  		shr     dh, 4
  1857 000008FE C0E602                  		shl     dh, 2
  1858 00000901 007517                  		add     [di+TrackInfo.VibPos], dh
  1859 00000904 8A7517                  		mov     dh, [di+TrackInfo.VibPos]
  1860 00000907 88F3                    		mov     bl, dh
  1861 00000909 C0EB02                  		shr     bl, 2
  1862 0000090C 83E31F                  		and     bx, 1Fh
  1863 0000090F 8A87[B70F]              		mov     al, [SinTable+bx]
  1864 00000913 F6E2                    		mul     dl
  1865 00000915 D1C0                    		rol     ax, 1
  1866 00000917 86C4                    		xchg    al, ah
  1867 00000919 80E401                  		and     ah, 1
  1868 0000091C 84F6                    		test    dh, dh
  1869 0000091E 7902                    		jns     short VibUp
  1870 00000920 F7D8                    		neg     ax
  1871                                  VibUp:          
  1872 00000922 03450E                  		add     ax, [di+TrackInfo.Period]
  1873 00000925 89C3                    		mov     bx, ax
  1874 00000927 83FB71                  		cmp     bx, 113
  1875 0000092A 7D03                    		jge     short NoLoVib
  1876 0000092C BB7100                  		mov     bx, 113
  1877                                  NoLoVib:        
  1878 0000092F 81FB5803                		cmp     bx, 856
  1879 00000933 7E03                    		jle     short NoHiVib
  1880 00000935 BB5803                  		mov     bx, 856
  1881                                  NoHiVib:        
  1882 00000938 01DB                    		add     bx, bx
  1883 0000093A 8B87[8828]              		mov     ax, [PitchTable+bx]
  1884 0000093E 894510                  		mov     [di+TrackInfo.Pitch], ax
  1885 00000941 C3                      		retn
  1886                                  PortSlide:
  1887 00000942 E80D00                  		call    VolSlide
  1888 00000945 8A5516                  		mov     dl, [di+TrackInfo.PortParm]
  1889 00000948 EB81                    		jmp     short TonePort
  1890                                  VibSlide:
  1891 0000094A E80500                  		call    VolSlide
  1892 0000094D 8A5518                  		mov     dl, [di+TrackInfo.VibParm]
  1893 00000950 EBA4                    		jmp     short Vibrato
  1894                                  VolSlide:
  1895 00000952 88D6                    		mov     dh, dl
  1896 00000954 80E20F                  		and     dl, 0Fh
  1897 00000957 C0EE04                  		shr     dh, 4
  1898 0000095A 8A450C                  		mov     al, [di+TrackInfo.Volume]
  1899 0000095D 28D0                    		sub     al, dl
  1900 0000095F 7D02                    		jge     short NoLoVol
  1901 00000961 30C0                    		xor     al, al
  1902                                  NoLoVol:        
  1903 00000963 00F0                    		add     al, dh
  1904 00000965 3C40                    		cmp     al, 64
  1905 00000967 7602                    		jbe     short NoHiVol
  1906 00000969 B040                    		mov     al, 64
  1907                                  NoHiVol:        
  1908 0000096B 88450C                  		mov     [di+TrackInfo.Volume], al
  1909 0000096E C3                      		retn
  1910                                  
  1911                                  ;--------------------------------------------------------------------------
  1912                                  ; GetTrack:   Get the next Note from a pattern.
  1913                                  ;  In:
  1914                                  ;    ds:di -  Track info Address.
  1915                                  ;    es:si -  Pattern Note Address.
  1916                                  ; Out:
  1917                                  ;    es:si -  The Next Pattern Note address.
  1918                                  ;--------------------------------------------------------------------------
  1919                                  
  1920                                  GetTrack:
  1921 0000096F 26AD                    		es lodsw
  1922 00000971 86C4                    		xchg    al, ah
  1923 00000973 88E3                    		mov     bl, ah
  1924 00000975 80E40F                  		and     ah, 0Fh
  1925 00000978 89C1                    		mov     cx, ax
  1926 0000097A 26AD                    		es lodsw
  1927 0000097C 86C4                    		xchg    al, ah
  1928 0000097E 88E7                    		mov     bh, ah
  1929 00000980 80E40F                  		and     ah, 0Fh
  1930 00000983 89C2                    		mov     dx, ax
  1931 00000985 895512                  		mov     [di+TrackInfo.Effect], dx
  1932 00000988 80E3F0                  		and     bl, 0F0h
  1933 0000098B C0EF04                  		shr     bh, 4
  1934 0000098E 08FB                    		or      bl, bh
  1935 00000990 742E                    		je      short SetPeriod
  1936                                  SetSample:
  1937 00000992 30FF                    		xor     bh, bh
  1938 00000994 4B                      		dec     bx
  1939 00000995 01DB                    		add     bx, bx
  1940 00000997 8B87[4A28]              		mov     ax, [ModInfo.SampVol+bx]
  1941 0000099B 88450C                  		mov     [di+TrackInfo.Volume], al
  1942 0000099E 8B87[1427]              		mov     ax, [ModInfo.SampOfs+bx]
  1943 000009A2 8905                    		mov     [di+TrackInfo.Samples], ax
  1944 000009A4 8B87[5227]              		mov     ax, [ModInfo.SampSeg+bx]
  1945 000009A8 894502                  		mov     [di+TrackInfo.Samples+2], ax
  1946 000009AB 8B87[9027]              		mov     ax, [ModInfo.SampLen+bx]
  1947 000009AF 894506                  		mov     [di+TrackInfo.Len], ax
  1948 000009B2 8B87[CE27]              		mov     ax, [ModInfo.SampRep+bx]
  1949 000009B6 894508                  		mov     [di+TrackInfo.Repeat], ax
  1950 000009B9 8B87[0C28]              		mov     ax, [ModInfo.SampRepLen+bx]
  1951 000009BD 89450A                  		mov     [di+TrackInfo.RepLen], ax
  1952                                  SetPeriod:      
  1953 000009C0 85C9                    		test    cx, cx
  1954 000009C2 741B                    		je      short SetEffect
  1955                                  
  1956 000009C4 894D14                  		mov     [di+TrackInfo.PortTo], cx
  1957 000009C7 80FE03                  		cmp     dh, 03h
  1958 000009CA 7413                    		je      short SetEffect
  1959                                  
  1960 000009CC 894D0E                  		mov     [di+TrackInfo.Period], cx
  1961 000009CF 89CB                    		mov     bx, cx
  1962 000009D1 01DB                    		add     bx, bx
  1963 000009D3 8B87[8828]              		mov     ax, [PitchTable+bx]
  1964 000009D7 894510                  		mov     [di+TrackInfo.Pitch], ax
  1965 000009DA C745040000              		mov     word [di+TrackInfo.Position], 0
  1966                                  SetEffect:
  1967 000009DF 85D2                    		test    dx, dx
  1968 000009E1 742A                    		je      short InitNone
  1969 000009E3 80FE00                  		cmp     dh, 00h
  1970 000009E6 0F84C400                		je      InitArpeggio
  1971 000009EA 80FE03                  		cmp     dh, 03h
  1972 000009ED 741F                    		je      short InitTonePort
  1973 000009EF 80FE04                  		cmp     dh, 04h
  1974 000009F2 7428                    		je      short InitVibrato
  1975 000009F4 80FE09                  		cmp     dh, 09h
  1976 000009F7 744A                    		je      short SampleOfs
  1977 000009F9 80FE0B                  		cmp     dh, 0Bh
  1978 000009FC 7457                    		je      short PosJump
  1979 000009FE 80FE0C                  		cmp     dh, 0Ch
  1980 00000A01 745C                    		je      short SetVolume
  1981 00000A03 80FE0D                  		cmp     dh, 0Dh
  1982 00000A06 7462                    		je      short Break
  1983 00000A08 80FE0F                  		cmp     dh, 0Fh
  1984 00000A0B 7478                    		je      short SetSpeed
  1985                                  InitNone:
  1986 00000A0D C3                      		retn
  1987                                  InitTonePort:
  1988 00000A0E 84D2                    		test    dl, dl
  1989 00000A10 7503                    		jne     short SetPortParm
  1990 00000A12 8A5516                  		mov     dl, [di+TrackInfo.PortParm]
  1991                                  SetPortParm:    
  1992 00000A15 885516                  		mov     [di+TrackInfo.PortParm], dl
  1993 00000A18 895512                  		mov     [di+TrackInfo.Effect], dx
  1994 00000A1B C3                      		retn
  1995                                  InitVibrato:
  1996 00000A1C 8A4518                  		mov     al, [di+TrackInfo.VibParm]
  1997 00000A1F 88C4                    		mov     ah, al
  1998 00000A21 240F                    		and     al, 0Fh
  1999 00000A23 80E4F0                  		and     ah, 0F0h
  2000 00000A26 F6C20F                  		test    dl, 0Fh
  2001 00000A29 7502                    		jne     short OkDepth
  2002 00000A2B 08C2                    		or      dl, al
  2003                                  OkDepth:        
  2004 00000A2D F6C2F0                  		test    dl, 0F0h
  2005 00000A30 7502                    		jne     short OkRate
  2006 00000A32 08E2                    		or      dl, ah
  2007                                  OkRate:         
  2008 00000A34 885518                  		mov     [di+TrackInfo.VibParm], dl
  2009 00000A37 895512                  		mov     [di+TrackInfo.Effect], dx
  2010 00000A3A 85C9                    		test    cx, cx
  2011 00000A3C 7404                    		je      short OkPos
  2012 00000A3E C6451700                		mov     byte [di+TrackInfo.VibPos], 0
  2013                                  OkPos:          
  2014 00000A42 C3                      		retn
  2015                                  SampleOfs:      
  2016 00000A43 84D2                    		test    dl, dl
  2017 00000A45 7503                    		jne     short SetSampleOfs
  2018 00000A47 8A5519                  		mov     dl, [di+TrackInfo.OldSampOfs]
  2019                                  SetSampleOfs:
  2020 00000A4A 885519                  		mov     [di+TrackInfo.OldSampOfs], dl
  2021 00000A4D 88D6                    		mov     dh, dl
  2022 00000A4F 30D2                    		xor     dl, dl
  2023 00000A51 895504                  		mov     [di+TrackInfo.Position], dx
  2024 00000A54 C3                      		retn
  2025                                  PosJump:
  2026 00000A55 8816[3A80]              		mov     [OrderPos], dl
  2027 00000A59 C606[3E80]40            		mov     byte [Row], 64
  2028 00000A5E C3                      		retn
  2029                                  SetVolume:
  2030 00000A5F 80FA40                  		cmp     dl, 64
  2031 00000A62 7602                    		jbe     short OkVol
  2032 00000A64 B240                    		mov     dl, 64
  2033                                  OkVol:
  2034 00000A66 88550C                  		mov     [di+TrackInfo.Volume], dl
  2035 00000A69 C3                      		retn
  2036                                  Break:
  2037 00000A6A 88D6                    		mov     dh, dl
  2038 00000A6C 80E20F                  		and     dl, 0Fh
  2039 00000A6F C0EE04                  		shr     dh, 4
  2040 00000A72 00F6                    		add     dh, dh
  2041 00000A74 00F2                    		add     dl, dh
  2042 00000A76 C0E602                  		shl     dh, 2
  2043 00000A79 00F2                    		add     dl, dh
  2044 00000A7B 8816[3F80]              		mov     [BreakRow], dl
  2045 00000A7F C606[3E80]40            		mov     byte [Row], 64
  2046 00000A84 C3                      		retn
  2047                                  SetSpeed:
  2048 00000A85 84D2                    		test    dl,dl
  2049 00000A87 7424                    		je      Skip
  2050 00000A89 80FA1F                  		cmp     dl,31
  2051 00000A8C 7709                    		ja      short SetBpm
  2052                                  SetTempo:       
  2053 00000A8E 8816[3B80]              		mov     [Tempo], dl
  2054 00000A92 8816[3C80]              		mov     [TempoWait], dl
  2055 00000A96 C3                      		retn
  2056                                  SetBpm:
  2057 00000A97 8816[3D80]              		mov     [Bpm], dl
  2058 00000A9B B067                    		mov     al, 103
  2059 00000A9D F6E2                    		mul     dl
  2060 00000A9F 88E3                    		mov     bl, ah
  2061 00000AA1 30FF                    		xor     bh, bh
  2062 00000AA3 A1[8C26]                		mov     ax, [MixSpeed]
  2063 00000AA6 31D2                    		xor     dx, dx
  2064 00000AA8 F7F3                    		div     bx
  2065 00000AAA A3[4080]                		mov     [BpmSamples], ax
  2066                                  Skip:           
  2067 00000AAD C3                      		retn
  2068                                  InitArpeggio:
  2069 00000AAE 88D6                    		mov     dh, dl
  2070 00000AB0 80E20F                  		and     dl, 0Fh
  2071 00000AB3 C0EE04                  		shr     dh, 4
  2072 00000AB6 B92400                  		mov     cx, 36
  2073 00000AB9 31DB                    		xor     bx, bx
  2074 00000ABB 8B450E                  		mov     ax, [di+TrackInfo.Period]
  2075                                  gt_ScanPeriod:
  2076 00000ABE 3B87[D70F]              		cmp     ax, [PeriodTable+bx]
  2077 00000AC2 7305                    		jae     short SetArp
  2078 00000AC4 83C302                  		add     bx, 2
  2079 00000AC7 E2F5                    		loop    gt_ScanPeriod
  2080                                  SetArp:         
  2081 00000AC9 01D2                    		add     dx, dx
  2082 00000ACB 00DE                    		add     dh, bl
  2083 00000ACD 00DA                    		add     dl, bl
  2084 00000ACF 8B9F[D70F]              		mov     bx, [PeriodTable+bx]
  2085 00000AD3 01DB                    		add     bx, bx
  2086 00000AD5 8B87[8828]              		mov     ax, [PitchTable+bx]
  2087 00000AD9 89451A                  		mov     [di+TrackInfo.Arp], ax
  2088 00000ADC 88F3                    		mov     bl, dh
  2089 00000ADE 30FF                    		xor     bh, bh
  2090 00000AE0 8B9F[D70F]              		mov     bx, [PeriodTable+bx]
  2091 00000AE4 01DB                    		add     bx, bx
  2092 00000AE6 8B87[8828]              		mov     ax, [PitchTable+bx]
  2093 00000AEA 89451C                  		mov     [di+TrackInfo.Arp+2], ax
  2094 00000AED 88D3                    		mov     bl, dl
  2095 00000AEF 30FF                    		xor     bh, bh
  2096 00000AF1 8B9F[D70F]              		mov     bx, [PeriodTable+bx]
  2097 00000AF5 01DB                    		add     bx, bx
  2098 00000AF7 8B87[8828]              		mov     ax, [PitchTable+bx]
  2099 00000AFB 89451E                  		mov     [di+TrackInfo.Arp+4], ax
  2100 00000AFE C745200000              		mov     word [di+TrackInfo.ArpIndex], 0
  2101 00000B03 C3                      		retn
  2102                                  
  2103                                  ;--------------------------------------------------------------------------
  2104                                  ; UpdateTracks:  Main code to process the next tick to be played.
  2105                                  ;--------------------------------------------------------------------------
  2106                                  
  2107                                  UpdateTracks:
  2108 00000B04 FE0E[3C80]              		dec     byte [TempoWait]
  2109 00000B08 740F                    		jz      short GetTracks
  2110                                  
  2111 00000B0A B90400                  		mov	cx, NumTracks
  2112 00000B0D BF[4C80]                		mov	di, Tracks
  2113                                  BeatTracks:
  2114 00000B10 E830FD                  		call	BeatTrack	
  2115 00000B13 83C722                  		add	di, TrackInfo.size
  2116 00000B16 E2F8                    		loop	BeatTracks
  2117 00000B18 C3                      		retn
  2118                                  GetTracks:
  2119 00000B19 A0[3B80]                		mov     al, [Tempo]
  2120 00000B1C A2[3C80]                		mov     [TempoWait], al
  2121                                  
  2122 00000B1F C436[4880]              		les     si, [Note]
  2123 00000B23 803E[3E80]40            		cmp     byte [Row], 64
  2124 00000B28 7246                    		jb      short NoPattWrap
  2125                                  
  2126 00000B2A C436[1027]              		les     si, [ModInfo.Patterns]
  2127 00000B2E 8A1E[3A80]              		mov     bl, [OrderPos]
  2128 00000B32 3A1E[8E26]              		cmp     bl, [ModInfo.OrderLen]
  2129 00000B36 720E                    		jb      short NoOrderWrap
  2130 00000B38 8A1E[8F26]              		mov     bl, [ModInfo.ReStart]
  2131 00000B3C 881E[3A80]              		mov     [OrderPos], bl
  2132 00000B40 3A1E[8E26]              		cmp     bl, [ModInfo.OrderLen]
  2133 00000B44 7343                    		jae     short NoUpdate
  2134                                  NoOrderWrap:    
  2135 00000B46 30FF                    		xor     bh, bh
  2136 00000B48 8A9F[9026]              		mov     bl, [ModInfo.Order+bx]
  2137 00000B4C C1E30A                  		shl     bx, 10
  2138 00000B4F 01DE                    		add     si, bx
  2139 00000B51 8A1E[3F80]              		mov     bl, [BreakRow]
  2140 00000B55 881E[3E80]              		mov     [Row], bl
  2141 00000B59 30FF                    		xor     bh, bh
  2142 00000B5B 883E[3F80]              		mov     [BreakRow], bh
  2143 00000B5F C1E304                  		shl     bx, 4
  2144 00000B62 01DE                    		add     si, bx
  2145 00000B64 8936[4880]              		mov     [Note], si
  2146 00000B68 8C06[4A80]              		mov     [Note+2], es
  2147 00000B6C FE06[3A80]              		inc     byte [OrderPos]
  2148                                  NoPattWrap:     
  2149 00000B70 FE06[3E80]              		inc     byte [Row]
  2150                                  
  2151 00000B74 FC                      		cld
  2152 00000B75 B90400                  		mov	cx, NumTracks
  2153 00000B78 BF[4C80]                		mov	di, Tracks
  2154                                  GetTracks_next:
  2155 00000B7B 51                      		push	cx		
  2156 00000B7C E8F0FD                  		call	GetTrack
  2157 00000B7F 59                      		pop	cx
  2158 00000B80 83C722                  		add	di, TrackInfo.size
  2159 00000B83 E2F6                    		loop	GetTracks_next
  2160                                  
  2161 00000B85 8936[4880]              		mov     [Note], si
  2162                                  NoUpdate:
  2163 00000B89 C3                      		retn
  2164                                  
  2165                                  ;--------------------------------------------------------------------------
  2166                                  ; MixTrack:  Mixes one track into a CLEAN buffer.
  2167                                  ;  In:
  2168                                  ;   ds:si -  Track Info Address.
  2169                                  ;   ds:di -  Buffer Address.
  2170                                  ;    cx   -  Buffer Size.
  2171                                  ;--------------------------------------------------------------------------
  2172                                  
  2173                                  MixTrack:
  2174 00000B8A 837C0A02                		cmp     word [si+TrackInfo.RepLen], 2
  2175 00000B8E 7742                    		ja      short MixLooped
  2176                                  MixNonLooped:   
  2177 00000B90 C414                    		les     dx, [si+TrackInfo.Samples]
  2178 00000B92 8B5C04                  		mov     bx, [si+TrackInfo.Position]
  2179 00000B95 8B6C06                  		mov     bp, [si+TrackInfo.Len]
  2180 00000B98 52                      		push    dx
  2181 00000B99 56                      		push    si
  2182 00000B9A 01D3                    		add     bx, dx
  2183 00000B9C 01D5                    		add     bp, dx
  2184 00000B9E 8B5410                  		mov     dx, [si+TrackInfo.Pitch]
  2185 00000BA1 8A440C                  		mov     al, [si+TrackInfo.Volume]
  2186 00000BA4 8A640D                  		mov     ah, [si+TrackInfo.Error]
  2187 00000BA7 89DE                    		mov     si, bx
  2188 00000BA9 88C7                    		mov     bh, al
  2189 00000BAB 88D0                    		mov     al, dl
  2190 00000BAD 88F2                    		mov     dl, dh
  2191 00000BAF 30F6                    		xor     dh, dh
  2192                                  nlMixSamp:      
  2193 00000BB1 39EE                    		cmp     si, bp
  2194 00000BB3 7310                    		jae     short nlMixBye
  2195 00000BB5 268A1C                  		mov     bl, [es:si]
  2196 00000BB8 8A9F[3A2F]              		mov     bl, [VolTable+bx]
  2197 00000BBC 001D                    		add     [di], bl
  2198 00000BBE 47                      		inc     di
  2199 00000BBF 00C4                    		add     ah, al
  2200 00000BC1 11D6                    		adc     si, dx
  2201 00000BC3 E2EC                    		loop    nlMixSamp
  2202                                  nlMixBye:       
  2203 00000BC5 89F3                    		mov     bx, si
  2204 00000BC7 5E                      		pop     si
  2205 00000BC8 5A                      		pop     dx
  2206 00000BC9 29D3                    		sub     bx, dx
  2207 00000BCB 895C04                  		mov     [si+TrackInfo.Position], bx
  2208 00000BCE 88640D                  		mov     [si+TrackInfo.Error], ah
  2209 00000BD1 C3                      		retn
  2210                                  MixLooped:
  2211 00000BD2 C414                    		les     dx, [si+TrackInfo.Samples]
  2212 00000BD4 8B5C04                  		mov     bx, [si+TrackInfo.Position]
  2213 00000BD7 8B6C0A                  		mov     bp, [si+TrackInfo.RepLen]
  2214 00000BDA 892E[4680]              		mov     [BufRep], bp
  2215 00000BDE 036C08                  		add     bp, [si+TrackInfo.Repeat]
  2216 00000BE1 52                      		push    dx
  2217 00000BE2 56                      		push    si
  2218 00000BE3 01D3                    		add     bx, dx
  2219 00000BE5 01D5                    		add     bp, dx
  2220 00000BE7 8B5410                  		mov     dx, [si+TrackInfo.Pitch]
  2221 00000BEA 8A440C                  		mov     al, [si+TrackInfo.Volume]
  2222 00000BED 8A640D                  		mov     ah, [si+TrackInfo.Error]
  2223 00000BF0 89DE                    		mov     si, bx
  2224 00000BF2 88C7                    		mov     bh, al
  2225 00000BF4 88D0                    		mov     al, dl
  2226 00000BF6 88F2                    		mov     dl, dh
  2227 00000BF8 30F6                    		xor     dh, dh
  2228                                  lpMixSamp:      
  2229 00000BFA 39EE                    		cmp     si, bp
  2230 00000BFC 7204                    		jb      short lpMixNow
  2231 00000BFE 2B36[4680]              		sub     si, [BufRep]
  2232                                  lpMixNow:       
  2233 00000C02 268A1C                  		mov     bl, [es:si]
  2234 00000C05 8A9F[3A2F]              		mov     bl, [VolTable+bx]
  2235 00000C09 001D                    		add     [di], bl
  2236 00000C0B 47                      		inc     di
  2237 00000C0C 00C4                    		add     ah, al
  2238 00000C0E 11D6                    		adc     si, dx
  2239 00000C10 E2E8                    		loop    lpMixSamp
  2240                                  lpMixBye:       
  2241 00000C12 89F3                    		mov     bx, si
  2242 00000C14 5E                      		pop     si
  2243 00000C15 5A                      		pop     dx
  2244 00000C16 29D3                    		sub     bx, dx
  2245 00000C18 895C04                  		mov     [si+TrackInfo.Position], bx
  2246 00000C1B 88640D                  		mov     [si+TrackInfo.Error], ah
  2247 00000C1E C3                      		retn
  2248                                  
  2249                                  ;--------------------------------------------------------------------------
  2250                                  ; GetSamples:  Returns the next chunk of samples to be played.
  2251                                  ;  In:
  2252                                  ;    Buffer  - Buffer Address.
  2253                                  ;    Count   - Buffer Size.
  2254                                  ;--------------------------------------------------------------------------
  2255                                  
  2256                                  GetSamples:
  2257                                  		;ds:si = buffer address
  2258                                  		;cx = count
  2259                                  
  2260                                  		;[sp+6] = ds
  2261                                  		;[sp+4] = si
  2262                                  		;[sp+2] = count
  2263                                  
  2264                                  		Count	equ 4
  2265                                  		Buffer	equ 6 
  2266                                  
  2267 00000C1F 55                      		push	bp
  2268 00000C20 89E5                    		mov	bp, sp
  2269                                  
  2270 00000C22 60                      		pusha
  2271 00000C23 1E                      		push    ds
  2272 00000C24 06                      		push    es
  2273 00000C25 FC                      		cld
  2274                                  
  2275 00000C26 C47E06                  		les     di, [bp+Buffer]
  2276 00000C29 8B5E04                  		mov     bx, [bp+Count]
  2277                                  
  2278 00000C2C 833E[4480]00            NextChunk:      cmp     word [BufLen], 0
  2279 00000C31 7538                    		jne     short CopyChunk
  2280                                  
  2281 00000C33 53                      		push    bx
  2282 00000C34 57                      		push    di
  2283 00000C35 06                      		push    es
  2284                                  MixChunk:       
  2285                                  		;lea     di, [MixBuffer]
  2286 00000C36 BF[3A70]                		mov	di, MixBuffer
  2287 00000C39 8B0E[4080]              		mov     cx, [BpmSamples]
  2288 00000C3D 893E[4280]              		mov     [BufPtr], di
  2289 00000C41 890E[4480]              		mov     [BufLen], cx
  2290                                  
  2291 00000C45 8CD8                    		mov     ax, ds
  2292 00000C47 8EC0                    		mov     es, ax
  2293 00000C49 B080                    		mov     al, 80h
  2294 00000C4B F3AA                    		rep     stosb
  2295                                  
  2296 00000C4D B90400                  		mov	cx, NumTracks
  2297 00000C50 BE[2A80]                		mov	si, Tracks - TrackInfo.size
  2298                                  GetSamples_next:
  2299 00000C53 51                      		push	cx
  2300 00000C54 83C622                  		add	si, TrackInfo.size
  2301 00000C57 8B0E[4480]              		mov	cx, [BufLen]
  2302 00000C5B 8B3E[4280]              		mov	di, [BufPtr]
  2303 00000C5F E828FF                  		call	MixTrack
  2304 00000C62 59                      		pop	cx
  2305 00000C63 E2EE                    		loop	GetSamples_next		
  2306                                  
  2307 00000C65 E89CFE                  		call    UpdateTracks
  2308                                  
  2309 00000C68 07                      		pop     es
  2310 00000C69 5F                      		pop     di
  2311 00000C6A 5B                      		pop     bx
  2312                                  CopyChunk:      
  2313 00000C6B 8B0E[4480]              		mov     cx, [BufLen]
  2314 00000C6F 39D9                    		cmp     cx, bx
  2315 00000C71 7602                    		jbe     short MoveChunk
  2316 00000C73 89D9                    		mov     cx, bx
  2317                                  MoveChunk:
  2318 00000C75 8B36[4280]              		mov     si, [BufPtr]
  2319 00000C79 010E[4280]              		add     [BufPtr], cx
  2320 00000C7D 290E[4480]              		sub     [BufLen], cx
  2321 00000C81 29CB                    		sub     bx, cx
  2322 00000C83 F3A4                    		rep     movsb
  2323 00000C85 85DB                    		test    bx, bx
  2324 00000C87 75A3                    		jne     short NextChunk
  2325                                  
  2326 00000C89 07                      		pop     es
  2327 00000C8A 1F                      		pop     ds
  2328 00000C8B 61                      		popa
  2329 00000C8C 5D                      		pop	bp
  2330 00000C8D C20600                  		ret	6
  2331                                  
  2332                                  ;--------------------------------------------------------------------------
  2333                                  ; StartPlaying: Initializes the Sound System.
  2334                                  ;  In:
  2335                                  ;   Module Information Resources.
  2336                                  ;--------------------------------------------------------------------------
  2337                                  
  2338                                  StartPlaying:
  2339 00000C90 60                      		pusha
  2340 00000C91 1E                      		push    ds
  2341 00000C92 06                      		push    es
  2342                                  SetModParms:    
  2343 00000C93 C606[3A80]00            		mov     byte [OrderPos], 0
  2344 00000C98 C606[3B80]06            		mov     byte [Tempo], DefTempo
  2345 00000C9D C606[3C80]06            		mov     byte [TempoWait], DefTempo
  2346 00000CA2 C606[3D80]7D            		mov     byte [Bpm], DefBpm
  2347 00000CA7 C606[3E80]40            		mov     byte [Row], 64
  2348 00000CAC C606[3F80]00            		mov     byte [BreakRow], 0
  2349 00000CB1 A1[8C26]                		mov     ax, [MixSpeed]
  2350 00000CB4 31D2                    		xor     dx, dx
  2351 00000CB6 BB3200                  		mov     bx, 24*DefBpm/60
  2352 00000CB9 F7F3                    		div     bx
  2353 00000CBB A3[4080]                		mov     [BpmSamples], ax
  2354                                  ClearTracks:    
  2355 00000CBE BF[4C80]                		mov     di, Tracks
  2356 00000CC1 8CD8                    		mov     ax, ds
  2357 00000CC3 8EC0                    		mov     es, ax
  2358 00000CC5 B98800                  		mov     cx, NumTracks*TrackInfo.size
  2359 00000CC8 31C0                    		xor     ax, ax
  2360 00000CCA FC                      		cld
  2361 00000CCB F3AA                    		rep     stosb
  2362                                  
  2363 00000CCD A3[4280]                		mov     [BufPtr], ax
  2364 00000CD0 A3[4480]                		mov     [BufLen], ax
  2365                                  MakePitch:
  2366 00000CD3 B80021                  		mov     ax, MidCRate
  2367 00000CD6 BBAC01                  		mov     bx, 428
  2368 00000CD9 F7E3                    		mul     bx
  2369 00000CDB F736[8C26]              		div     word [MixSpeed]
  2370 00000CDF 30F6                    		xor     dh, dh
  2371 00000CE1 88E2                    		mov     dl, ah
  2372 00000CE3 88C4                    		mov     ah, al
  2373 00000CE5 30C0                    		xor     al, al
  2374 00000CE7 B95903                  		mov     cx, 857
  2375 00000CEA 31DB                    		xor     bx, bx
  2376 00000CEC BF[8828]                		mov     di, PitchTable
  2377                                  PitchLoop:      
  2378 00000CEF 50                      		push    ax
  2379 00000CF0 52                      		push    dx
  2380 00000CF1 39DA                    		cmp     dx, bx
  2381 00000CF3 7302                    		jae     short NoDiv
  2382 00000CF5 F7F3                    		div     bx
  2383                                  NoDiv:          
  2384 00000CF7 AB                      		stosw
  2385 00000CF8 5A                      		pop     dx
  2386 00000CF9 58                      		pop     ax
  2387 00000CFA 43                      		inc     bx
  2388 00000CFB E2F2                    		loop    PitchLoop
  2389                                  MakeVolume:     
  2390 00000CFD B90041                  		mov     cx, 16640
  2391 00000D00 89CB                    		mov     bx, cx
  2392                                  VolLoop:
  2393 00000D02 4B                      		dec     bx
  2394 00000D03 88D8                    		mov     al, bl
  2395 00000D05 F6EF                    		imul    bh
  2396 00000D07 88A7[3A2F]              		mov     [VolTable+bx], ah
  2397 00000D0B E2F5                    		loop    VolLoop
  2398                                  
  2399 00000D0D 07                      		pop     es
  2400 00000D0E 1F                      		pop     ds
  2401 00000D0F 61                      		popa
  2402                                  		;retn
  2403                                  
  2404                                  ;--------------------------------------------------------------------------
  2405                                  ; StopPlaying: ShutDown the Sound System.
  2406                                  ;--------------------------------------------------------------------------
  2407                                  
  2408                                  StopPlaying:
  2409 00000D10 C3                      		retn
  2410                                  
  2411                                  ;=============================================================================
  2412                                  ;               PLAYER.ASM
  2413                                  ;=============================================================================
  2414                                  
  2415                                  ; UTILS.ASM
  2416                                  ;----------------------------------------------------------------------------
  2417                                  ;       delay1_4ms - Delay for 1/4 millisecond.
  2418                                  ;		    1mS = 1000us
  2419                                  ;       Entry:
  2420                                  ;         None
  2421                                  ;       Exit:
  2422                                  ;	  None
  2423                                  ;
  2424                                  ;       Modified:
  2425                                  ;         None
  2426                                  ;
  2427                                  PORTB			EQU	061h
  2428                                    REFRESH_STATUS	EQU	010h		; Refresh signal status
  2429                                  
  2430                                  delay1_4ms:
  2431 00000D11 50                              push    ax 
  2432 00000D12 51                              push    cx
  2433 00000D13 B91000                          mov     cx, 16			; close enough.
  2434 00000D16 E461                    	in	al,PORTB
  2435 00000D18 2410                    	and	al,REFRESH_STATUS
  2436 00000D1A 88C4                    	mov	ah,al			; Start toggle state
  2437 00000D1C 09C9                    	or	cx, cx
  2438 00000D1E 7401                    	jz	short _d4ms1
  2439 00000D20 41                      	inc	cx			; Throwaway first toggle
  2440                                  _d4ms1:	
  2441 00000D21 E461                    	in	al,PORTB		; Read system control port
  2442 00000D23 2410                    	and	al,REFRESH_STATUS	; Refresh toggles 15.085 microseconds
  2443 00000D25 38C4                    	cmp	ah,al
  2444 00000D27 74F8                    	je	short _d4ms1		; Wait for state change
  2445                                  
  2446 00000D29 88C4                    	mov	ah,al			; Update with new state
  2447 00000D2B 49                      	dec	cx
  2448 00000D2C 75F3                    	jnz	short _d4ms1
  2449                                  
  2450 00000D2E 59                              pop     cx
  2451 00000D2F 58                              pop     ax
  2452 00000D30 C3                              retn
  2453                                  
  2454                                  print_msg:
  2455                                  	; 13/11/2016 - Erdogan Tan 
  2456                                  	; esi = ASCIIZ text address
  2457                                  	;
  2458 00000D31 BB0700                  	mov	bx, 7h
  2459 00000D34 B40E                    	mov	ah, 0Eh 
  2460                                  pm_next_char:
  2461 00000D36 AC                      	lodsb
  2462 00000D37 20C0                    	and	al, al
  2463 00000D39 7404                    	jz	short pm_retn
  2464 00000D3B CD10                    	int	10h
  2465 00000D3D EBF7                    	jmp	short pm_next_char
  2466                                  pm_retn:
  2467 00000D3F C3                      	retn
  2468                                  
  2469                                  dword2str:
  2470                                  	; 13/11/2016 - Erdogan Tan 
  2471                                  	; eax = dword value
  2472                                  	;
  2473 00000D40 E84400                  	call	dwordtohex
  2474 00000D43 668916[0611]            	mov	[dword_str], edx
  2475 00000D48 66A3[0A11]              	mov	[dword_str+4], eax
  2476 00000D4C BE[0611]                	mov	si, dword_str
  2477 00000D4F C3                      	retn
  2478                                  
  2479                                  	; trdos386.s (unix386.s) - 10/05/2015
  2480                                  	; Convert binary number to hexadecimal string
  2481                                  
  2482                                  bytetohex:
  2483                                  	; INPUT ->
  2484                                  	; 	AL = byte (binary number)
  2485                                  	; OUTPUT ->
  2486                                  	;	AX = hexadecimal string
  2487                                  	;
  2488 00000D50 53                      	push	bx
  2489 00000D51 30FF                    	xor	bh, bh
  2490 00000D53 88C3                    	mov	bl, al
  2491 00000D55 C0EB04                  	shr	bl, 4
  2492 00000D58 8A9F[3010]              	mov	bl, [bx+hex_chars] 	 	
  2493 00000D5C 86D8                    	xchg	bl, al
  2494 00000D5E 80E30F                  	and	bl, 0Fh
  2495 00000D61 8AA7[3010]              	mov	ah, [bx+hex_chars] 
  2496 00000D65 5B                      	pop	bx	
  2497 00000D66 C3                      	retn
  2498                                  
  2499                                  wordtohex:
  2500                                  	; INPUT ->
  2501                                  	; 	AX = word (binary number)
  2502                                  	; OUTPUT ->
  2503                                  	;	EAX = hexadecimal string
  2504                                  	;
  2505 00000D67 53                      	push	bx
  2506 00000D68 30FF                    	xor	bh, bh
  2507 00000D6A 86E0                    	xchg	ah, al
  2508 00000D6C 50                      	push	ax
  2509 00000D6D 88E3                    	mov	bl, ah
  2510 00000D6F C0EB04                  	shr	bl, 4
  2511 00000D72 8A87[3010]              	mov	al, [bx+hex_chars] 	 	
  2512 00000D76 88E3                    	mov	bl, ah
  2513 00000D78 80E30F                  	and	bl, 0Fh
  2514 00000D7B 8AA7[3010]              	mov	ah, [bx+hex_chars]
  2515 00000D7F 66C1E010                	shl	eax, 16
  2516 00000D83 58                      	pop	ax
  2517 00000D84 5B                      	pop	bx
  2518 00000D85 EBC9                    	jmp	short bytetohex
  2519                                  
  2520                                  dwordtohex:
  2521                                  	; INPUT ->
  2522                                  	; 	EAX = dword (binary number)
  2523                                  	; OUTPUT ->
  2524                                  	;	EDX:EAX = hexadecimal string
  2525                                  	;
  2526 00000D87 6650                    	push	eax
  2527 00000D89 66C1E810                	shr	eax, 16
  2528 00000D8D E8D7FF                  	call	wordtohex
  2529 00000D90 6689C2                  	mov	edx, eax
  2530 00000D93 6658                    	pop	eax
  2531 00000D95 E8CFFF                  	call	wordtohex
  2532 00000D98 C3                      	retn
  2533                                  
  2534                                  	; 13/11/2016 - Erdogan Tan
  2535                                  write_ac97_dev_info:
  2536                                  	; BUS/DEV/FN
  2537                                  	;	00000000BBBBBBBBDDDDDFFF00000000
  2538                                  	; DEV/VENDOR
  2539                                  	;	DDDDDDDDDDDDDDDDVVVVVVVVVVVVVVVV
  2540                                  
  2541 00000D99 30FF                    	xor	bh, bh
  2542 00000D9B 668B36[4211]            	mov	esi, [dev_vendor]
  2543 00000DA0 89F0                    	mov	ax, si
  2544 00000DA2 88C3                    	mov	bl, al
  2545 00000DA4 88DA                    	mov	dl, bl
  2546 00000DA6 80E30F                  	and	bl, 0Fh
  2547 00000DA9 8A87[3010]              	mov	al, [bx+hex_chars]
  2548 00000DAD A2[7310]                	mov	[msgVendorId+3], al
  2549 00000DB0 88D3                    	mov	bl, dl
  2550 00000DB2 C0EB04                  	shr	bl, 4
  2551 00000DB5 8A87[3010]              	mov	al, [bx+hex_chars]
  2552 00000DB9 A2[7210]                	mov	[msgVendorId+2], al
  2553 00000DBC 88E3                    	mov	bl, ah
  2554 00000DBE 88DA                    	mov	dl, bl
  2555 00000DC0 80E30F                  	and	bl, 0Fh
  2556 00000DC3 8A87[3010]              	mov	al, [bx+hex_chars]
  2557 00000DC7 A2[7110]                	mov	[msgVendorId+1], al
  2558 00000DCA 88D3                    	mov	bl, dl
  2559 00000DCC C0EB04                  	shr	bl, 4
  2560 00000DCF 8A87[3010]              	mov	al, [bx+hex_chars]
  2561 00000DD3 A2[7010]                	mov	[msgVendorId], al
  2562 00000DD6 66C1EE10                	shr	esi, 16
  2563 00000DDA 89F0                    	mov	ax, si
  2564 00000DDC 88C3                    	mov	bl, al
  2565 00000DDE 88DA                    	mov	dl, bl
  2566 00000DE0 80E30F                  	and	bl, 0Fh
  2567 00000DE3 8A87[3010]              	mov	al, [bx+hex_chars]
  2568 00000DE7 A2[8410]                	mov	[msgDevId+3], al
  2569 00000DEA 88D3                    	mov	bl, dl
  2570 00000DEC C0EB04                  	shr	bl, 4
  2571 00000DEF 8A87[3010]              	mov	al, [bx+hex_chars]
  2572 00000DF3 A2[8310]                	mov	[msgDevId+2], al
  2573 00000DF6 88E3                    	mov	bl, ah
  2574 00000DF8 88DA                    	mov	dl, bl
  2575 00000DFA 80E30F                  	and	bl, 0Fh
  2576 00000DFD 8A87[3010]              	mov	al, [bx+hex_chars]
  2577 00000E01 A2[8210]                	mov	[msgDevId+1], al
  2578 00000E04 88D3                    	mov	bl, dl
  2579 00000E06 C0EB04                  	shr	bl, 4
  2580 00000E09 8A87[3010]              	mov	al, [bx+hex_chars]
  2581 00000E0D A2[8110]                	mov	[msgDevId], al
  2582                                  
  2583 00000E10 668B36[3E11]            	mov	esi, [bus_dev_fn]
  2584 00000E15 66C1EE08                	shr	esi, 8
  2585 00000E19 89F0                    	mov	ax, si
  2586 00000E1B 88C3                    	mov	bl, al
  2587 00000E1D 88DA                    	mov	dl, bl
  2588 00000E1F 80E307                  	and	bl, 7 ; bit 0,1,2
  2589 00000E22 8A87[3010]              	mov	al, [bx+hex_chars]
  2590 00000E26 A2[A810]                	mov	[msgFncNo+1], al
  2591 00000E29 88D3                    	mov	bl, dl
  2592 00000E2B C0EB03                  	shr	bl, 3
  2593 00000E2E 88DA                    	mov	dl, bl
  2594 00000E30 80E30F                  	and	bl, 0Fh
  2595 00000E33 8A87[3010]              	mov	al, [bx+hex_chars]
  2596 00000E37 A2[9A10]                	mov	[msgDevNo+1], al
  2597 00000E3A 88D3                    	mov	bl, dl
  2598 00000E3C C0EB04                  	shr	bl, 4
  2599 00000E3F 8A87[3010]              	mov	al, [bx+hex_chars]
  2600 00000E43 A2[9910]                	mov	[msgDevNo], al
  2601 00000E46 88E3                    	mov	bl, ah
  2602 00000E48 88DA                    	mov	dl, bl
  2603 00000E4A 80E30F                  	and	bl, 0Fh
  2604 00000E4D 8A87[3010]              	mov	al, [bx+hex_chars]
  2605 00000E51 A2[8E10]                	mov	[msgBusNo+1], al
  2606 00000E54 88D3                    	mov	bl, dl
  2607 00000E56 C0EB04                  	shr	bl, 4
  2608 00000E59 8A87[3010]              	mov	al, [bx+hex_chars]
  2609 00000E5D A2[8D10]                	mov	[msgBusNo], al
  2610                                  
  2611 00000E60 A1[4A11]                	mov	ax, [ac97_io_base]
  2612 00000E63 88C3                    	mov	bl, al
  2613 00000E65 88DA                    	mov	dl, bl
  2614 00000E67 80E30F                  	and	bl, 0Fh
  2615 00000E6A 8A87[3010]              	mov	al, [bx+hex_chars]
  2616 00000E6E A2[C110]                	mov	[msgIOBaseAddr+3], al
  2617 00000E71 88D3                    	mov	bl, dl
  2618 00000E73 C0EB04                  	shr	bl, 4
  2619 00000E76 8A87[3010]              	mov	al, [bx+hex_chars]
  2620 00000E7A A2[C010]                	mov	[msgIOBaseAddr+2], al
  2621 00000E7D 88E3                    	mov	bl, ah
  2622 00000E7F 88DA                    	mov	dl, bl
  2623 00000E81 80E30F                  	and	bl, 0Fh
  2624 00000E84 8A87[3010]              	mov	al, [bx+hex_chars]
  2625 00000E88 A2[BF10]                	mov	[msgIOBaseAddr+1], al
  2626 00000E8B 88D3                    	mov	bl, dl
  2627 00000E8D C0EB04                  	shr	bl, 4
  2628 00000E90 8A87[3010]              	mov	al, [bx+hex_chars]
  2629 00000E94 A2[BE10]                	mov	[msgIOBaseAddr], al
  2630                                  
  2631                                  	; 24/11/2016
  2632 00000E97 30E4                    	xor	ah, ah
  2633 00000E99 A0[3C11]                	mov	al, [ac97_int_ln_reg]
  2634 00000E9C B10A                    	mov	cl, 10
  2635 00000E9E F6F1                    	div	cl
  2636 00000EA0 0106[C910]              	add	[msgIRQ], ax
  2637 00000EA4 20C0                    	and	al, al
  2638 00000EA6 7508                    	jnz	short _pmi
  2639 00000EA8 A0[CA10]                	mov	al, [msgIRQ+1]
  2640 00000EAB B420                    	mov	ah, ' '
  2641 00000EAD A3[C910]                	mov	[msgIRQ], ax
  2642                                  _pmi:
  2643 00000EB0 BA[4110]                        mov	dx, msgAC97Info
  2644 00000EB3 B409                            mov     ah, 9
  2645 00000EB5 CD21                            int     21h
  2646 00000EB7 C3                              retn
  2647                                  
  2648                                  ;=============================================================================
  2649                                  ;               preinitialized data
  2650                                  ;=============================================================================
  2651                                  
  2652                                  ;=============================================================================
  2653                                  ;               PLAY.ASM - DATA
  2654                                  ;=============================================================================
  2655                                  
  2656                                  msg_2017:
  2657 00000EB8 54696E79204D4F4420-     		db	'Tiny MOD Player by Erdogan Tan. February 2017.',10,13
  2657 00000EC1 506C61796572206279-
  2657 00000ECA 204572646F67616E20-
  2657 00000ED3 54616E2E2046656272-
  2657 00000EDC 756172792032303137-
  2657 00000EE5 2E0A0D             
  2658 00000EE8 75736167653A20706C-     		db	'usage: playmod filename.mod', 10, 13, '$'
  2658 00000EF1 61796D6F642066696C-
  2658 00000EFA 656E616D652E6D6F64-
  2658 00000F03 0A0D24             
  2659 00000F06 31352F30322F323031-     		db	'15/02/2017'
  2659 00000F0F 37                 
  2660                                  
  2661 00000F10 54696E79204D4F4420-     Credits:	db	'Tiny MOD Player v0.1b by Carlos Hasan. July 1993.'
  2661 00000F19 506C61796572207630-
  2661 00000F22 2E3162206279204361-
  2661 00000F2B 726C6F732048617361-
  2661 00000F34 6E2E204A756C792031-
  2661 00000F3D 3939332E           
  2662 00000F41 0A0D24                  		db	10,13,'$'
  2663 00000F44 4572726F72206C6F61-     ErrorMesg:	db	'Error loading Module file.',10,13,'$'
  2663 00000F4D 64696E67204D6F6475-
  2663 00000F56 6C652066696C652E0A-
  2663 00000F5F 0D24               
  2664 00000F61 536F756E6420426C61-     MsgNotFound:	db	'Sound Blaster not found or IRQ error.',10,13,'$'
  2664 00000F6A 73746572206E6F7420-
  2664 00000F73 666F756E64206F7220-
  2664 00000F7C 495251206572726F72-
  2664 00000F85 2E0A0D24           
  2665 00000F89 536F756E6420426C61-     MsgFound:	db	'Sound Blaster found at Address 2'
  2665 00000F92 7374657220666F756E-
  2665 00000F9B 642061742041646472-
  2665 00000FA4 6573732032         
  2666 00000FA9 7830682C2049525120      PortText:	db	'x0h, IRQ '
  2667 00000FB2 782E0A0D24              IrqText:	db	'x.',10,13,'$'
  2668                                  
  2669                                  ;=============================================================================
  2670                                  ;               MODPLAY.ASM - DATA
  2671                                  ;=============================================================================
  2672                                  
  2673                                  ;Credits:	db	'Amiga Module Player v0.3b by Carlos Hasan.'
  2674                                  
  2675 00000FB7 0019324A62788EA2B4-     SinTable:	db	0,25,50,74,98,120,142,162,180,197,212,225
  2675 00000FC0 C5D4E1             
  2676 00000FC3 ECF4FAFEFFFEFAF4EC-     		db	236,244,250,254,255,254,250,244,236,225
  2676 00000FCC E1                 
  2677 00000FCD D4C5B4A28E78624A32-     		db	212,197,180,162,142,120,98,74,50,25
  2677 00000FD6 19                 
  2678                                  
  2679 00000FD7 58032803FA02D002A6-     PeriodTable:	dw	856,808,762,720,678,640,604,570,538,508,480,453
  2679 00000FE0 0280025C023A021A02-
  2679 00000FE9 FC01E001C501       
  2680 00000FEF AC0194017D01680153-     		dw	428,404,381,360,339,320,302,285,269,254,240,226
  2680 00000FF8 0140012E011D010D01-
  2680 00001001 FE00F000E200       
  2681 00001007 D600CA00BE00B400AA-     		dw	214,202,190,180,170,160,151,143,135,127,120,113
  2681 00001010 00A00097008F008700-
  2681 00001019 7F0078007100       
  2682                                  
  2683                                  ;=============================================================================
  2684                                  ;               PLAYER.ASM - DATA
  2685                                  ;=============================================================================
  2686                                  
  2687 0000101F 02                      tBuff	db 2	; 08/12/2016
  2688                                  
  2689                                  ; 24/11/2016
  2690                                  ;	       IRQ  0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15 
  2691 00001020 08090A0B0C0D0E0F70-     irq_int		db 08h,09h,0Ah,0Bh,0Ch,0Dh,0Eh,0Fh,70h,71h,72h,73h,74h,75h,76h,77h
  2691 00001029 71727374757677     
  2692                                  
  2693                                  ; 13/11/2016
  2694 00001030 303132333435363738-     hex_chars	db "0123456789ABCDEF", 0
  2694 00001039 3941424344454600   
  2695 00001041 414339372041756469-     msgAC97Info	db "AC97 Audio Controller & Codec Info", 0Dh, 0Ah 
  2695 0000104A 6F20436F6E74726F6C-
  2695 00001053 6C6572202620436F64-
  2695 0000105C 656320496E666F0D0A 
  2696 00001065 56656E646F72204944-     		db "Vendor ID: "
  2696 0000106E 3A20               
  2697 00001070 303030306820446576-     msgVendorId	db "0000h Device ID: "
  2697 00001079 6963652049443A20   
  2698 00001081 30303030680D0A          msgDevId	db "0000h", 0Dh, 0Ah
  2699 00001088 4275733A20              		db "Bus: "
  2700 0000108D 303068204465766963-     msgBusNo	db "00h Device: "
  2700 00001096 653A20             
  2701 00001099 3030682046756E6374-     msgDevNo	db "00h Function: "
  2701 000010A2 696F6E3A20         
  2702 000010A7 303068                  msgFncNo	db "00h"
  2703 000010AA 0D0A                    		db 0Dh, 0Ah
  2704 000010AC 492F4F204261736520-     		db "I/O Base Address: "
  2704 000010B5 416464726573733A20 
  2705 000010BE 303030306820495251-     msgIOBaseAddr	db "0000h IRQ: "
  2705 000010C7 3A20               
  2706 000010C9 3030                    msgIRQ		dw 3030h
  2707 000010CB 0D0A24                  		db 0Dh, 0Ah, "$"
  2708 000010CE 53616D706C65205261-     msgSampleRate	db "Sample Rate: "
  2708 000010D7 74653A20           
  2709 000010DB 303030303020487A20-     msgHertz	db "00000 Hz ", "$" 
  2709 000010E4 24                 
  2710 000010E5 3820626974732024        msg8Bits	db "8 bits ", "$" 
  2711 000010ED 4D6F6E6F0D0A24          msgMono		db "Mono", 0Dh, 0Ah, "$"
  2712 000010F4 313620626974732024      msg16Bits	db "16 bits ", "$" 
  2713 000010FD 53746572656F0D0A24      msgStereo	db "Stereo", 0Dh, 0Ah, "$"
  2714                                  
  2715                                  ;; 13/11/2016 - Erdogan Tan (Ref: KolibriOS, codec.inc)
  2716                                  ;codec_id	dd 0
  2717                                  ;codec_chip_id	dd 0
  2718                                  ;codec_vendor_ids dw 0
  2719                                  ;codec_chip_ids	dw 0
  2720                                  
  2721 00001106 3030303030303030        dword_str	 dd 30303030h, 30303030h
  2722 0000110E 680D0A00                		 db 'h', 0Dh, 0Ah, 0
  2723                                  
  2724                                  ;=============================================================================
  2725                                  ;        	uninitialized data
  2726                                  ;=============================================================================
  2727                                  
  2728                                  bss_start:
  2729                                  
  2730                                  ABSOLUTE bss_start
  2731                                  
  2732 00001112 <res 00000002>          alignb 4
  2733                                  
  2734 00001114 <res 00000001>          stmo		resb	1 ; stereo or mono  
  2735 00001115 <res 00000001>          bps		resb	1 ; bits per sample (16)
  2736                                  
  2737 00001116 <res 0000001C>          smpRBuff:	resw	14	; 19/11/2016
  2738                                  
  2739 00001132 <res 00000001>          flags:		resb	1
  2740 00001133 <res 00000001>          irq_status:	resb 	1
  2741                                  
  2742 00001134 <res 00000001>          uLVI:		resb	1 
  2743 00001135 <res 00000001>          tLoop:		resb 	1
  2744                                  
  2745                                  ; 256 byte buffer for descriptor list
  2746 00001136 <res 00000002>          BDL_BUFFER:	resw	1		; segment of our 256byte BDL buffer
  2747 00001138 <res 00000002>          DMA_BUFFER1:	resw 	1		; Pointer to 1st half of DMA Buffer
  2748 0000113A <res 00000002>          DMA_BUFFER2:	resw	1		; Pointer to 1st half of DMA Buffer
  2749                                  
  2750                                  ; 12/11/2016 - Erdogan Tan
  2751                                  
  2752 0000113C <res 00000001>          ac97_int_ln_reg: resb 1 
  2753 0000113D <res 00000001>          err_num:	resb 1
  2754                                  
  2755 0000113E <res 00000004>          bus_dev_fn:	resd 1
  2756 00001142 <res 00000004>          dev_vendor:	resd 1
  2757 00001146 <res 00000004>          stats_cmd:	resd 1
  2758 0000114A <res 00000002>          ac97_io_base:	resw 1
  2759                                  
  2760                                  alignb 4
  2761                                  
  2762 0000114C <res 00000100>          BdlBuffer:	resb	BDL_SIZE ; 13/02/2017
  2763 0000124C <res 00001000>          DmaBuffer:	resb	2*BUFFERSIZE ; 13/02/2017
  2764                                  
  2765                                  ; MODLOAD.ASM
  2766 0000224C <res 00000002>          FileHandle:	resw	1
  2767 0000224E <res 00000002>          ErrorInfo:	resw	1
  2768 00002250 <res 0000043C>          Header:		resb	ModHeader.size
  2769                                  
  2770                                  sample_rate: ; PLAYER.ASM (22050Hz)
  2771                                  ; MODPLAY.ASM
  2772 0000268C <res 00000002>          MixSpeed:	    resw 1
  2773                                  
  2774                                  ModInfo:
  2775 0000268E <res 00000001>          ModInfo.OrderLen:   resb 1
  2776 0000268F <res 00000001>          ModInfo.ReStart:    resb 1
  2777 00002690 <res 00000080>          ModInfo.Order:	    resb 128
  2778 00002710 <res 00000004>          ModInfo.Patterns:   resd 1
  2779                                  
  2780 00002714 <res 0000003E>          ModInfo.SampOfs:    resw 31
  2781 00002752 <res 0000003E>          ModInfo.SampSeg:    resw 31
  2782 00002790 <res 0000003E>          ModInfo.SampLen:    resw 31
  2783 000027CE <res 0000003E>          ModInfo.SampRep:    resw 31
  2784 0000280C <res 0000003E>          ModInfo.SampRepLen: resw 31
  2785 0000284A <res 0000003E>          ModInfo.SampVol:    resw 31
  2786                                  
  2787                                  ; MODPLAY.ASM
  2788 00002888 <res 000006B2>          PitchTable:	resw	857
  2789 00002F3A <res 00004100>          VolTable:	resb	16640
  2790 0000703A <res 00001000>          MixBuffer       resb	MixBufSize
  2791                                  
  2792                                  ; MODPLAY.ASM
  2793 0000803A <res 00000001>          OrderPos:	resb 1
  2794 0000803B <res 00000001>          Tempo:		resb 1
  2795 0000803C <res 00000001>          TempoWait:	resb 1
  2796 0000803D <res 00000001>          Bpm:		resb 1
  2797 0000803E <res 00000001>          Row:		resb 1
  2798 0000803F <res 00000001>          BreakRow:	resb 1
  2799 00008040 <res 00000002>          BpmSamples:	resw 1
  2800 00008042 <res 00000002>          BufPtr:		resw 1
  2801 00008044 <res 00000002>          BufLen:		resw 1
  2802 00008046 <res 00000002>          BufRep:		resw 1
  2803 00008048 <res 00000004>          Note:		resd 1
  2804 0000804C <res 00000088>          Tracks:		resb TrackInfo.size*NumTracks
  2805                                  
  2806 000080D4 <res 0000000C>          alignb 16
  2807                                  
  2808                                  ; PLAY.ASM
  2809 000080E0 <res 00000280>          Scope:		resw	320
  2810 00008360 <res 00000200>          RowOfs:		resw	256
  2811                                  
  2812                                  EOF:
