     1                                  ; ****************************************************************************
     2                                  ; playmod2.asm (for MSDOS)
     3                                  ; ----------------------------------------------------------------------------
     4                                  ; PLAYMOD2.COM ! ICH AC97 MOD PLAYER & VGA DEMO program by Erdogan TAN
     5                                  ;
     6                                  ; 18/02/2017
     7                                  ;
     8                                  ; [ Last Modification: 20/05/2024 ]
     9                                  ;
    10                                  ; Derived from source code of 'PLAYWAV.COM' ('PLAYWAV.ASM') by Erdogan Tan
    11                                  ;							      (17/02/2017)
    12                                  ; Modified from 'PLAYMOD.COM' ('playmod.asm') source code 
    13                                  ;		 VIA VT8237 MOD PLAYER & VGA DEMO program by Erdogan TAN
    14                                  ;							     (15/02/2017)
    15                                  ;
    16                                  ; Derived from source code of 'PLAY.EXE' (TINYPLAY) by Carlos Hasan (1993)
    17                                  ;          PLAY.EXE: PLAY.ASM, MODLOAD.ASM, MODPLAY.ASM, SB.ASM
    18                                  ;
    19                                  ; Assembler: NASM 2.11
    20                                  ; ----------------------------------------------------------------------------
    21                                  ;	   nasm  playmod2.asm -l playmod2.lst -o PLAYMOD2.COM	
    22                                  ; ****************************************************************************
    23                                  
    24                                  ; Tiny MOD Player v0.1b by Carlos Hasan.
    25                                  ;		July 14th, 1993.
    26                                  
    27                                  ;=============================================================================
    28                                  ;               PLAYWAV.ASM / PLAYER.ASM / TINYPLAY.ASM
    29                                  ;=============================================================================
    30                                  ; Audio controller, codec & PCI functions are derived from '.wav file player 
    31                                  ; for DOS' source code by Jeff Leyda (PLAYER.EXE), Sep 02, 2002.
    32                                  
    33                                  ; TUNELOOP version ; 12/05/2024
    34                                  ; PLAYMODM.ASM (15/04/2024)
    35                                  
    36                                  [BITS 16]
    37                                  [org 100h]
    38                                  
    39                                  Start:
    40 00000000 E8CC00                  	call    DetectICH		; Detect AC97 Audio Device
    41                                  GetFileName:    			; Parse  the Command line...
    42 00000003 BE8000                  	mov	si, 80h
    43 00000006 8A1C                    	mov	bl, [si]
    44 00000008 30FF                    	xor	bh, bh
    45 0000000A 43                      	inc	bx
    46 0000000B C60000                  	mov	byte [si+bx], 0		; make AsciiZ filename.
    47 0000000E 46                      	inc	si
    48                                  ScanName:       
    49 0000000F AC                      	lodsb
    50 00000010 84C0                    	test	al, al
    51 00000012 0F84AF00                	je	pmsg_2017
    52 00000016 3C20                    	cmp	al, 20h
    53 00000018 74F5                    	je	short ScanName		; scan start of name.
    54 0000001A 89F7                    	mov	di, si
    55 0000001C 4F                      	dec	di
    56                                  ScanPeriod:
    57 0000001D AC                      	lodsb
    58 0000001E 3C2E                    	cmp	al, '.'			; if period NOT found,
    59 00000020 7410                    	je	short PrintMesg		; then add a .MOD extension.
    60 00000022 84C0                    	test	al, al
    61 00000024 75F7                    	jnz	short ScanPeriod
    62 00000026 4E                      	dec	si
    63                                  SetExt:
    64                                  	;mov	byte [si+0], '.'
    65                                  	;mov	byte [si+1], 'M'
    66                                  	;mov	byte [si+2], 'O'
    67                                  	;mov	byte [si+3], 'D'
    68 00000027 66C7042E4D4F44          	mov	dword [si], '.MOD'
    69 0000002E C6440400                	mov	byte [si+4], 0
    70                                  
    71                                  PrintMesg:
    72 00000032 B80009                  	mov	ax, 0900h		; Prints the Credits Text.
    73                                  	;lea	dx, [Credits]
    74 00000035 BA[0E0E]                	mov	dx, Credits
    75 00000038 CD21                    	int	21h
    76                                  
    77                                  	; 13/05/2024
    78 0000003A E8320C                  	call	write_ac97_dev_info
    79 0000003D B80009                  	mov	ax, 0900h		; Prints the Credits Text.
    80 00000040 BA[3F0E]                	mov	dx, CRLF
    81 00000043 CD21                    	int	21h
    82                                  LoadMod:  
    83                                  	; es:di = Filename address
    84 00000045 06                      	push	es
    85 00000046 57                      	push	di
    86 00000047 E84A05                  	call    LoadModule		; Load the MODule...
    87                                  
    88 0000004A 833E[FA60]00            	cmp     word [ErrorInfo], 0	; any error loading?
    89 0000004F 740A                    	je      short init_codec
    90                                  
    91 00000051 B80009                  	mov     ax, 0900h		; yes, print error and Exit.
    92                                  	;lea    dx, [ErrorMesg]
    93 00000054 BA[420E]                	mov	dx, ErrorMesg
    94 00000057 CD21                    	int     21h
    95 00000059 EB63                    	jmp     Exit
    96                                  
    97                                  init_codec:
    98                                  	; 13/05/2024
    99                                  	;call	write_ac97_dev_info
   100                                  
   101                                  	; 08/05/2024
   102                                  	; 17/02/2017
   103                                  	;mov	dx, [stats_cmd]
   104                                          ;or	dl, IO_ENA+BM_ENA		; enable IO and bus master
   105                                          ;call	pciRegWrite16 ; pciRegWrite8
   106                                  
   107                                  	; 18/02/2017
   108                                  	;mov	word [sample_rate], 22050	; Mixing at 22.050 kHz
   109                                  	; 14/05/2024
   110 0000005B C706[3865]C05D          	mov	word [sample_rate], 24000
   111                                  
   112                                  	; 08/05/2024
   113                                  	; (48 kHZ mixing is necessary 
   114                                  	;  if the AC97 hardware/codec has not got VRA feature)
   115                                  	; ((or frequency converting code would be needed))
   116                                  	;mov	word [sample_rate], 48000	; Mixing at 48 kHz
   117                                  
   118                                  ; setup the Codec (actually mixer registers)
   119 00000061 E8FD01                          call    codecConfig			; unmute codec, set rates.
   120 00000064 731A                    	jnc	short PlayNow
   121                                  
   122                                  _codec_err:
   123 00000066 0E                      	push	cs
   124 00000067 1F                      	pop	ds
   125 00000068 BA[7100]                        mov	dx, CodecErrMsg
   126 0000006B B409                            mov     ah, 9
   127 0000006D CD21                            int     21h
   128 0000006F EB4D                            jmp     Exit
   129                                  
   130 00000071 436F64656320457272-     CodecErrMsg db "Codec Error!"
   130 0000007A 6F7221             
   131 0000007D 0D0A24                  	db	CR,LF,"$"
   132                                  PlayNow:  
   133 00000080 B8[F80F]                	mov	ax, BdlBuffer
   134 00000083 A3[E60F]                	mov	[BDL_BUFFER], ax
   135                                      
   136 00000086 B8[F810]                	mov	ax, DmaBuffer		; DmaBuffer (4096 bytes) buff addr
   137 00000089 A3[E80F]                	mov	[DMA_BUFFER1], ax	; 2048 byte half buffer 1
   138                                  
   139 0000008C 050028                  	add	ax, BUFFERSIZE		; code/current segment
   140 0000008F A3[EA0F]                	mov	[DMA_BUFFER2], ax	; 2048 byte half buffer 2
   141                                    
   142                                  	;mov    word [MixSpeed], 22050	; Mixing at 22.050 kHz
   143                                  
   144 00000092 E8CD0A                  	call    StartPlaying
   145                                  
   146 00000095 B81300                  	mov     ax, 0013h		; Set Mode 320x200x256
   147 00000098 CD10                    	int     10h
   148                                  
   149 0000009A B98000                  	mov     cx, 128			; Make a lookup table
   150 0000009D 31DB                    	xor     bx, bx			; for fastest pixel
   151 0000009F BA002D                  	mov     dx, 320*(100-64)	; addressing.
   152                                  MakeOfs:        
   153 000000A2 8997[00C2]              	mov     [RowOfs+bx], dx
   154 000000A6 8997[02C2]              	mov     [RowOfs+bx+2], dx
   155 000000AA 81C24001                	add     dx, 320
   156 000000AE 83C304                  	add     bx, 4
   157 000000B1 E2EF                    	loop    MakeOfs
   158                                  
   159                                  ; Note: Normally IRQ 0 calls the ModPlay Polling at 18.2Hz thru
   160                                  ;       the software interrupt 1Ch. If the IRQ 0 is disabled, then
   161                                  ;       the INT 1Ch MUST BE CALLED at least MixSpeed/1024 times per
   162                                  ;       second, or the module will sound "looped".
   163                                  ;       Because we need better sync with the ModPlayer to draw the scope,
   164                                  ;       the polling is called from my routine, and then the irq 0 must be
   165                                  ;       disabled. The [DmaBuffer] points to the current buffer of 8-bit
   166                                  ;       samples played by the Sound Blaster. Note that some samples are
   167                                  ;       discarded in the next code, just for fun!
   168                                  
   169                                  	;in	al, 21h			; disable irq 0!
   170                                  	;or	al, 00000001b
   171                                  	;out	21h, al
   172                                  		
   173 000000B3 E87503                  	call	ModPlay ; 13/02/2017
   174                                  
   175                                  	;in	al, 21h			; enable irq 0!
   176                                  	;and	al, 11111110b
   177                                  	;out	21h, al
   178                                  
   179 000000B6 B80300                  	mov     ax, 0003h		; Set Text Mode 80x25x16
   180 000000B9 CD10                    	int     10h
   181                                  
   182 000000BB E8250B                  	call	StopPlaying		; STOP!
   183                                  Exit:           
   184                                  	;call   FreeModule		; Free MODule core.
   185                                  error_exit:
   186 000000BE B8004C                  	mov     ax, 4C00h		; Bye!
   187 000000C1 CD21                    	int     21h
   188                                  here:
   189 000000C3 EBFE                    	jmp	short here
   190                                  
   191                                  pmsg_2017:
   192 000000C5 B80009                  	mov     ax, 0900h		; Prints the Credits Text.
   193                                  	;lea    dx, [msg_2017]
   194 000000C8 BA[AE0D]                	mov	dx, msg_2017
   195 000000CB CD21                    	int     21h
   196 000000CD EBEF                    	jmp	short Exit
   197                                  
   198                                  DetectICH:
   199                                  	; 18/02/2017
   200                                  	; Detech Intel ICH based AC97 Audio Device 
   201 000000CF E84E01                  	call    pciFindDevice 	; AC97.ASM (PLAYWAV.COM)
   202 000000D2 733F                            jnc     short _1
   203                                  
   204                                  ; couldn't find the audio device!
   205                                  	;push	cs
   206                                  	;pop	ds
   207 000000D4 BA[DD00]                        mov     dx, noDevMsg
   208 000000D7 B409                            mov     ah, 9
   209 000000D9 CD21                            int     21h
   210 000000DB EBE1                            jmp     short error_exit
   211                                  
   212 000000DD 4572726F723A20556E-     noDevMsg db "Error: Unable to find Intel ICH based audio device!",CR,LF,"$"
   212 000000E6 61626C6520746F2066-
   212 000000EF 696E6420496E74656C-
   212 000000F8 204943482062617365-
   212 00000101 6420617564696F2064-
   212 0000010A 6576696365210D0A24 
   213                                  
   214                                  _1:
   215                                  	; 18/02/2017
   216                                  	; eax = BUS/DEV/FN
   217                                  	;	00000000BBBBBBBBDDDDDFFF00000000
   218                                  	; edx = DEV/VENDOR
   219                                  	;	DDDDDDDDDDDDDDDDVVVVVVVVVVVVVVVV
   220                                  
   221 00000113 66A3[EE0F]              	mov	[bus_dev_fn], eax
   222 00000117 668916[F20F]            	mov	[dev_vendor], edx
   223                                  
   224                                  	; get ICH base address regs for mixer and bus master
   225                                  
   226 0000011C B010                            mov     al, NAMBAR_REG
   227 0000011E E87100                          call    pciRegRead16			; read PCI registers 10-11
   228                                          ;and    dx, IO_ADDR_MASK 		; mask off BIT0
   229                                  	; 14/05/2024
   230 00000121 80E2FE                  	and	dl, 0FEh
   231                                  
   232 00000124 8916[D80F]                      mov     [NAMBAR], dx			; save audio mixer base addr
   233                                  
   234 00000128 B014                    	mov     al, NABMBAR_REG
   235 0000012A E86500                          call    pciRegRead16
   236                                          ;and    dx, IO_ADDR_MASK
   237                                  	;/14/05/2024
   238 0000012D 80E2C0                  	and	dl, 0C0h
   239                                  
   240 00000130 8916[DA0F]                      mov     [NABMBAR], dx			; save bus master base addr
   241                                  
   242                                  	; 08/05/2024
   243                                  	; 06/11/2023
   244                                  	;; init controller
   245                                  	;; 17/02/2017
   246                                  	;mov	al, PCI_CMD_REG ; command register (04h)
   247                                  	;call	pciRegRead16 ; pciRegRead8
   248                                  	;
   249                                  	;; eax = BUS/DEV/FN/REG
   250                                  	;;  dx = PCI Command Register Content ; 17/02/2017
   251                                  	;; 	00000000CCCCCCCC
   252                                  	;mov	[stats_cmd], dx
   253                                  	;
   254                                  	; 06/11/2023
   255                                  	;mov	al, PCI_IO_BASE ; IO base address register (10h)
   256                                  	;call	pciRegRead32
   257                                  	;
   258                                  	;and	dx, 0FFC0h	; IO_ADDR_MASK (0FFFE) ?
   259                                          ;mov	[ac97_io_base], dx
   260                                  
   261 00000134 B03C                    	mov	al, AC97_INT_LINE ; Interrupt line register (3Ch)
   262 00000136 E85100                  	call	pciRegRead8 ; 17/02/2017
   263                                  
   264 00000139 8816[EC0F]              	mov     [ac97_int_ln_reg], dl
   265                                  
   266                                  ; 12/05/2024 (tuneloop version)
   267                                  %if 0
   268                                  	; 28/11/2016
   269                                  	;mov	bx, 1	; 08/05/2024
   270                                  	xor	dh, dh	; 17/02/2017
   271                                  	; 10/11/2023
   272                                  	;mov	cx, dx
   273                                  	;shl	bx, cl
   274                                  
   275                                  	; 04/11/2023
   276                                  	cli
   277                                  
   278                                  	;not	bx
   279                                  	in	al, 0A1h ; irq 8-15
   280                                          mov	ah, al
   281                                          in	al, 21h  ; irq 0-7 
   282                                  
   283                                  	; 04/11/2023
   284                                  	; save IRQ status
   285                                  	mov	[IRQ_status], ax
   286                                  
   287                                  	; 08/05/2024
   288                                  	;mov	dx, 4D1h			;8259 ELCR1
   289                                          ;in	al, dx
   290                                  	;mov	ah, al
   291                                  	;mov	dx, 4D0h 
   292                                          ;in	al, dx
   293                                  	;;or	ax, bx        
   294                                  	;bts	ax, cx
   295                                  	;mov	dx, 4D0h
   296                                  	;out	dx, al                          ;set level-triggered mode
   297                                  	;mov	al, ah
   298                                  	;mov	dx, 4D1h
   299                                  	;out	dx, al                          ;set level-triggered mode
   300                                  
   301                                  	; 24/11/2016 - Erdogan Tan
   302                                  	;mov	bx, cx
   303                                  	; 10/11/2023
   304                                  	mov	bx, dx
   305                                  	mov	bl, [bx+irq_int]
   306                                  	shl	bx, 2 ; * 4
   307                                  
   308                                  	; set up interrupt vector
   309                                  	; 30/11/2016
   310                                  	push	es
   311                                  	xor	ax, ax
   312                                  	mov	es, ax
   313                                  	; 04/11/2023
   314                                  	; save interrupt vector
   315                                  	mov	ax, [es:bx]
   316                                  	mov	[IRQ_vector], ax
   317                                  	mov	ax, [es:bx+2]
   318                                  	mov	[IRQ_vector+2], ax
   319                                  
   320                                  	mov	word [es:bx], ac97_int_handler
   321                                  	mov	ax, cs
   322                                  	mov	[es:bx+2], ax
   323                                  	pop	es
   324                                  
   325                                  	; 04/11/2023
   326                                  	sti
   327                                  %endif
   328 0000013D C3                      	retn
   329                                  
   330                                  ; 12/05/2024 (tuneloop version)
   331                                  %if 0
   332                                  
   333                                  ac97_int_handler:
   334                                  	; 11/05/2024
   335                                  	; 11/11/2023
   336                                  	; 10/11/2023
   337                                  	; 17/02/2016
   338                                  	push	eax	; 11/11/2023
   339                                  	push	dx
   340                                  	; 05/11/2023
   341                                  	;push	cx
   342                                  	;push	bx
   343                                  	;push	si
   344                                  	;push	di
   345                                  
   346                                  	; 10/11/2023
   347                                  	; EOI at first
   348                                  	mov	al, 20h
   349                                  	test	byte [ac97_int_ln_reg], 8
   350                                  	jz	short _ih_0
   351                                  	out 	0A0h, al ; 20h	; EOI
   352                                  _ih_0:
   353                                  	out	20h, al  ; 20h	; EOI
   354                                  
   355                                  	; 11/11/2023
   356                                  	; 09/11/2023
   357                                  	mov	dx, GLOB_STS_REG
   358                                          add	dx, [NABMBAR]
   359                                  	in	eax, dx
   360                                  	
   361                                  	; 12/05/2024
   362                                  	; 09/11/2023,
   363                                          ;cmp	eax, 0FFFFFFFFh ; -1
   364                                  	;je	short _ih_2
   365                                  	
   366                                  	; 12/05/2024
   367                                  	;test	al, 40h		; PCM Out Interrupt
   368                                  	;jnz	short _ih_1
   369                                  
   370                                  	;test	eax, eax
   371                                  	;jz	short _ih_2
   372                                  	; 12/05/2024
   373                                  	test	ax, PCM_OUT_IRQ+BCIS
   374                                  	jnz	short _ih_1
   375                                  
   376                                   	;mov	dx, GLOB_STS_REG
   377                                          ;add	dx, [NABMBAR]
   378                                  	out	dx, eax
   379                                  	jmp	short _ih_2
   380                                  
   381                                  	; .....
   382                                  	;mov	al, 1
   383                                  	; 10/11/2023
   384                                  	;mov	[tLoop], al  ; 1
   385                                  
   386                                  	;cmp	[inside], al ; 1
   387                                  	;jnb	short _ih_3	; busy
   388                                  
   389                                  	;mov	[inside], al ; 1
   390                                  	;
   391                                  	;; 09/11/2023
   392                                          ;mov	dx, [NABMBAR]
   393                                          ;add	dx, PO_SR_REG	; set pointer to Status reg
   394                                  	;in	al, dx
   395                                  	;; 10/11/2023
   396                                  	;;;out	dx, eax
   397                                  	;;out	dx, al		; clear interrupt event
   398                                  	;			; (by writing 1 to same bits)
   399                                  	;
   400                                  	;;mov	[pcm_irq_status], al ; 05/11/2023
   401                                  	;test	al, BCIS ; Buffer Completion Interrupt Status (Bit 3)
   402                                  	;jz	short _ih_2
   403                                  	; .....
   404                                  
   405                                  _ih_1:
   406                                  	; 11/11/2023
   407                                  	push	eax
   408                                  
   409                                  	;mov	ax, 1Ch ; FIFOE(=16)+BCIS(=8)+LVBCI(=4)
   410                                  	;mov	dx, PO_SR_REG
   411                                          ;add	dx, [NABMBAR]
   412                                  	;out	dx, ax
   413                                  
   414                                  	; 10/11/2023
   415                                  	; 28/11/2016 - Erdogan Tan
   416                                  	call	tuneLoop
   417                                  
   418                                  	; 11/11/2023
   419                                  	pop	eax
   420                                  	mov	dx, GLOB_STS_REG
   421                                          add	dx, [NABMBAR]
   422                                  	out	dx, eax
   423                                  _ih_2:
   424                                  	; 11/11/2023
   425                                  	mov	dx, [NABMBAR]
   426                                  	add	dx, PO_SR_REG	; set pointer to Status reg
   427                                  	mov	ax, 1Ch
   428                                  	out	dx, ax
   429                                  
   430                                  ;	; 10/11/2023
   431                                  ;	mov	al, 20h
   432                                  ;	test	byte [ac97_int_ln_reg], 8
   433                                  ;	jz	short _ih_3
   434                                  ;	out 	0A0h, al ; 20h	; EOI
   435                                  ;_ih_3:
   436                                  ;	out	20h, al  ; 20h	; EOI
   437                                  ;_ih_4:
   438                                  	;mov	byte [inside], 0
   439                                  	;pop	di
   440                                  	;pop	si
   441                                  	;pop	bx
   442                                  	;pop	cx
   443                                  	pop	dx
   444                                  	pop	eax ; 11/11/2023
   445                                  	iret
   446                                  
   447                                  %endif
   448                                  
   449                                  ;=============================================================================
   450                                  ;               PCI.ASM
   451                                  ;=============================================================================
   452                                  
   453                                  ; EQUATES
   454                                  
   455                                  ;constants of stuff that seem hard to remember at times.
   456                                  
   457                                  TRUE  EQU 1
   458                                  FALSE EQU 0
   459                                  
   460                                  ENABLED  EQU 1
   461                                  DISABLED EQU 0
   462                                  
   463                                  BIT0  EQU 1
   464                                  BIT1  EQU 2
   465                                  BIT2  EQU 4
   466                                  BIT3  EQU 8
   467                                  BIT4  EQU 10h
   468                                  BIT5  EQU 20h
   469                                  BIT6  EQU 40h
   470                                  BIT7  EQU 80h
   471                                  BIT8  EQU 100h
   472                                  BIT9  EQU 200h
   473                                  BIT10 EQU 400h
   474                                  BIT11 EQU 800h
   475                                  BIT12 EQU 1000h
   476                                  BIT13 EQU 2000h
   477                                  BIT14 EQU 4000h
   478                                  BIT15 EQU 8000h
   479                                  BIT16 EQU 10000h
   480                                  BIT17 EQU 20000h
   481                                  BIT18 EQU 40000h
   482                                  BIT19 EQU 80000h
   483                                  BIT20 EQU 100000h
   484                                  BIT21 EQU 200000h
   485                                  BIT22 EQU 400000h
   486                                  BIT23 EQU 800000h
   487                                  BIT24 EQU 1000000h
   488                                  BIT25 EQU 2000000h
   489                                  BIT26 EQU 4000000h
   490                                  BIT27 EQU 8000000h
   491                                  BIT28 EQU 10000000h
   492                                  BIT29 EQU 20000000h
   493                                  BIT30 EQU 40000000h
   494                                  BIT31 EQU 80000000h
   495                                  
   496                                  ;special characters
   497                                  NUL     EQU 0
   498                                  NULL    EQU 0
   499                                  BELL    EQU 07
   500                                  BS      EQU 08
   501                                  TAB     EQU 09
   502                                  LF      EQU 10
   503                                  CR      EQU 13
   504                                  ESCAPE  EQU 27           ;ESC is a reserved word....
   505                                  
   506                                  
   507                                  ;file stuff
   508                                  READONLY  EQU   BIT0
   509                                  HIDDEN    EQU   BIT1
   510                                  SYSTEM    EQU   BIT2
   511                                  VOLUME    EQU   BIT3         ;ignored for file access
   512                                  DIRECTORY EQU   BIT4         ;must be 0 for file access
   513                                  ARCHIVE   EQU   BIT5
   514                                  SHAREABLE EQU   BIT7         ;for novell networks
   515                                  OPEN	EQU	2		; open existing file
   516                                  CREATE	EQU	1		; create new file
   517                                  
   518                                  
   519                                  ; PCI equates
   520                                  ; PCI function address (PFA)
   521                                  ; bit 31 = 1
   522                                  ; bit 23:16 = bus number     (0-255)
   523                                  ; bit 15:11 = device number  (0-31)
   524                                  ; bit 10:8 = function number (0-7)
   525                                  ; bit 7:0 = register number  (0-255)
   526                                  
   527                                  IO_ADDR_MASK    EQU     0FFFEh          ; mask off bit 0 for reading BARs
   528                                  PCI_INDEX_PORT  EQU     0CF8h
   529                                  PCI_DATA_PORT   EQU     0CFCh
   530                                  PCI32           EQU     BIT31           ; bitflag to signal 32bit access
   531                                  PCI16           EQU     BIT30           ; bitflag for 16bit access
   532                                  
   533                                  PCI_FN0         EQU     0 << 8
   534                                  PCI_FN1         EQU     1 << 8
   535                                  PCI_FN2         EQU     2 << 8
   536                                  PCI_FN3         EQU     3 << 8
   537                                  PCI_FN4         EQU     4 << 8
   538                                  PCI_FN5         EQU     5 << 8
   539                                  PCI_FN6         EQU     6 << 8
   540                                  PCI_FN7         EQU     7 << 8
   541                                  
   542                                  PCI_CMD_REG		EQU	04h		; reg 04, command reg
   543                                   IO_ENA			EQU	BIT0		; i/o decode enable
   544                                   MEM_ENA		EQU	BIT1		; memory decode enable
   545                                   BM_ENA                 EQU     BIT2		; bus master enable
   546                                  
   547                                  ; CODE
   548                                  
   549                                  ; AC97.ASM
   550                                  ; PCI device register reader/writers.
   551                                  ; NASM version: Erdogan Tan (29/11/2016)
   552                                  ; 		Last Update: 17/02/2017
   553                                  
   554                                  ;===============================================================
   555                                  ; 8/16/32bit PCI reader
   556                                  ;
   557                                  ; Entry: EAX=PCI Bus/Device/fn/register number
   558                                  ;           BIT30 set if 32 bit access requested
   559                                  ;           BIT29 set if 16 bit access requested
   560                                  ;           otherwise defaults to 8bit read
   561                                  ;
   562                                  ; Exit:  DL,DX,EDX register data depending on requested read size
   563                                  ;
   564                                  ; Note: this routine is meant to be called via pciRegRead8, pciRegread16,
   565                                  ;	or pciRegRead32, listed below.
   566                                  ;
   567                                  ; Note2: don't attempt to read 32bits of data from a non dword aligned reg
   568                                  ;	 number.  Likewise, don't do 16bit reads from non word aligned reg #
   569                                  ; 
   570                                  pciRegRead:
   571 0000013E 6653                    	push	ebx
   572 00000140 51                      	push	cx
   573 00000141 6689C3                          mov     ebx, eax                        ; save eax, dh
   574 00000144 88F1                            mov     cl, dh
   575 00000146 6625FFFFFFBF                    and     eax, (~PCI32)+PCI16             ; clear out data size request
   576 0000014C 660D00000080                    or      eax, BIT31                      ; make a PCI access request
   577 00000152 24FC                            and     al, ~3 ; NOT 3                  ; force index to be dword
   578                                  
   579 00000154 BAF80C                          mov     dx, PCI_INDEX_PORT
   580 00000157 66EF                            out     dx, eax                         ; write PCI selector
   581                                  
   582 00000159 BAFC0C                          mov     dx, PCI_DATA_PORT
   583 0000015C 88D8                            mov     al, bl
   584 0000015E 2403                            and     al, 3                           ; figure out which port to
   585 00000160 00C2                            add     dl, al                          ; read to
   586                                  
   587 00000162 66ED                    	in      eax, dx                         ; do 32bit read
   588 00000164 66F7C300000080                  test    ebx, PCI32
   589 0000016B 7403                            jz      short _pregr1
   590                                  
   591 0000016D 6689C2                          mov     edx, eax                        ; return 32bits of data
   592                                  _pregr1:
   593 00000170 89C2                    	mov     dx, ax                          ; return 16bits of data
   594 00000172 66F7C3000000C0                  test    ebx, PCI32+PCI16
   595 00000179 7502                            jnz     short _pregr2
   596 0000017B 88CE                            mov     dh, cl                          ; restore dh for 8 bit read
   597                                  _pregr2:
   598 0000017D 6689D8                          mov     eax, ebx                        ; restore eax
   599 00000180 6625FFFFFFBF                    and     eax, (~PCI32)+PCI16             ; clear out data size request
   600 00000186 59                      	pop	cx
   601 00000187 665B                    	pop	ebx
   602 00000189 C3                      	retn
   603                                  
   604                                  pciRegRead8:
   605 0000018A 6625FFFFFF3F                    and     eax, (~PCI16)+PCI32             ; set up 8 bit read size
   606 00000190 EBAC                            jmp     short pciRegRead		; call generic PCI access
   607                                  
   608                                  pciRegRead16:
   609 00000192 6625FFFFFF3F                    and     eax, (~PCI16)+PCI32		; set up 16 bit read size
   610 00000198 660D00000040                    or      eax, PCI16			; call generic PCI access
   611 0000019E EB9E                            jmp     short pciRegRead
   612                                  
   613                                  pciRegRead32:
   614 000001A0 6625FFFFFF3F                    and     eax, (~PCI16)+PCI32		; set up 32 bit read size
   615 000001A6 660D00000080                    or      eax, PCI32			; call generic PCI access
   616 000001AC EB90                            jmp     short pciRegRead
   617                                  
   618                                  ;===============================================================
   619                                  ; 8/16/32bit PCI writer
   620                                  ;
   621                                  ; Entry: EAX=PCI Bus/Device/fn/register number
   622                                  ;           BIT31 set if 32 bit access requested
   623                                  ;           BIT30 set if 16 bit access requested
   624                                  ;           otherwise defaults to 8bit read
   625                                  ;        DL/DX/EDX data to write depending on size
   626                                  ;
   627                                  ;
   628                                  ; note: this routine is meant to be called via pciRegWrite8, pciRegWrite16,
   629                                  ; 	or pciRegWrite32 as detailed below.
   630                                  ;
   631                                  ; Note2: don't attempt to write 32bits of data from a non dword aligned reg
   632                                  ;	 number.  Likewise, don't do 16bit writes from non word aligned reg #
   633                                  ;
   634                                  pciRegWrite:
   635 000001AE 6653                    	push	ebx
   636 000001B0 51                      	push	cx
   637 000001B1 6689C3                          mov     ebx, eax                        ; save eax, dx
   638 000001B4 89D1                            mov     cx, dx
   639 000001B6 660D00000080                    or      eax, BIT31                      ; make a PCI access request
   640 000001BC 6625FFFFFFBF                    and     eax, ~PCI16 ; NOT PCI16         ; clear out data size request
   641 000001C2 24FC                            and     al, ~3 ; NOT 3                  ; force index to be dword
   642                                  
   643 000001C4 BAF80C                          mov     dx, PCI_INDEX_PORT
   644 000001C7 66EF                            out     dx, eax                         ; write PCI selector
   645                                  
   646 000001C9 BAFC0C                          mov     dx, PCI_DATA_PORT
   647 000001CC 88D8                            mov     al, bl
   648 000001CE 2403                            and     al, 3                           ; figure out which port to
   649 000001D0 00C2                            add     dl, al                          ; write to
   650                                  
   651 000001D2 6689D0                          mov     eax, edx                        ; put data into eax
   652 000001D5 89C8                            mov     ax, cx
   653                                  
   654 000001D7 EE                              out     dx, al
   655 000001D8 66F7C3000000C0                  test    ebx, PCI16+PCI32                ; only 8bit access? bail
   656 000001DF 740C                            jz      short _pregw1
   657                                  
   658 000001E1 EF                              out     dx, ax                          ; write 16 bit value
   659 000001E2 66F7C300000040                  test    ebx, PCI16                      ; 16bit requested?  bail
   660 000001E9 7502                            jnz     short _pregw1
   661                                  
   662 000001EB 66EF                            out     dx, eax                         ; write full 32bit
   663                                  _pregw1:
   664 000001ED 6689D8                          mov     eax, ebx                        ; restore eax
   665 000001F0 6625FFFFFFBF                    and     eax, (~PCI32)+PCI16             ; clear out data size request
   666 000001F6 89CA                            mov     dx, cx                          ; restore dx
   667 000001F8 59                      	pop	cx
   668 000001F9 665B                    	pop	ebx
   669 000001FB C3                      	ret
   670                                  
   671                                  pciRegWrite8:
   672 000001FC 6625FFFFFF3F                    and     eax, (~PCI16)+PCI32		; set up 8 bit write size
   673 00000202 EBAA                            jmp     short pciRegWrite		; call generic PCI access
   674                                  
   675                                  pciRegWrite16:
   676 00000204 6625FFFFFF3F                    and     eax, (~PCI16)+PCI32		; set up 16 bit write size
   677 0000020A 660D00000040                    or      eax, PCI16			; call generic PCI access
   678 00000210 EB9C                            jmp     short pciRegWrite
   679                                  
   680                                  pciRegWrite32:
   681 00000212 6625FFFFFF3F                    and     eax, (~PCI16)+PCI32		; set up 32 bit write size
   682 00000218 660D00000080                    or      eax, PCI32			; call generic PCI access
   683 0000021E EB8E                            jmp     short pciRegWrite
   684                                  
   685                                  ; AC97.ASM (PLAYWAV.COM)
   686                                  ; 17/02/2017 (Modifed by Erdogan Tan for various ICH device IDs)
   687                                  ;===============================================================
   688                                  ; PCIFindDevice: scan through PCI space looking for a device+vendor ID
   689                                  ;
   690                                  ;  ENTRY: none
   691                                  ;; Entry: EAX=Device+Vendor ID
   692                                  ;
   693                                  ;  Exit: EAX=PCI address if device found
   694                                  ;	 EDX=Device+Vendor ID
   695                                  ;        CY clear if found, set if not found. EAX invalid if CY set.
   696                                  ;
   697                                  ; [old stackless] Destroys: ebx, esi, edi, cl
   698                                  ;
   699                                  pciFindDevice:
   700                                  	;push	cx
   701                                  	;push	eax ; *
   702                                  	;push	esi
   703                                  	;push	edi
   704                                  
   705                                   	;mov     esi, eax                ; save off vend+device ID
   706                                  
   707                                  	; 17/02/2017
   708 00000220 BE[D70E]                	mov	si, valid_ids	; address of Valid ICH (AC97) Device IDs
   709 00000223 B91500                  	mov	cx, valid_id_count
   710                                  pfd_0:
   711 00000226 66BF00FFFF7F                   	mov     edi, (80000000h - 100h) ; start with bus 0, dev 0 func 0
   712                                  nextPCIdevice:
   713 0000022C 6681C700010000                  add     edi, 100h
   714 00000233 6681FF00F8FF80                  cmp     edi, 80FFF800h		; scanned all devices?
   715                                          ;stc
   716                                          ;je 	short PCIScanExit       ; not found
   717 0000023A 720D                    	jb	short pfd_1
   718 0000023C 66BF00000080            	mov     edi, 80000000h
   719 00000242 83C604                  	add	si, 4 ; scan for next device ID
   720 00000245 E202                    	loop	pfd_1	 
   721 00000247 F9                      	stc	
   722                                  	;jmp 	short PCIScanExit
   723 00000248 C3                      	retn
   724                                  pfd_1:
   725 00000249 6689F8                          mov     eax, edi                ; read PCI registers
   726 0000024C E851FF                          call    pciRegRead32
   727                                          ;cmp    edx, esi                ; found device?
   728 0000024F 663B14                          cmp	edx, dword [si]
   729 00000252 75D8                    	jne     short nextPCIdevice
   730                                          ;clc
   731                                  PCIScanExit:
   732                                  	;pushf
   733 00000254 66B800000080            	mov	eax, BIT31
   734 0000025A 66F7D0                  	not	eax
   735 0000025D 6621F8                  	and	eax, edi		; return only bus/dev/fn #
   736                                  	;popf
   737                                  
   738                                  	;pop	edi
   739                                  	;pop	esi
   740                                  	;pop	edx ; *
   741                                  	;pop	cx
   742 00000260 C3                      	retn
   743                                  
   744                                  ;=============================================================================
   745                                  ;               CODEC.ASM
   746                                  ;=============================================================================
   747                                  
   748                                  ; EQUATES
   749                                  
   750                                  ;Codec registers.
   751                                  ;
   752                                  ;Not all codecs are created equal. Refer to the spec for your specific codec.
   753                                  ;
   754                                  ;All registers are 16bits wide.  Access to codec registers over the AC97 link
   755                                  ;is defined by the OEM.  
   756                                  ;
   757                                  ;Secondary codec's are accessed by ORing in BIT7 of all register accesses.
   758                                  ;
   759                                  
   760                                  ; each codec/mixer register is 16bits
   761                                  
   762                                  CODEC_RESET_REG                 equ     00      ; reset codec
   763                                  CODEC_MASTER_VOL_REG            equ     02      ; master volume
   764                                  CODEC_HP_VOL_REG                equ     04      ; headphone volume
   765                                  CODEC_MASTER_MONO_VOL_REG       equ     06      ; master mono volume
   766                                  CODEC_MASTER_TONE_REG           equ     08      ; master tone (R+L)
   767                                  CODEC_PCBEEP_VOL_REG            equ     0ah     ; PC beep volume
   768                                  CODEC_PHONE_VOL_REG             equ     0bh     ; phone volume
   769                                  CODEC_MIC_VOL_REG               equ     0eh     ; MIC volume
   770                                  CODEC_LINE_IN_VOL_REG           equ     10h     ; line input volume
   771                                  CODEC_CD_VOL_REG                equ     12h     ; CD volume
   772                                  CODEC_VID_VOL_REG               equ     14h     ; video volume
   773                                  CODEC_AUX_VOL_REG               equ     16h     ; aux volume
   774                                  CODEC_PCM_OUT_REG               equ     18h     ; PCM output volume
   775                                  CODEC_RECORD_SELECT_REG         equ     1ah     ; record select input
   776                                  CODEC_RECORD_VOL_REG            equ     1ch     ; record volume
   777                                  CODEC_RECORD_MIC_VOL_REG        equ     1eh     ; record mic volume
   778                                  CODEC_GP_REG                    equ     20h     ; general purpose
   779                                  CODEC_3D_CONTROL_REG            equ     22h     ; 3D control
   780                                  ; 24h is reserved
   781                                  CODEC_POWER_CTRL_REG            equ     26h     ; powerdown control
   782                                  CODEC_EXT_AUDIO_REG             equ     28h     ; extended audio
   783                                  CODEC_EXT_AUDIO_CTRL_REG        equ     2ah     ; extended audio control
   784                                  CODEC_PCM_FRONT_DACRATE_REG     equ     2ch     ; PCM out sample rate
   785                                  CODEC_PCM_SURND_DACRATE_REG     equ     2eh     ; surround sound sample rate
   786                                  CODEC_PCM_LFE_DACRATE_REG       equ     30h     ; LFE sample rate
   787                                  CODEC_LR_ADCRATE_REG            equ     32h     ; PCM in sample rate
   788                                  CODEC_MIC_ADCRATE_REG           equ     34h     ; mic in sample rate
   789                                  
   790                                  ; registers 36-7a are reserved on the ICH
   791                                  
   792                                  CODEC_VENDORID1_REG             equ     7ch     ; codec vendor ID 1
   793                                  CODEC_VENDORID2_REG             equ     7eh     ; codec vendor ID 2
   794                                  
   795                                  ; Mixer registers 0 through 51h reside in the ICH and are not forwarded over
   796                                  ; the AC97 link to the codec, which I think is a little weird.  Looks like
   797                                  ; the ICH makes it so you don't need a fully functional codec to play audio?
   798                                  ;
   799                                  ; whenever 2 codecs are present in the system, use BIT7 to access the 2nd
   800                                  ; set of registers, ie 80h-feh
   801                                  
   802                                  PRIMARY_CODEC                   equ     0       ; 0-7F for primary codec
   803                                  SECONDARY_CODEC                 equ     BIT7    ; 80-8f registers for 2ndary
   804                                  
   805                                  SAMPLE_RATE_441khz	equ     44100   ; 44.1Khz (cd quality) rate
   806                                  
   807                                  ; ----------------------------------------------------------------------------
   808                                  ; 17/02/2017
   809                                  PCI_IO_BASE	equ 10h			; = NAMBAR register offset
   810                                  AC97_INT_LINE   equ 3Ch			; AC97 Interrupt Line register offset
   811                                  
   812                                  ; ----------------------------------------------------------------------------
   813                                  ; ICH2AC97.INC
   814                                  ; ----------------------------------------------------------------------------
   815                                  
   816                                  ; PCI stuff
   817                                  
   818                                  ; Intel ICH2 equates. It is assumed that ICH0 and plain ole ICH are compatible.
   819                                  
   820                                  INTEL_VID       equ     8086h           ; Intel's PCI vendor ID
   821                                  
   822                                  ; 08/05/2024
   823                                  ; 03/11/2023 - Erdogan Tan (Ref: MenuetOS AC97 WAV Player source code, 2004)
   824                                  SIS_VID		equ	1039h
   825                                  NVIDIA_VID	equ	10DEh	 ; Ref: MPXPLAY/SBEMU/KOLIBRIOS AC97 source c.
   826                                  AMD_VID		equ	1022h
   827                                  
   828                                  ICH_DID         equ     2415h           ; ICH device ID
   829                                  ICH0_DID        equ     2425h           ; ICH0
   830                                  ICH2_DID        equ     2445h           ; ICH2 I think there are more ICHes.
   831                                                                          ; they all should be compatible.
   832                                  ; 08/05/2024
   833                                  ; 17/02/2017 (Erdogan Tan, ref: ALSA Device IDs, ALSA project)
   834                                  ICH3_DID	equ     2485h           ; ICH3
   835                                  ICH4_DID        equ     24C5h           ; ICH4
   836                                  ICH5_DID	equ     24D5h           ; ICH5
   837                                  ICH6_DID	equ     266Eh           ; ICH6
   838                                  ESB6300_DID	equ     25A6h           ; 6300ESB
   839                                  ESB631X_DID	equ     2698h           ; 631XESB
   840                                  ICH7_DID	equ	27DEh		; ICH7
   841                                  ; 03/11/2023 - Erdogan Tan (Ref: MenuetOS AC97 WAV Player source code, 2004)
   842                                  MX82440_DID	equ	7195h
   843                                  SI7012_DID	equ	7012h
   844                                  NFORCE_DID	equ	01B1h
   845                                  NFORCE2_DID	equ	006Ah
   846                                  AMD8111_DID	equ	746Dh
   847                                  AMD768_DID	equ	7445h
   848                                  ; 03/11/2023 - Erdogan Tan - Ref: MPXPLAY/SBEMU/KOLIBRIOS AC97 source code
   849                                  CK804_DID	equ	0059h
   850                                  MCP04_DID	equ	003Ah
   851                                  CK8_DID		equ	008Ah
   852                                  NFORCE3_DID	equ	00DAh
   853                                  CK8S_DID	equ	00EAh
   854                                  
   855                                  NAMBAR_REG      equ     10h             ; native audio mixer BAR
   856                                   NAM_SIZE       equ     256             ; 256 bytes required.
   857                                  
   858                                  NABMBAR_REG     equ     14h             ; native audio bus mastering BAR
   859                                   NABM_SIZE      equ     64              ; 64 bytes
   860                                  
   861                                  ; BUS master registers, accessed via NABMBAR+offset
   862                                  
   863                                  ; ICH supports 3 different types of register sets for three types of things
   864                                  ; it can do, thus:
   865                                  ;
   866                                  ; PCM in (for recording) aka PI
   867                                  ; PCM out (for playback) aka PO
   868                                  ; MIC in (for recording) aka MC
   869                                  
   870                                  PI_BDBAR_REG            equ     0       ; PCM in buffer descriptor BAR
   871                                  PO_BDBAR_REG            equ     10h     ; PCM out buffer descriptor BAR
   872                                  MC_BDBAR_REG            equ     20h     ; MIC in buffer descriptor BAR
   873                                  
   874                                  ; each buffer descriptor BAR holds a pointer which has entries to the buffer
   875                                  ; contents of the .WAV file we're going to play.  Each entry is 8 bytes long
   876                                  ; (more on that later) and can contain 32 entries total, so each BAR is
   877                                  ; 256 bytes in length, thus:
   878                                  
   879                                  BDL_SIZE                equ     32*8    ; Buffer Descriptor List size
   880                                  INDEX_MASK              equ     31      ; indexes must be 0-31
   881                                  
   882                                  
   883                                  
   884                                  PI_CIV_REG              equ     4       ; PCM in current Index value (RO)
   885                                  PO_CIV_REG              equ     14h     ; PCM out current Index value (RO)
   886                                  MC_CIV_REG              equ     24h     ; MIC in current Index value (RO)
   887                                  ;8bit read only
   888                                  ; each current index value is simply a pointer showing us which buffer
   889                                  ; (0-31) the codec is currently processing.  Once this counter hits 31, it
   890                                  ; wraps back to 0.
   891                                  ; this can be handy to know, as once it hits 31, we're almost out of data to
   892                                  ; play back or room to record!
   893                                  
   894                                  
   895                                  PI_LVI_REG              equ     5       ; PCM in Last Valid Index
   896                                  PO_LVI_REG              equ     15h     ; PCM out Last Valid Index
   897                                  MC_LVI_REG              equ     25h     ; MIC in Last Valid Index
   898                                  ;8bit read/write
   899                                  ; The Last Valid Index is a number (0-31) to let the codec know what buffer
   900                                  ; number to stop on after processing.  It could be very nasty to play audio
   901                                  ; from buffers that aren't filled with the audio we want to play.
   902                                  
   903                                  
   904                                  PI_SR_REG               equ     6       ; PCM in Status register
   905                                  PO_SR_REG               equ     16h     ; PCM out Status register
   906                                  MC_SR_REG               equ     26h     ; MIC in Status register
   907                                  ;16bit read/write
   908                                  ; status registers.  Bitfields follow:
   909                                  
   910                                  FIFO_ERR                equ     BIT4    ; FIFO Over/Underrun W1TC.
   911                                  
   912                                  BCIS                    equ     BIT3    ; buffer completion interrupt status.
   913                                                                          ; Set whenever the last sample in ANY
   914                                                                          ; buffer is finished.  Bit is only
   915                                                                          ; set when the Interrupt on Complete
   916                                                                          ; (BIT4 of control reg) is set.
   917                                  
   918                                  LVBCI                   equ     BIT2    ; Set whenever the codec has processed
   919                                                                          ; the last buffer in the buffer list.
   920                                                                          ; Will fire an interrupt if IOC bit is
   921                                                                          ; set. Probably set after the last
   922                                                                          ; sample in the last buffer is
   923                                                                          ; processed.  W1TC
   924                                  
   925                                                                          ; 
   926                                  CELV                    equ     BIT1    ; Current buffer == last valid.
   927                                                                          ; Bit is RO and remains set until LVI is
   928                                                                          ; cleared.  Probably set up the start
   929                                                                          ; of processing for the last buffer.
   930                                  
   931                                  
   932                                  DCH                     equ     BIT0    ; DMA controller halted.
   933                                                                          ; set whenever audio stream is stopped
   934                                                                          ; or something else goes wrong.
   935                                  
   936                                  PI_PICB_REG             equ     8       ; PCM in position in current buffer(RO)
   937                                  PO_PICB_REG             equ     18h     ; PCM out position in current buffer(RO)
   938                                  MC_PICB_REG             equ     28h     ; MIC in position in current buffer (RO)
   939                                  ;16bit read only
   940                                  ; position in current buffer regs show the number of dwords left to be
   941                                  ; processed in the current buffer.
   942                                  ; 
   943                                  
   944                                  PI_PIV_REG              equ     0ah     ; PCM in Prefected index value
   945                                  PO_PIV_REG              equ     1ah     ; PCM out Prefected index value
   946                                  MC_PIV_REG              equ     2ah     ; MIC in Prefected index value
   947                                  ;8bit, read only
   948                                  ; Prefetched index value register.
   949                                  ; tells which buffer number (0-31) has be prefetched.  I'd imagine this
   950                                  ; value follows the current index value fairly closely. (CIV+1)
   951                                  ;
   952                                  
   953                                  PI_CR_REG               equ     0bh     ; PCM in Control Register
   954                                  PO_CR_REG               equ     1bh     ; PCM out Control Register
   955                                  MC_CR_REG               equ     2bh     ; MIC in Control Register
   956                                  ; 8bit
   957                                  ; Control register *MUST* only be accessed as an 8bit value.
   958                                  ; Control register.  See bitfields below.
   959                                  ;
   960                                  
   961                                  IOCE                    equ     BIT4    ; interrupt on complete enable.
   962                                                                          ; set this bit if you want an intrtpt
   963                                                                          ; to fire whenever LVBCI is set.
   964                                  FEIFE                   equ     BIT3    ; set if you want an interrupt to fire
   965                                                                          ; whenever there is a FIFO (over or
   966                                                                          ; under) error.
   967                                  LVBIE                   equ     BIT2    ; last valid buffer interrupt enable.
   968                                                                          ; set if you want an interrupt to fire
   969                                                                          ; whenever the completion of the last
   970                                                                          ; valid buffer.
   971                                  RR                      equ     BIT1    ; reset registers.  Nukes all regs
   972                                                                          ; except bits 4:2 of this register.
   973                                                                          ; Only set this bit if BIT 0 is 0
   974                                  RPBM                    equ     BIT0    ; Run/Pause
   975                                                                          ; set this bit to start the codec!
   976                                  
   977                                  
   978                                  GLOB_CNT_REG            equ     2ch     ; Global control register
   979                                  SEC_RES_EN              equ     BIT5    ; secondary codec resume event 
   980                                                                          ; interrupt enable.  Not used here.
   981                                  PRI_RES_EN              equ     BIT4    ; ditto for primary. Not used here.
   982                                  ACLINK_OFF              equ     BIT3    ; Turn off the AC97 link
   983                                  ACWARM_RESET            equ     BIT2    ; Awaken the AC97 link from sleep.
   984                                                                          ; registers preserved, bit self clears
   985                                  ACCOLD_RESET            equ     BIT1    ; Reset everything in the AC97 and
   986                                                                          ; reset all registers.  Not self clearing
   987                                  
   988                                  GPIIE                   equ     BIT0    ; GPI Interrupt enable.
   989                                                                          ; set if you want an interrupt to
   990                                                                          ; fire upon ANY of the bits in the
   991                                                                          ; GPI (general pursose inputs?) not used.
   992                                  
   993                                  GLOB_STS_REG            equ     30h     ; Global Status register (RO)
   994                                  
   995                                  MD3                     equ     BIT17   ; modem powerdown status (yawn)
   996                                  AD3                     equ     BIT16   ; Audio powerdown status (yawn)
   997                                  RD_COMPLETE_STS         equ     BIT15   ; Codec read timed out. 0=normal
   998                                  BIT3SLOT12              equ     BIT14   ; shadowed status of bit 3 in slot 12
   999                                  BIT2SLOT12              equ     BIT13   ; shadowed status of bit 2 in slot 12
  1000                                  BIT1SLOT12              equ     BIT12   ; shadowed status of bit 1 in slot 12
  1001                                  SEC_RESUME_STS          equ     BIT11   ; secondary codec has resumed (and irqed)
  1002                                  PRI_RESUME_STS          equ     BIT10   ; primary codec has resumed (and irqed)
  1003                                  SEC_CODEC_RDY           equ     BIT9    ; secondary codec is ready for action
  1004                                  PRI_CODEC_RDY           equ     BIT8    ; Primary codec is ready for action
  1005                                                                          ; software must check these bits before
  1006                                                                          ; starting the codec!
  1007                                  MIC_IN_IRQ              equ     BIT7    ; MIC in caused an interrupt
  1008                                  PCM_OUT_IRQ             equ     BIT6    ; One of the PCM out channels IRQed
  1009                                  PCM_IN_IRQ              equ     BIT5    ; One of the PCM in channels IRQed
  1010                                  MODEM_OUT_IRQ           equ     BIT2    ; modem out channel IRQed
  1011                                  MODEM_IN_IRQ            equ     BIT1    ; modem in channel IRQed
  1012                                  GPI_STS_CHANGE          equ     BIT0    ; set whenever GPI's have changed.
  1013                                                                          ; BIT0 of slot 12 also reflects this.
  1014                                  
  1015                                  
  1016                                  ACC_SEMA_REG            equ     34h     ; Codec write semiphore register
  1017                                  CODEC_BUSY              equ     BIT0    ; codec register I/O is happening
  1018                                                                          ; self clearing
  1019                                  ;
  1020                                  ; Buffer Descriptors List
  1021                                  ; As stated earlier, each buffer descriptor list is a set of (up to) 32
  1022                                  ; descriptors, each 8 bytes in length.  Bytes 0-3 of a descriptor entry point
  1023                                  ; to a chunk of memory to either play from or record to.  Bytes 4-7 of an
  1024                                  ; entry describe various control things detailed below.
  1025                                  ; 
  1026                                  ; Buffer pointers must always be aligned on a Dword boundry.
  1027                                  ;
  1028                                  ;
  1029                                  
  1030                                  IOC                     equ     BIT31   ; Fire an interrupt whenever this
  1031                                                                          ; buffer is complete.
  1032                                  
  1033                                  BUP                     equ     BIT30   ; Buffer Underrun Policy.
  1034                                                                          ; if this buffer is the last buffer
  1035                                                                          ; in a playback, fill the remaining
  1036                                                                          ; samples with 0 (silence) or not.
  1037                                                                          ; It's a good idea to set this to 1
  1038                                                                          ; for the last buffer in playback,
  1039                                                                          ; otherwise you're likely to get a lot
  1040                                                                          ; of noise at the end of the sound.
  1041                                  
  1042                                  ;
  1043                                  ; Bits 15:0 contain the length of the buffer, in number of samples, which
  1044                                  ; are 16 bits each, coupled in left and right pairs, or 32bits each.
  1045                                  ; Luckily for us, that's the same format as .wav files.
  1046                                  ;
  1047                                  ; A value of FFFF is 65536 samples.  Running at 44.1Khz, that's just about
  1048                                  ; 1.5 seconds of sample time.  FFFF * 32bits is 1FFFFh bytes or 128k of data.
  1049                                  ;
  1050                                  ; A value of 0 in these bits means play no samples.
  1051                                  ;
  1052                                  
  1053                                  ; CODE
  1054                                  
  1055                                  ; AC97.ASM
  1056                                  
  1057                                  ; codec configuration code.  Not much here really.
  1058                                  ; NASM version: Erdogan Tan (29/11/2016)
  1059                                  
  1060                                  ; enable codec, unmute stuff, set output rate to 44.1
  1061                                  ; entry: ax = desired sample rate
  1062                                  ;
  1063                                  
  1064                                  ; 08/04/2024
  1065                                  %if 0
  1066                                  
  1067                                  codecConfig:
  1068                                  	; 17/02/2017 
  1069                                  	; 07/11/2016 (Erdogan Tan)
  1070                                  	PORT_NABM_GLB_CTRL_STAT equ 60h
  1071                                  
  1072                                  	;mov    dx, [NAMBAR]               	; mixer base address
  1073                                  	;add	dx, CODEC_EXT_AUDIO_REG	       	; 28h
  1074                                  	;in	ax, dx
  1075                                  	;and	ax, 1
  1076                                  	;jnz	short _ssr
  1077                                  	;pop	ax
  1078                                  	;jmp	short cconf_1
  1079                                  
  1080                                  _ssr:
  1081                                  	mov    	dx, [NAMBAR]
  1082                                  	add    	dx, CODEC_EXT_AUDIO_CTRL_REG  	; 2Ah
  1083                                  	in     	ax, dx
  1084                                  	or	ax, 1
  1085                                  	out	dx, ax 				; Enable variable rate audio
  1086                                  
  1087                                          call    delay1_4ms
  1088                                          call    delay1_4ms
  1089                                          call    delay1_4ms
  1090                                          call    delay1_4ms
  1091                                  
  1092                                  	mov	ax, [sample_rate] ; 17/02/2017 (Erdogan Tan)
  1093                                  
  1094                                  	mov    	dx, [NAMBAR]
  1095                                  	add    	dx, CODEC_PCM_FRONT_DACRATE_REG	; 2Ch
  1096                                  	out	dx, ax 				; out sample rate
  1097                                  		
  1098                                  	;mov    dx, [NAMBAR]
  1099                                  	;add    dx, CODEC_LR_ADCRATE_REG 	; 32h
  1100                                  	;out	dx, ax 
  1101                                  
  1102                                          call    delay1_4ms
  1103                                          call    delay1_4ms
  1104                                          call    delay1_4ms
  1105                                          call    delay1_4ms
  1106                                  
  1107                                  ;cconf_1:
  1108                                  	mov     dx, [NAMBAR]			; mixer base address
  1109                                          add     dx, CODEC_RESET_REG  		; reset register
  1110                                          mov	ax, 42
  1111                                  	out     dx, ax                          ; reset
  1112                                  
  1113                                  	mov     dx, [NABMBAR]			; bus master base address
  1114                                          add     dx, PORT_NABM_GLB_CTRL_STAT
  1115                                          mov	ax, 2
  1116                                  	out     dx, ax
  1117                                  
  1118                                  	mov	cx, 7
  1119                                  _100ms:
  1120                                  	push	cx
  1121                                          call    delay1_4ms
  1122                                          call    delay1_4ms
  1123                                          call    delay1_4ms
  1124                                          call    delay1_4ms
  1125                                  	pop	cx
  1126                                  	loop	_100ms	
  1127                                  	
  1128                                    	mov     dx, [NAMBAR]
  1129                                    	add     dx, CODEC_MASTER_VOL_REG        ; 02h
  1130                                    	xor     ax, ax ; ; volume attenuation = 0 (max. volume)
  1131                                    	out     dx, ax
  1132                                   
  1133                                    	mov     dx, [NAMBAR]
  1134                                    	add     dx, CODEC_MASTER_MONO_VOL_REG   ; 06h
  1135                                    	;xor    ax, ax
  1136                                    	out     dx, ax
  1137                                  
  1138                                    	mov     dx, [NAMBAR]
  1139                                    	add     dx, CODEC_PCBEEP_VOL_REG        ; 0Ah
  1140                                    	;xor    ax, ax
  1141                                    	out     dx, ax
  1142                                  
  1143                                    	mov     dx, [NAMBAR]
  1144                                    	add     dx, CODEC_PCM_OUT_REG		; 18h
  1145                                    	;xor    ax, ax
  1146                                    	out     dx, ax
  1147                                  
  1148                                          call    delay1_4ms
  1149                                          call    delay1_4ms
  1150                                          call    delay1_4ms
  1151                                          call    delay1_4ms
  1152                                  
  1153                                          retn
  1154                                  
  1155                                  %else
  1156                                  	; 12/05/2024
  1157                                  	; 08/05/2024
  1158                                  	; (ac97_vra.asm, 19/11/2023, Erdogan Tan, playwav3.asm) 
  1159                                  codecConfig:
  1160                                  	; 02/12/2023
  1161                                  	; 26/11/2023
  1162                                  	; 21/11/2023
  1163                                  	; 20/11/2023
  1164                                  	; 19/11/2023 (TRDOS 386 v2.0.7)
  1165                                  	; 15/11/2023
  1166                                  	; 04/11/2023
  1167                                  	; 17/02/2017 
  1168                                  	; 07/11/2016 (Erdogan Tan)
  1169                                  	;PORT_NABM_GLB_CTRL_STAT equ 60h
  1170                                  
  1171                                  	; 03/11/2023 (MPXPLAY, 'SC_ICH.C', ac97_init)
  1172                                   	; 'AC97_DEF.H'
  1173                                  	;AC97_EXTENDED_STATUS equ 002Ah
  1174                                  	AC97_EA_SPDIF	equ 0002h
  1175                                  	AC97_EA_VRA	equ 0001h
  1176                                  	; 04/11/2023
  1177                                  	ICH_PO_CR_RESET equ 0002h  ; reset codec
  1178                                  	ICH_PCM_20BIT	equ 400000h ; 20-bit samples (ICH4)
  1179                                  	ICH_PCM_246_MASK equ 300000h ; 6 channels
  1180                                  
  1181                                  	; 08/05/2024
  1182                                  	; 11/11/2023
  1183                                  	CTRL_ST_CREADY	equ	BIT8+BIT9+BIT28 ; Primary Codec Ready
  1184                                  	CODEC_REG_POWERDOWN equ	26h
  1185                                  
  1186                                  	; 04/11/2023
  1187                                  init_ac97_controller:
  1188 00000261 66A1[EE0F]              	mov	eax, [bus_dev_fn]
  1189 00000265 B004                    	mov	al, PCI_CMD_REG
  1190 00000267 E828FF                  	call	pciRegRead16		; read PCI command register
  1191 0000026A 80CA05                  	or      dl, IO_ENA+BM_ENA	; enable IO and bus master
  1192 0000026D E894FF                  	call	pciRegWrite16
  1193                                  
  1194                                  	; 14/05/2024
  1195                                  	; 02/12/2023
  1196 00000270 E8AD01                  	call	delay_100ms ; 29/05/2017
  1197                                  
  1198                                  	; 02/12/2023
  1199                                  	;call	delay1_4ms
  1200                                  	;call	delay1_4ms
  1201                                  	;call	delay1_4ms
  1202                                  	;call	delay1_4ms
  1203                                  
  1204                                  init_ac97_codec:
  1205                                  	; 18/11/2023
  1206 00000273 BD2800                  	mov	bp, 40
  1207                                  	; 14/05/2024
  1208                                  	;mov	bp, 100
  1209                                  _initc_1:
  1210                                  	; 11/11/2023
  1211                                  	; (TRDOS 386 v2.0.5, 'audio.s')
  1212 00000276 BA2C00                  	mov	dx, GLOB_CNT_REG ; 2Ch
  1213 00000279 0316[DA0F]              	add	dx, [NABMBAR]
  1214 0000027D 66ED                    	in	eax, dx
  1215                                  
  1216                                  	; 14/05/2024
  1217                                  	; 02/12/2023
  1218 0000027F E86509                  	call	delay1_4ms
  1219                                  
  1220                                  	; ?
  1221                                  	;; 15/11/2023
  1222                                  	;;mov	cx, 40
  1223                                  	;mov	bp, 40 ; 18/11/2023
  1224                                  ;_initc_1:
  1225 00000282 BA3000                  	mov	dx, GLOB_STS_REG ; 30h
  1226 00000285 0316[DA0F]              	add	dx, [NABMBAR]
  1227 00000289 66ED                    	in	eax, dx
  1228                                  
  1229                                  	; 14/05/2024
  1230                                  	; 02/12/2023
  1231 0000028B E85909                  	call	delay1_4ms
  1232                                  
  1233 0000028E 6683F8FF                	cmp	eax, 0FFFFFFFFh ; -1
  1234                                  	;je	short init_ac97_codec_err1
  1235                                  	; 15/11/2023
  1236 00000292 7508                    	jne	short _initc_3
  1237                                  _initc_2:
  1238                                  	;dec	cx
  1239 00000294 4D                      	dec	bp	; 18/11/2023
  1240                                  	;jz	short init_ac97_codec_err1
  1241                                  	; 19/11/2023
  1242 00000295 7412                    	jz	short _ac97_codec_ready
  1243                                  
  1244 00000297 E88601                  	call	delay_100ms
  1245 0000029A EBDA                    	jmp	short _initc_1
  1246                                  _initc_3:
  1247 0000029C 66A900030010            	test	eax, CTRL_ST_CREADY
  1248 000002A2 7505                    	jnz	short _ac97_codec_ready
  1249                                  
  1250 000002A4 E8F900                  	call	reset_ac97_codec
  1251                                  	; 11/11/2023
  1252                                  	;jc	short init_ac97_codec_err2
  1253                                  	; 15/11/2023
  1254                                  	;jc	short _initc_2
  1255                                  	; 26/11/2023
  1256 000002A7 EBEB                    	jmp	short _initc_2
  1257                                  
  1258                                  _ac97_codec_ready:
  1259 000002A9 8B16[D80F]              	mov	dx, [NAMBAR]
  1260                                  	;add	dx, 0 ; ac_reg_0 ; reset register
  1261 000002AD EF                      	out	dx, ax
  1262                                  
  1263 000002AE E86F01                  	call	delay_100ms
  1264                                  
  1265                                  	; 19/11/2023
  1266 000002B1 09ED                    	or	bp, bp
  1267 000002B3 7529                    	jnz	short _ac97_codec_init_ok
  1268                                  
  1269 000002B5 6631C0                  	xor	eax, eax ; 0
  1270 000002B8 8B16[D80F]              	mov	dx, [NAMBAR]
  1271 000002BC 83C226                  	add	dx, CODEC_REG_POWERDOWN
  1272 000002BF EF                      	out	dx, ax
  1273                                  	
  1274                                  	; 19/11/2023
  1275                                  	; wait for 1 second
  1276                                  	; 14/05/2024
  1277                                  	;mov	ecx, 1000 ; 1000*4*0.25ms = 1s
  1278                                  	;mov	cx, 10
  1279                                  	; 20/05/2024
  1280 000002C0 66B928000000            	mov	ecx, 40
  1281                                  _ac97_codec_rloop:
  1282                                  	;call	delay1_4ms
  1283                                  	;call	delay1_4ms
  1284                                  	;call	delay1_4ms
  1285                                  	;call	delay1_4ms
  1286 000002C6 E85701                  	call	delay_100ms
  1287                                  	
  1288 000002C9 8B16[D80F]              	mov	dx, [NAMBAR]
  1289 000002CD 83C226                  	add	dx, CODEC_REG_POWERDOWN
  1290 000002D0 ED                      	in	ax, dx
  1291                                  
  1292                                  	; 14/05/2024
  1293                                  	; 02/12/2023
  1294 000002D1 E81309                  	call	delay1_4ms
  1295                                  	
  1296 000002D4 83E00F                  	and	ax, 0Fh
  1297 000002D7 3C0F                    	cmp	al, 0Fh
  1298 000002D9 7403                    	je	short _ac97_codec_init_ok
  1299 000002DB E2E9                    	loop	_ac97_codec_rloop
  1300                                  
  1301                                  	; 12/05/2024
  1302                                  	; cf = 1
  1303                                  init_ac97_codec_err1:
  1304                                  	;stc	; 12/05/2024
  1305                                  init_ac97_codec_err2:
  1306 000002DD C3                      	retn
  1307                                  
  1308                                  _ac97_codec_init_ok:
  1309                                          ; 11/11/2023
  1310                                  	;mov	al, 2 ; force set 16-bit 2-channel PCM
  1311                                  	;mov	dx, GLOB_CNT_REG ; 2Ch
  1312                                  	;add	dx, [NABMBAR]
  1313                                  	;out	dx, eax
  1314                                  
  1315                                  	;;call	delay1_4ms
  1316                                  
  1317 000002DE E87800                  	call 	reset_ac97_controller
  1318                                  
  1319                                  	; 11/11/2023
  1320                                  	;call	delay1_4ms
  1321                                  	; 21/11/2023 - temporary
  1322 000002E1 E83C01                  	call	delay_100ms
  1323                                  
  1324                                  	;call 	setup_ac97_codec
  1325                                  
  1326                                  setup_ac97_codec:
  1327                                  	; 08/05/2028
  1328                                  	; [sample_rate] = 22050
  1329                                  	; 12/11/2023
  1330                                  	;cmp	word [sample_rate], 48000
  1331                                  	;je	short skip_rate
  1332                                  
  1333                                  ; 11/11/2023
  1334                                  ; 05/11/2023
  1335                                  ;%if 1
  1336                                  	AC97_EA_VRA equ BIT0 ; 11/11/2023
  1337                                  
  1338                                  	; 18/05/2024
  1339 000002E4 E80009                  	call	delay1_4ms
  1340                                  
  1341                                  	; 16/05/2024
  1342 000002E7 8B16[D80F]              	mov	dx, [NAMBAR]
  1343 000002EB 83C228                  	add	dx, CODEC_EXT_AUDIO_REG	; 28h
  1344 000002EE ED                      	in	ax, dx
  1345                                  
  1346                                  	; 18/05/2024
  1347                                  	; 16/05/2024
  1348 000002EF E8F508                  	call	delay1_4ms
  1349                                  	; 17/05/2024
  1350                                  	;call	delay1_4ms
  1351                                  	;call	delay1_4ms
  1352                                  	;call	delay1_4ms
  1353                                  
  1354                                  	; 17/05/2024
  1355                                  	;call	delay_100ms
  1356                                  
  1357                                  	; 14/05/2024
  1358 000002F2 A801                    	test	al, 1 ; BIT0 ; Variable Rate Audio bit
  1359 000002F4 741D                    	jz	short vra_not_supported
  1360                                  
  1361                                  	; 11/11/2023
  1362 000002F6 8B16[D80F]              	mov    	dx, [NAMBAR]
  1363 000002FA 83C22A                  	add    	dx, CODEC_EXT_AUDIO_CTRL_REG ; 2Ah
  1364 000002FD ED                      	in     	ax, dx
  1365                                  
  1366                                  	; 14/05/2024
  1367                                  	; 02/12/2023
  1368 000002FE E8E608                  	call	delay1_4ms
  1369                                  
  1370 00000301 24FD                    	and	al, ~BIT1 ; Clear DRA
  1371 00000303 0C01                    	or	al, AC97_EA_VRA ; 1 ; 04/11/2023
  1372 00000305 EF                      	out	dx, ax			; Enable variable rate audio
  1373                                  	
  1374 00000306 B90A00                  	mov	cx, 10
  1375                                  check_vra:
  1376 00000309 E81401                  	call	delay_100ms
  1377                                  
  1378                                  	; 11/11/2023
  1379 0000030C ED                      	in	ax, dx
  1380 0000030D A801                    	test	al, AC97_EA_VRA ; 1
  1381 0000030F 750A                    	jnz	short set_rate
  1382                                  
  1383                                  	; 11/11/2023
  1384 00000311 E2F6                    	loop	check_vra
  1385                                  
  1386                                  	; 13/11/2023
  1387                                  	;mov	byte [VRA], 0
  1388                                  	; 14/05/2024
  1389                                  vra_not_supported:
  1390                                  	; 08/05/2024
  1391 00000313 C706[3865]80BB          	mov	word [sample_rate], 48000
  1392 00000319 EB0E                    	jmp	short skip_rate	
  1393                                  
  1394                                  	; 12/11/2023
  1395                                  	;pop	ax ; discard return address to the caller
  1396                                  	;mov	dx, msg_no_vra
  1397                                  	;jmp	vra_err
  1398                                  
  1399                                  set_rate:
  1400 0000031B A1[3865]                	mov	ax, [sample_rate] ; 17/02/2017 (Erdogan Tan)
  1401                                  	; 08/05/2024
  1402                                  	; ax = 22050 (Hz)
  1403                                  
  1404 0000031E 8B16[D80F]              	mov    	dx, [NAMBAR]               	
  1405 00000322 83C22C                  	add    	dx, CODEC_PCM_FRONT_DACRATE_REG	; 2Ch
  1406 00000325 EF                      	out	dx, ax 			; PCM Front/Center Output Sample Rate
  1407                                  
  1408 00000326 E8F700                  	call	delay_100ms
  1409                                  
  1410                                  	; 12/11/2023
  1411                                  skip_rate:
  1412                                  	; 11/11/2023 (temporary)
  1413                                  
  1414                                  	;mov   	dx, [NAMBAR]               	
  1415                                  	;add   	dx, CODEC_PCM_SURND_DACRATE_REG	; 2Eh
  1416                                  	;out	dx, ax 			; PCM Surround Output Sample Rate
  1417                                  
  1418                                  	;call	delay_100ms
  1419                                  
  1420                                  	;mov   	dx, [NAMBAR]               	
  1421                                  	;add   	dx, CODEC_PCM_LFE_DACRATE_REG	; 30h
  1422                                  	;out	dx, ax 			; PCM LFE Output Sample Rate
  1423                                  
  1424                                  	;call	delay_100ms
  1425                                  
  1426                                  	; 05/11/2023 (temporary)
  1427                                  	;mov	dx, [NAMBAR]               	
  1428                                  	;add	dx, CODEC_LR_ADCRATE_REG 	; 32h
  1429                                  	;out	dx, ax 			; PCM Input Sample Rate
  1430                                  	;
  1431                                  	;call	delay_100ms
  1432                                  
  1433 00000329 B80202                  	mov	ax, 0202h
  1434 0000032C A2[F70F]                	mov	[volume], al ; 29
  1435 0000032F 8B16[D80F]              	mov     dx, [NAMBAR]
  1436 00000333 83C202                    	add     dx, CODEC_MASTER_VOL_REG	; 02h
  1437 00000336 EF                      	out     dx, ax
  1438                                  
  1439                                  	; 11/11/2023
  1440                                          ;call	delay1_4ms
  1441                                          ;call	delay1_4ms
  1442                                          ;call	delay1_4ms
  1443                                          ;call	delay1_4ms
  1444                                   	;
  1445                                    	;mov	dx, [NAMBAR]
  1446                                    	;add	dx, CODEC_MASTER_MONO_VOL_REG	; 06h
  1447                                    	;out	dx, ax
  1448                                  
  1449                                  	; 11/11/2023
  1450                                          ;call	delay1_4ms
  1451                                          ;call	delay1_4ms
  1452                                          ;call	delay1_4ms
  1453                                          ;call	delay1_4ms
  1454                                  	;
  1455                                  	;mov	ax, 02h
  1456                                    	;mov	dx, [NAMBAR]
  1457                                    	;add	dx, CODEC_PCBEEP_VOL_REG	; 0Ah
  1458                                    	;out	dx, ax
  1459                                  
  1460                                  	; 14/05/2024	
  1461                                  	; 20/11/2023
  1462 00000337 E8AD08                          call	delay1_4ms
  1463 0000033A E8AA08                          call	delay1_4ms
  1464 0000033D E8A708                          call	delay1_4ms
  1465 00000340 E8A408                          call	delay1_4ms
  1466                                  
  1467                                  	; 21/11/2023 temporary
  1468                                  	;call	delay_100ms
  1469                                  
  1470                                  	;mov	ax, 0202h
  1471 00000343 8B16[D80F]                	mov     dx, [NAMBAR]
  1472 00000347 83C218                    	add     dx, CODEC_PCM_OUT_REG		; 18h
  1473 0000034A EF                        	out     dx, ax
  1474                                  
  1475                                  	; 14/05/2024
  1476                                  	; 20/11/2023
  1477 0000034B E89908                          call	delay1_4ms
  1478 0000034E E89608                          call	delay1_4ms
  1479 00000351 E89308                          call	delay1_4ms
  1480 00000354 E89008                          call	delay1_4ms
  1481                                  
  1482                                  	; 14/05/2024
  1483                                  	; 21/11/2023 - temporary
  1484                                  	;call	delay_100ms
  1485                                  
  1486                                  	; 11/11/2023
  1487                                  	;mov	ax, 8008h ; Mute
  1488                                    	;mov	dx, [NAMBAR]
  1489                                  	;add	dx, CODEC_PHONE_VOL_REG		; 0Ch
  1490                                  	;			 ; AC97_PHONE_VOL ; TAD Input (Mono)
  1491                                    	;out	dx, ax
  1492                                  	;
  1493                                          ;call	delay1_4ms
  1494                                          ;call	delay1_4ms
  1495                                          ;call	delay1_4ms
  1496                                  	;call	delay1_4ms
  1497                                  
  1498                                  	;mov	ax, 0808h
  1499                                  	;mov	dx, [NAMBAR]
  1500                                  	;add	dx, CODEC_LINE_IN_VOL_REG ;10h ; Line Input (Stereo)
  1501                                  	;out	dx, ax
  1502                                  	;
  1503                                          ;call	delay1_4ms
  1504                                          ;call	delay1_4ms
  1505                                          ;call	delay1_4ms
  1506                                  	;call	delay1_4ms
  1507                                  
  1508                                    	;mov	dx, [NAMBAR]
  1509                                          ;add	dx, CODEC_CD_VOL_REG ;12h ; CD Input (Stereo)
  1510                                    	;out	dx, ax
  1511                                  	;
  1512                                    	;mov	dx, [NAMBAR]
  1513                                          ;add	dx, CODEC_AUX_VOL_REG ;16h ; Aux Input (Stereo)
  1514                                    	;out	dx, ax
  1515                                  	;
  1516                                          ;call	delay1_4ms
  1517                                          ;call	delay1_4ms
  1518                                          ;call	delay1_4ms
  1519                                  	;call	delay1_4ms
  1520                                  
  1521                                  	; 14/05/2024
  1522                                  	;call	delay_100ms
  1523                                  
  1524                                  	; 14/05/2024
  1525 00000357 F8                      	clc
  1526                                  
  1527                                  ;detect_ac97_codec:
  1528 00000358 C3                              retn
  1529                                  
  1530                                  reset_ac97_controller:
  1531                                  	; 11/11/2023
  1532                                  	; 10/06/2017
  1533                                  	; 29/05/2017
  1534                                  	; 28/05/2017
  1535                                  	; reset AC97 audio controller registers
  1536 00000359 31C0                    	xor     ax, ax
  1537 0000035B BA0B00                          mov	dx, PI_CR_REG
  1538 0000035E 0316[DA0F]              	add	dx, [NABMBAR]
  1539 00000362 EE                      	out     dx, al
  1540                                  
  1541                                  	; 14/05/2024
  1542 00000363 E88108                  	call	delay1_4ms
  1543                                  
  1544 00000366 BA1B00                          mov     dx, PO_CR_REG
  1545 00000369 0316[DA0F]              	add	dx, [NABMBAR]
  1546 0000036D EE                      	out     dx, al
  1547                                  
  1548                                  	; 14/05/2024
  1549 0000036E E87608                  	call	delay1_4ms
  1550                                  
  1551 00000371 BA2B00                          mov     dx, MC_CR_REG
  1552 00000374 0316[DA0F]              	add	dx, [NABMBAR]
  1553 00000378 EE                      	out     dx, al
  1554                                  
  1555                                  	; 14/05/2024
  1556 00000379 E86B08                  	call	delay1_4ms
  1557                                  
  1558 0000037C B002                            mov     al, RR
  1559 0000037E BA0B00                          mov     dx, PI_CR_REG
  1560 00000381 0316[DA0F]              	add	dx, [NABMBAR]
  1561 00000385 EE                      	out     dx, al
  1562                                  
  1563                                  	; 14/05/2024
  1564 00000386 E85E08                  	call	delay1_4ms
  1565                                  
  1566 00000389 BA1B00                          mov     dx, PO_CR_REG
  1567 0000038C 0316[DA0F]              	add	dx, [NABMBAR]
  1568 00000390 EE                      	out     dx, al
  1569                                  
  1570                                  	; 14/05/2024
  1571 00000391 E85308                  	call	delay1_4ms
  1572                                  
  1573 00000394 BA2B00                          mov     dx, MC_CR_REG
  1574 00000397 0316[DA0F]              	add	dx, [NABMBAR]
  1575 0000039B EE                      	out     dx, al
  1576                                  
  1577                                  	; 14/05/2024
  1578 0000039C E84808                  	call	delay1_4ms
  1579                                  
  1580 0000039F C3                      	retn
  1581                                  
  1582                                  reset_ac97_codec:
  1583                                  	; 11/11/2023
  1584                                  	; 28/05/2017 - Erdogan Tan (Ref: KolibriOS, intelac97.asm)
  1585 000003A0 BA2C00                  	mov	dx, GLOB_CNT_REG ; 2Ch
  1586 000003A3 0316[DA0F]              	add	dx, [NABMBAR]
  1587 000003A7 66ED                    	in	eax, dx
  1588                                  
  1589                                  	;test	eax, 2
  1590                                  	; 06/08/2022
  1591 000003A9 A802                    	test	al, 2
  1592 000003AB 7405                    	jz	short _r_ac97codec_cold	
  1593                                  
  1594 000003AD E80E00                  	call	warm_ac97codec_reset
  1595 000003B0 7306                    	jnc	short _r_ac97codec_ok
  1596                                  _r_ac97codec_cold:
  1597 000003B2 E83400                          call    cold_ac97codec_reset
  1598 000003B5 7301                            jnc     short _r_ac97codec_ok
  1599                                  	
  1600                                  	; 16/04/2017
  1601                                          ;xor	eax, eax	; timeout error
  1602                                         	;stc
  1603 000003B7 C3                      	retn
  1604                                  
  1605                                  _r_ac97codec_ok:
  1606 000003B8 6631C0                          xor     eax, eax
  1607                                          ;mov	al, VIA_ACLINK_C00_READY ; 1
  1608 000003BB FEC0                            inc	al
  1609 000003BD C3                      	retn
  1610                                  
  1611                                  warm_ac97codec_reset:
  1612                                  	; 11/11/2023
  1613                                  	; 06/08/2022 - TRDOS 386 v2.0.5
  1614                                  	; 28/05/2017 - Erdogan Tan (Ref: KolibriOS, intelac97.asm)
  1615 000003BE 66B806000000            	mov	eax, 6
  1616 000003C4 BA2C00                  	mov	dx, GLOB_CNT_REG ; 2Ch
  1617 000003C7 0316[DA0F]              	add	dx, [NABMBAR]
  1618 000003CB 66EF                    	out	dx, eax
  1619                                  
  1620 000003CD B90A00                  	mov	cx, 10	; total 1s
  1621                                  _warm_ac97c_rst_wait:
  1622 000003D0 E84D00                  	call	delay_100ms
  1623                                  
  1624 000003D3 BA3000                  	mov	dx, GLOB_STS_REG ; 30h
  1625 000003D6 0316[DA0F]              	add	dx, [NABMBAR]
  1626 000003DA 66ED                    	in	eax, dx
  1627                                  
  1628 000003DC 66A900030010            	test	eax, CTRL_ST_CREADY
  1629 000003E2 7504                    	jnz	short _warm_ac97c_rst_ok
  1630                                  
  1631 000003E4 49                              dec     cx
  1632 000003E5 75E9                            jnz     short _warm_ac97c_rst_wait
  1633                                  
  1634                                  _warm_ac97c_rst_fail:
  1635 000003E7 F9                              stc
  1636                                  _warm_ac97c_rst_ok:
  1637 000003E8 C3                      	retn
  1638                                  
  1639                                  cold_ac97codec_reset:
  1640                                  	; 11/11/2023
  1641                                  	; 06/08/2022 - TRDOS 386 v2.0.5
  1642                                  	; 28/05/2017 - Erdogan Tan (Ref: KolibriOS, intelac97.asm)
  1643 000003E9 66B802000000                    mov	eax, 2
  1644 000003EF BA2C00                  	mov	dx, GLOB_CNT_REG ; 2Ch
  1645 000003F2 0316[DA0F]              	add	dx, [NABMBAR]
  1646 000003F6 66EF                    	out	dx, eax
  1647                                  
  1648 000003F8 E82500                  	call	delay_100ms 	; wait 100 ms
  1649 000003FB E82200                  	call	delay_100ms 	; wait 100 ms
  1650 000003FE E81F00                  	call	delay_100ms 	; wait 100 ms
  1651 00000401 E81C00                  	call	delay_100ms 	; wait 100 ms
  1652                                  
  1653 00000404 B91000                  	mov	cx, 16	; total 20*100 ms = 2s
  1654                                  
  1655                                  _cold_ac97c_rst_wait:
  1656 00000407 BA3000                  	mov	dx, GLOB_STS_REG ; 30h
  1657 0000040A 0316[DA0F]              	add	dx, [NABMBAR]
  1658 0000040E 66ED                    	in	eax, dx
  1659                                  
  1660 00000410 66A900030010            	test	eax, CTRL_ST_CREADY
  1661 00000416 7507                    	jnz	short _cold_ac97c_rst_ok
  1662                                  
  1663 00000418 E80500                  	call	delay_100ms
  1664                                  
  1665 0000041B 49                              dec     cx
  1666 0000041C 75E9                            jnz     short _cold_ac97c_rst_wait
  1667                                  
  1668                                  _cold_ac97c_rst_fail:
  1669 0000041E F9                              stc
  1670                                  _cold_ac97c_rst_ok:
  1671 0000041F C3                      	retn
  1672                                  
  1673                                  delay_100ms:
  1674                                  	; 11/11/2023
  1675                                  	; 29/05/2017
  1676                                  	; 24/03/2017 ('codec.asm')
  1677                                  	; wait 100 ms
  1678 00000420 51                      	push	cx
  1679 00000421 B99001                  	mov	cx, 400  ; 400*0.25ms
  1680                                  _delay_x_ms:
  1681 00000424 E8C007                  	call	delay1_4ms
  1682 00000427 E2FB                            loop	_delay_x_ms
  1683 00000429 59                      	pop	cx
  1684 0000042A C3                      	retn
  1685                                  
  1686                                  %endif
  1687                                  
  1688                                  ;=============================================================================
  1689                                  ;               ICH_WAV.ASM
  1690                                  ;=============================================================================
  1691                                  
  1692                                  ; DOS based .WAV player using AC'97 and codec interface.
  1693                                  ; ---------------------------------------------------------------
  1694                                  ; NASM version: Erdogan Tan (29/11/2016)
  1695                                  ; Last Update: 17/02/2017 (by Erdogan Tan)
  1696                                  
  1697                                  ; ICHWAV.ASM
  1698                                  ; PLAYMOD.ASM
  1699                                  ; player internal variables and other equates.
  1700                                  ;BUFFERSIZE	equ	2048*4		; 8K half buffer size. 18/02/2017
  1701                                  ; 14/05/2024
  1702                                  BUFFERSIZE	equ	2560*4
  1703                                  ENDOFFILE	equ	BIT0		; flag for knowing end of file
  1704                                  
  1705                                  ;===========================================================================
  1706                                  ; entry: none.  File is already open and [filehandle] filled.
  1707                                  ; exit:  not until the song is finished or the user aborts.
  1708                                  ;
  1709                                  ; 18/02/2017
  1710                                  ModPlay: ; 13/02/2017  ; ModPlay Polling!
  1711                                  	;cld
  1712                                  	; clear (half) buffer 2
  1713                                         	;mov	di, [DMA_BUFFER2]
  1714                                  	;sub	ax, ax
  1715                                  	;mov	cx, (BUFFERSIZE/2)
  1716                                  	;rep	stosw
  1717                                  
  1718                                  	; 15/05/2024
  1719 0000042B 06                      	push	es
  1720 0000042C 1E                      	push	ds
  1721 0000042D 07                      	pop	es
  1722 0000042E B94001                  	mov	cx, 320
  1723 00000431 BF[02C4]                	mov	di, MOD_BUFFER
  1724 00000434 B88080                  	mov	ax, 8080h
  1725 00000437 F3AB                    	rep	stosw
  1726 00000439 B900A0                  	mov	cx, 0A000h
  1727 0000043C 8EC1                    	mov	es, cx
  1728 0000043E E8EF00                  	call	ScopeLoop
  1729 00000441 07                      	pop	es
  1730                                  
  1731                                          ; load 2048 bytes into buffer 1
  1732 00000442 8B36[E80F]              	mov	si, [DMA_BUFFER1]
  1733                                  	; 11/05/2024
  1734                                  	;mov	cx, BUFFERSIZE
  1735                                  	;push	ds ; segment
  1736                                  	;push	si ; offset
  1737                                  	;push	cx ; count
  1738 00000446 E89B06                  	call    GetSamples_ICH ; 18/02/2017
  1739                                  
  1740                                          ; load 2048 bytes into buffer  2
  1741 00000449 8B36[EA0F]              	mov	si, [DMA_BUFFER2]
  1742                                  	; 11/05/2024
  1743                                  	;mov	cx, BUFFERSIZE
  1744                                  	;push	ds ; segment
  1745                                  	;push	si ; offset
  1746                                  	;push	cx ; count
  1747 0000044D E89406                  	call	GetSamples_ICH ; 18/02/2017
  1748                                  
  1749                                  ; register reset the DMA engine. This may cause a pop noise on the output
  1750                                  ; lines when the device is reset. Prolly a better idea to mute output, then
  1751                                  ; reset.
  1752                                  
  1753                                  	; 08/05/2024
  1754                                          ;mov    dx, [NABMBAR]
  1755                                          ;add    dx, PO_CR_REG		; set pointer to Ctrl reg
  1756                                          ;mov    al, RR			; set reset
  1757                                  	;out    dx, al			; self clearing bit
  1758                                  
  1759                                  ; write last valid index to 31 to start with.
  1760                                  ; The Last Valid Index register tells the DMA engine when to stop playing.
  1761                                  ; 
  1762                                  ; As we progress through the song we change the last valid index to always be
  1763                                  ; something other than the index we're currently playing.  
  1764                                  ;
  1765                                          ;;mov   al, 1
  1766                                          ;mov	al, 31
  1767                                  	;call   setLastValidIndex
  1768                                  
  1769                                  ; create Buffer Descriptor List
  1770                                  ;
  1771                                  ; A buffer descriptor list is a list of pointers and control bits that the
  1772                                  ; DMA engine uses to know where to get the .wav data and how to play it.
  1773                                  ;
  1774                                  ; I set it up to use only 2 buffers of .wav data, and whenever 1 buffer is
  1775                                  ; playing, I refresh the other one with good data.
  1776                                  ;
  1777                                  ;
  1778                                  ; For the control bits, you can specify that the DMA engine fire an interrupt
  1779                                  ; after a buffer has been processed, but I poll the current index register
  1780                                  ; to know when it's safe to update the other buffer.
  1781                                  ;
  1782                                  ; I set the BUP bit, which tells the DMA engine to just play 0's (silence)
  1783                                  ; if it ever runs out of data to play. Good for safety.
  1784                                  ;
  1785                                  	; 14/02/2017
  1786 00000450 8B3E[E60F]                      mov     di, [BDL_BUFFER]		; get BDL address
  1787 00000454 B91000                          mov     cx, 32 / 2                      ; make 32 entries in BDL
  1788 00000457 6631D2                  	xor	edx, edx
  1789 0000045A 8CDA                    	mov	dx, ds
  1790 0000045C 66C1E204                	shl	edx, 4 ; segment*16 (linear/physical address of the segment)
  1791                                  _0:
  1792                                  
  1793                                  ; set buffer descriptor 0 to start of data file in memory
  1794                                  	; 14/02/2017
  1795 00000460 660FB706[E80F]                  movzx   eax, word [DMA_BUFFER1]
  1796 00000466 6601D0                  	add	eax, edx ; linear/physical address of the buffer (seg*16+off)
  1797 00000469 66AB                            stosd					; store dmabuffer1 address
  1798                                  
  1799                                  ;
  1800                                  ; set length to 32k samples. 1 sample is 16bits or 2bytes.
  1801                                  ; Set control (bits 31:16) to BUP, bits 15:0=number of samples.
  1802                                  ; 
  1803                                  
  1804                                  ; 17/02/2017 (Erdogan Tan)
  1805                                  ; Intel 82801AA (ICH) & Intel 82801AB (ICH0) I/O Controller Hub AC 97
  1806                                  ; Programmers Reference Manual
  1807                                  
  1808                                  ; 2.2.1 Buffer Descriptor List  (on Page 13)
  1809                                  	;
  1810                                  	;  Generic Form of Buffer Descriptor
  1811                                  	;  ---------------------------------
  1812                                  	;  63   62    61-48    47-32   31-0
  1813                                  	;  ---  ---  --------  ------- -----
  1814                                  	;  IOC  BUP -reserved- Buffer  Buffer
  1815                                  	;		      Length   Pointer
  1816                                  	;		      [15:0]   [31:0]
  1817                                  	;
  1818                                  	;  IOC:	Interrupt On Completion. 
  1819                                  	;	1 = Enabled. 
  1820                                  	;	    When this is set, it means that the controller should
  1821                                  	;	    issue an interrupt upon completion of this buffer.
  1822                                  	;	    It should also set the IOC bit in the status register
  1823                                  	;	0 = Disabled	
  1824                                  	;
  1825                                  	;  BUP: Buffer Underrun Policy.
  1826                                  	;       0 = When this buffer is complete,
  1827                                  	;	    if the next buffer is not yet ready 
  1828                                  	;	    (i.e., the last valid buffer has been processed),
  1829                                  	;	    then continue to transmit the last valid sample.
  1830                                  	;	1 = When this buffer is complete,
  1831                                  	;     	    if this is the last valid buffer, transmit zeros after
  1832                                  	;	    this buffer has been processed completely.
  1833                                  	;	    This bit typically is set only if this is the last 
  1834                                  	;	    buffer in the current stream.
  1835                                  	;
  1836                                  	; [31:0]: Buffer pointer. This field points to the location of
  1837                                  	;	  the data buffer. Since samples can be as wide as one
  1838                                  	;	  word, the buffer must be aligned with word boundaries,
  1839                                  	;	  to prevent samples from straddling DWord boundaries.
  1840                                  	;
  1841                                  	; [15:0]: Buffer Length: This is the length of the data buffer,
  1842                                  	;	  in number of samples. The controller uses this data
  1843                                  	;	  to determine the length of the buffer, in bytes.
  1844                                  	;	  "0" indicates no sample to process.
  1845                                  
  1846                                  ; ICH2AC97.INC
  1847                                  
  1848                                  ;	IOC	equ     BIT31   ; Fire an interrupt whenever this
  1849                                  				; buffer is complete.
  1850                                  
  1851                                  ;	BUP	equ     BIT30   ; Buffer Underrun Policy.
  1852                                  				; if this buffer is the last buffer
  1853                                  				; in a playback, fill the remaining
  1854                                  				; samples with 0 (silence) or not.
  1855                                  				; It's a good idea to set this to 1
  1856                                  				; for the last buffer in playback,
  1857                                  				; otherwise you're likely to get a lot
  1858                                  				; of noise at the end of the sound.
  1859                                  ;
  1860                                  ; Bits 15:0 contain the length of the buffer, in number of samples, which
  1861                                  ; are 16 bits each, coupled in left and right pairs, or 32bits each.
  1862                                  ; Luckily for us, that's the same format as .wav files.
  1863                                  ;
  1864                                  ; A value of FFFF is 65536 samples. Running at 44.1Khz, that's just about
  1865                                  ; 1.5 seconds of sample time. FFFF * 32bits is 1FFFFh bytes or 128k of data.
  1866                                  ;
  1867                                  ; A value of 0 in these bits means play no samples.
  1868                                  ;
  1869                                  	; 08/12/2016 - Erdogan Tan
  1870                                  	;mov	eax, BUFFERSIZE
  1871                                  	;or	eax, IOC + BUP
  1872                                  	; 12/05/2024
  1873 0000046B 66B800140000            	mov	eax, BUFFERSIZE/2
  1874 00000471 660D00000040            	or	eax, BUP ; (tuneloop without interrupt)
  1875 00000477 66AB                    	stosd
  1876                                  
  1877                                  ; 2nd buffer:
  1878                                  	; 14/02/2017
  1879 00000479 660FB706[EA0F]                  movzx   eax, word [DMA_BUFFER2]
  1880 0000047F 6601D0                  	add	eax, edx ; linear/physical address of the buffer (seg*16+off)
  1881 00000482 66AB                            stosd					; store dmabuffer2 address
  1882                                  
  1883                                  ; set length to 64k (32k of two 16 bit samples)
  1884                                  ; Set control (bits 31:16) to BUP, bits 15:0=number of samples
  1885                                  ; 
  1886                                  	; 08/12/2016 - Erdogan Tan
  1887                                  	;mov	eax, BUFFERSIZE
  1888                                  	;or	eax, IOC + BUP
  1889                                  	; 12/05/2024
  1890 00000484 66B800140000            	mov	eax, BUFFERSIZE/2
  1891                                  	; 12/05/2024
  1892 0000048A 660D00000040            	or	eax, BUP ; (tuneloop without interrupt)
  1893 00000490 66AB                    	stosd
  1894 00000492 E2CC                            loop    _0
  1895                                  
  1896                                  ;
  1897                                  ; tell the DMA engine where to find our list of Buffer Descriptors.
  1898                                  ; this 32bit value is a flat mode memory offset (ie no segment:offset)
  1899                                  ;
  1900                                  ; write NABMBAR+10h with offset of buffer descriptor list
  1901                                  ;
  1902 00000494 660FB706[E60F]                  movzx   eax, word [BDL_BUFFER]
  1903                                  	; 14/02/2017
  1904 0000049A 6601D0                  	add	eax, edx ; linear/physical address of the BDL
  1905                                    	; 18/02/2017
  1906 0000049D 8B16[DA0F]                      mov     dx, [NABMBAR]
  1907 000004A1 83C210                          add     dx, PO_BDBAR_REG                ; set pointer to BDL
  1908 000004A4 66EF                            out     dx, eax                         ; write to AC97 controller
  1909                                  
  1910                                  ;
  1911                                  ; All set.  Let's play some music.
  1912                                  ;
  1913                                  	; 08/12/2016
  1914                                  	; 07/10/2016
  1915                                          ;mov    al, 1
  1916 000004A6 B01F                            mov	al, 31
  1917                                  	; 08/05/2024
  1918 000004A8 A2[F60F]                	mov	[LVI], al ; 10/11/2023
  1919                                  	
  1920 000004AB E8C800                  	call    setLastValidIndex
  1921                                  
  1922 000004AE C606[DF0F]01            	mov	byte [tLoop], 1 ; 30/11/2016
  1923                                  
  1924                                  ; 12/05/2024 (tuneloop, without interrupt)
  1925                                  %if 0
  1926                                  	; 12/05/2024	
  1927                                  	; 17/02/2017
  1928                                          ;mov    dx, [NABMBAR]
  1929                                          ;add    dx, PO_CR_REG                   ; PCM out Control Register
  1930                                          ;mov	al, IOCE + RPBM	; Enable 'Interrupt On Completion' + run
  1931                                  	;			; (LVBI interrupt will not be enabled)
  1932                                          ;out    dx, al                          ; Start bus master operation.
  1933                                  
  1934                                  ; while DMA engine is running, examine current index and wait until it hits 1
  1935                                  ; as soon as it's 1, we need to refresh the data in wavbuffer1 with another
  1936                                  ; 64k.  Likewise when it's playing buffer 2, refresh buffer 1 and repeat.
  1937                                     
  1938                                  	; 18/02/2017
  1939                                  	; 14/02/2017
  1940                                  	; 13/02/2017
  1941                                  	; 08/12/2016
  1942                                  	; 28/11/2016
  1943                                  
  1944                                  	push	es
  1945                                  	mov	ax, 0A000h
  1946                                  	mov	es, ax
  1947                                  	;mov	bp, DmaBuffer ; 14/02/2017
  1948                                  p_loop:
  1949                                  	mov     ah, 1			; any key pressed?
  1950                                  	int     16h			; no, Loop.
  1951                                  	jz	short q_loop
  1952                                  
  1953                                  	mov     ah, 0			; flush key buffer...
  1954                                  	int     16h
  1955                                  p_return:
  1956                                  	mov	byte [tLoop], 0	; 13/02/2017
  1957                                  	pop	es
  1958                                  	retn
  1959                                  q_loop:
  1960                                  	; 10/05/2024
  1961                                  	xor	ax, ax
  1962                                  	xchg	al, [tBuff] ; AL = [tBuff], [tBuff] = 0
  1963                                  	cmp	al, 1
  1964                                  	ja	short r_loop
  1965                                  	jb	short ScopeLoop
  1966                                  	;
  1967                                       	mov	si, [DMA_BUFFER1] ; [tBuff]=1 (from tuneLoop)
  1968                                         	jmp	short s_loop 
  1969                                  r_loop:
  1970                                  	; 13/02/2017
  1971                                          mov     si, [DMA_BUFFER2] ; [tBuff]=2 (from tuneLoop)
  1972                                  s_loop:
  1973                                  	; 14/02/2017
  1974                                  	;mov	bp, si ; save current buffer addres in bp register
  1975                                  	; 11/05/2024
  1976                                  	;mov	cx, BUFFERSIZE ; 2048*4 byte
  1977                                  	;push	ds ; segment
  1978                                  	;push	si ; offset
  1979                                  	;push	cx ; count
  1980                                  	call    GetSamples_ICH ; 18/02/2017
  1981                                  	;
  1982                                  ScopeLoop:
  1983                                  	;mov    si, bp			; get current samples
  1984                                  	mov	si, MOD_BUFFER ; 18/02/2017
  1985                                  	xor     cx, cx			; to be drawed ...
  1986                                  	xor     dx, dx
  1987                                  DrawLoop:       
  1988                                  	mov     bx, dx			; (save Index)
  1989                                  	mov     di, [Scope+bx]		; get old SCOPE pixel address
  1990                                  	mov     byte [es:di], 0		; erase it!
  1991                                  	lodsb				; get a sample (8-bit)
  1992                                  	mov     bl, al			; calc new pixel address...
  1993                                  	xor     bh, bh
  1994                                  	shl     bx, 1
  1995                                  	mov     di, [RowOfs+bx]
  1996                                  	add     di, cx
  1997                                  	mov     bx, dx			; (restore Index)
  1998                                  	mov     [Scope+bx], di		; save new address...
  1999                                  	mov     byte [es:di], 10 ; 0Ah	; and DRAW.
  2000                                  	add     dx, 2			; the next pixel...
  2001                                  	inc     cx
  2002                                  	cmp     cx, 320			; 320 pixels drawed?
  2003                                  	jb      short DrawLoop
  2004                                  	jmp	short p_loop
  2005                                  
  2006                                  tuneLoop:
  2007                                  	; 11/05/2024
  2008                                  	; 11/11/2023
  2009                                  	; 10/11/2023
  2010                                  	; 18/02/2017
  2011                                  	; 08/12/2016
  2012                                  	; 28/11/2016 - Erdogan Tan
  2013                                  
  2014                                  	; 11/05/2024
  2015                                  	cmp	byte [tLoop], 1
  2016                                  	jb	short tL3
  2017                                  	
  2018                                  	call    getCurrentIndex
  2019                                  
  2020                                  	; 10/11/2023
  2021                                  	cmp	al, [LVI]
  2022                                  	jne	short tL1
  2023                                  
  2024                                  	dec	ax
  2025                                  	and	al, 1Fh 
  2026                                  	call	setLastValidIndex
  2027                                  	xchg	al, [LVI]
  2028                                  tL1:
  2029                                  	test	al, BIT0
  2030                                  	jz	short tL2
  2031                                  
  2032                                  	; 11/05/2024
  2033                                  	mov	byte [tBuff], 1
  2034                                  	retn
  2035                                  tL2:	
  2036                                  	mov	byte [tBuff], 2
  2037                                  tL3:
  2038                                  	retn
  2039                                  
  2040                                  ; returns AL = current index value
  2041                                  getCurrentIndex:
  2042                                  	;push	dx
  2043                                  	mov	dx, [NABMBAR]
  2044                                  	add	dx, PO_CIV_REG
  2045                                  	in	al, dx
  2046                                  	;pop	dx
  2047                                  	retn
  2048                                  
  2049                                  ;input AL = index # to stop on
  2050                                  setLastValidIndex:
  2051                                  	;push	dx
  2052                                  	mov	dx, [NABMBAR]
  2053                                  	add	dx, PO_LVI_REG
  2054                                          out     dx, al
  2055                                  	;pop	dx
  2056                                  	retn
  2057                                  
  2058                                  %else
  2059                                  	; 12/05/2024
  2060                                  	; 17/02/2017
  2061 000004B3 8B16[DA0F]                      mov     dx, [NABMBAR]
  2062 000004B7 83C21B                          add     dx, PO_CR_REG		; PCM out Control Register
  2063                                          ;mov	al, IOCE + RPBM	; Enable 'Interrupt On Completion' + run
  2064                                  	;			; (LVBI interrupt will not be enabled)
  2065                                  	; 06/11/2023 (TUNELOOP version, without interrupt)
  2066 000004BA B001                    	mov	al, RPBM
  2067 000004BC EE                      	out     dx, al			; Start bus master operation.
  2068                                  
  2069 000004BD 06                      	push	es
  2070 000004BE B800A0                  	mov	ax, 0A000h
  2071 000004C1 8EC0                    	mov	es, ax
  2072                                  
  2073                                  	; 12/05/2024
  2074                                  ;p_loop:
  2075                                  ;	call	tuneLoop
  2076                                  ;	cmp	byte [tLoop], 0
  2077                                  ;	ja	short p_loop
  2078                                  ;	pop	es
  2079                                  ;	retn
  2080                                  
  2081                                  p_loop:
  2082 000004C3 B401                    	mov     ah, 1			; any key pressed?
  2083                                  	;mov	ah, 11h
  2084 000004C5 CD16                    	int     16h			; no, Loop.
  2085 000004C7 743D                    	jz	short q_loop
  2086                                  
  2087 000004C9 B400                    	mov	ah, 0
  2088                                  	;mov    ah, 10h			; flush key buffer...
  2089 000004CB CD16                    	int     16h
  2090                                  
  2091                                  	; 12/05/2024 (change PCM out volume)
  2092 000004CD 3C2B                    	cmp	al, '+'
  2093 000004CF 750B                    	jne	short p_1
  2094                                  	
  2095 000004D1 A0[F70F]                	mov	al, [volume]
  2096 000004D4 3C00                    	cmp	al, 0
  2097 000004D6 762E                    	jna	short q_loop
  2098 000004D8 FEC8                    	dec	al
  2099 000004DA EB0D                    	jmp	short p_2
  2100                                  p_1:
  2101 000004DC 3C2D                    	cmp	al, '-'
  2102 000004DE 7524                    	jne	short p_return
  2103                                  
  2104 000004E0 A0[F70F]                	mov	al, [volume]
  2105 000004E3 3C1F                    	cmp	al, 31
  2106 000004E5 731F                    	jnb	short q_loop
  2107 000004E7 FEC0                    	inc	al
  2108                                  p_2:
  2109 000004E9 A2[F70F]                	mov	[volume], al
  2110 000004EC 88C4                    	mov	ah, al
  2111 000004EE 8B16[D80F]              	mov     dx, [NAMBAR]
  2112                                    	;add    dx, CODEC_MASTER_VOL_REG
  2113 000004F2 83C218                  	add	dx, CODEC_PCM_OUT_REG
  2114 000004F5 EF                      	out     dx, ax
  2115                                  
  2116                                  	; 12/05/2024
  2117 000004F6 E8EE06                  	call    delay1_4ms
  2118 000004F9 E8EB06                          call    delay1_4ms
  2119 000004FC E8E806                          call    delay1_4ms
  2120 000004FF E8E506                          call    delay1_4ms
  2121                                  
  2122 00000502 EB02                    	jmp	short q_loop
  2123                                  
  2124                                  p_return:
  2125 00000504 07                      	pop	es
  2126 00000505 C3                      	retn
  2127                                  q_loop:
  2128                                  tuneLoop:
  2129                                  	; 12/05/2024
  2130                                  	; 18/11/2023 (ich_wav4.asm, Erdogan Tan)
  2131                                  tL1:
  2132 00000506 E85A00                  	call    updateLVI	; /set LVI != CIV/
  2133                                  	;call   check4keyboardstop
  2134                                  	;jc	short _exit_
  2135 00000509 E87300                  	call   getCurrentIndex
  2136 0000050C A801                    	test	al, BIT0
  2137 0000050E 74F6                    	jz	short tL1	; loop if buffer 2 is not playing
  2138                                  
  2139 00000510 8B36[E80F]              	mov     si, [DMA_BUFFER1]
  2140 00000514 E8CD05                  	call    GetSamples_ICH
  2141                                  
  2142 00000517 E81600                  	call	ScopeLoop
  2143                                  tL2:
  2144 0000051A E84600                  	call    updateLVI
  2145                                  	;call   check4keyboardstop
  2146                                  	;jc	short _exit_
  2147 0000051D E85F00                  	call   getCurrentIndex
  2148 00000520 A801                    	test	al, BIT0
  2149 00000522 75F6                    	jnz	short tL2	; loop if buffer 1 is not playing
  2150                                  
  2151 00000524 8B36[EA0F]              	mov     si, [DMA_BUFFER2]
  2152 00000528 E8B905                  	call    GetSamples_ICH
  2153                                  
  2154 0000052B E80200                  	call	ScopeLoop
  2155 0000052E EB93                    	jmp	short p_loop
  2156                                  
  2157                                  ScopeLoop:
  2158                                  	;mov    si, bp			; get current samples
  2159 00000530 BE[02C4]                	mov	si, MOD_BUFFER ; 18/02/2017
  2160 00000533 31C9                    	xor     cx, cx			; to be drawed ...
  2161 00000535 31D2                    	xor     dx, dx
  2162                                  DrawLoop:       
  2163 00000537 89D3                    	mov     bx, dx			; (save Index)
  2164 00000539 8BBF[80BF]              	mov     di, [Scope+bx]		; get old SCOPE pixel address
  2165 0000053D 26C60500                	mov     byte [es:di], 0		; erase it!
  2166                                  	;lodsb				; get a sample (8-bit)
  2167                                  	; 14/05/2024
  2168                                  	;lodsw
  2169                                  	; 15/05/2024 ('PLAYMODM.ASM')
  2170 00000541 AC                      	lodsb
  2171 00000542 88C3                    	mov     bl, al			; calc new pixel address...
  2172 00000544 30FF                    	xor     bh, bh
  2173 00000546 D1E3                    	shl     bx, 1
  2174 00000548 8BBF[00C2]              	mov     di, [RowOfs+bx]
  2175 0000054C 01CF                    	add     di, cx
  2176 0000054E 89D3                    	mov     bx, dx			; (restore Index)
  2177 00000550 89BF[80BF]              	mov     [Scope+bx], di		; save new address...
  2178 00000554 26C6050A                	mov     byte [es:di], 10 ; 0Ah	; and DRAW.
  2179 00000558 83C202                  	add     dx, 2			; the next pixel...
  2180 0000055B 41                      	inc     cx
  2181 0000055C 81F94001                	cmp     cx, 320			; 320 pixels drawed?
  2182 00000560 72D5                    	jb      short DrawLoop
  2183 00000562 C3                      	retn
  2184                                  	
  2185                                  ;_exit_:
  2186                                  	;mov	byte [tLoop], 0
  2187                                  	;retn
  2188                                  
  2189                                  	; 12/05/2024
  2190                                  updateLVI:
  2191                                  	; 06/11/2023
  2192 00000563 8B16[DA0F]              	mov	dx, [NABMBAR]
  2193 00000567 83C214                  	add	dx, PO_CIV_REG
  2194                                  	; (Current Index Value and Last Valid Index value)
  2195 0000056A ED                      	in	ax, dx
  2196                                  
  2197 0000056B 38E0                    	cmp	al, ah ; is current index = last index ?
  2198 0000056D 750F                    	jne	short uLVI_exit ; 12/05/2024
  2199                                  
  2200                                  	; 08/11/2023
  2201 0000056F E80D00                  	call	getCurrentIndex
  2202                                  
  2203 00000572 FEC8                    	dec	al
  2204 00000574 241F                    	and	al, 1Fh
  2205                                  
  2206                                  ;input AL = index # to stop on
  2207                                  setLastValidIndex:
  2208                                  	; 08/11/2023
  2209                                  	;push	dx
  2210 00000576 8B16[DA0F]              	mov	dx, [NABMBAR]
  2211 0000057A 83C215                  	add	dx, PO_LVI_REG
  2212 0000057D EE                              out     dx, al
  2213                                  	;pop	dx
  2214                                  uLVI_exit:	; 12/05/2024
  2215 0000057E C3                      	retn
  2216                                  
  2217                                  ; returns AL = current index value
  2218                                  getCurrentIndex:
  2219                                  	;push	dx
  2220 0000057F 8B16[DA0F]              	mov	dx, [NABMBAR]
  2221 00000583 83C214                  	add	dx, PO_CIV_REG
  2222 00000586 EC                      	in	al, dx
  2223                                  	;pop	dx
  2224 00000587 C3                      	retn
  2225                                  
  2226                                  	; 12/05/2024
  2227                                  check4keyboardstop:
  2228                                  	; 08/11/2023
  2229                                  	; 04/11/2023
  2230 00000588 B401                    	mov	ah, 1
  2231 0000058A CD16                    	int	16h
  2232 0000058C 7405                    	jz	short _cksr
  2233 0000058E 30E4                    	xor	ah, ah
  2234 00000590 CD16                    	int	16h
  2235 00000592 F9                      	stc
  2236                                  _cksr:
  2237 00000593 C3                      	retn
  2238                                  
  2239                                  %endif
  2240                                  
  2241                                  ;=============================================================================
  2242                                  ;               MODLOAD.ASM
  2243                                  ;=============================================================================
  2244                                  
  2245                                  ; Amiga Module Loader v0.1b by Carlos Hasan.
  2246                                  ;		July 10th, 1993.
  2247                                  
  2248                                  ; STRUCTURES
  2249                                  
  2250                                  struc ModSample
  2251 00000000 <res 16h>               .msName:	resb 22
  2252 00000016 ????                    .msLength:	resw 1
  2253 00000018 ??                      .msFinetune:	resb 1
  2254 00000019 ??                      .msVolume:	resb 1
  2255 0000001A ????                    .msRepeat:	resw 1
  2256 0000001C ????                    .msRepLen:	resw 1
  2257                                  .size:
  2258                                  endstruc
  2259                                  
  2260                                  struc ModHeader
  2261 00000000 <res 14h>               .mhName:	resb 20
  2262 00000014 <res 3A2h>              .mhSamples:	resb ModSample.size*31
  2263 000003B6 ??                      .mhOrderLen:	resb 1
  2264 000003B7 ??                      .mhReStart:	resb 1
  2265 000003B8 <res 80h>               .mhOrder:	resb 128
  2266 00000438 ????????                .mhSign:	resw 2
  2267                                  .size:	
  2268                                  endstruc
  2269                                  
  2270                                  struc ModInfoRec
  2271 00000000 ??                      .OrderLen:	resb 1
  2272 00000001 ??                      .ReStart:	resb 1
  2273 00000002 <res 80h>               .Order:		resb 128
  2274 00000082 ????????                .Patterns:	resd 1
  2275 00000086 <res 3Eh>               .SampOfs:	resw 31
  2276 000000C4 <res 3Eh>               .SampSeg:	resw 31
  2277 00000102 <res 3Eh>               .SampLen:	resw 31
  2278 00000140 <res 3Eh>               .SampRep:	resw 31
  2279 0000017E <res 3Eh>               .SampRepLen:	resw 31
  2280 000001BC <res 3Eh>               .SampVol:	resw 31
  2281                                  .size:	
  2282                                  endstruc
  2283                                  
  2284                                  ; CODE
  2285                                  
  2286                                  LoadModule:
  2287                                  		;es:di = filename
  2288                                  
  2289                                  		;[sp+4] = es
  2290                                  		;[sp+2] = di
  2291                                  
  2292                                  		FileName equ 4
  2293                                  
  2294 00000594 55                      		push    bp
  2295 00000595 89E5                    		mov     bp, sp
  2296 00000597 60                      		pusha
  2297 00000598 1E                      		push    ds
  2298 00000599 06                      		push    es
  2299                                  
  2300 0000059A C706[FA60]0100          		mov	word [ErrorInfo], 1
  2301                                  
  2302 000005A0 E85101                  		call    ClearModInfo
  2303                                  OpenFile:       
  2304 000005A3 1E                      		push    ds
  2305 000005A4 B8003D                  		mov     ax, 3D00h
  2306 000005A7 C55604                  		lds     dx, [bp+FileName]
  2307 000005AA CD21                    		int     21h
  2308 000005AC 1F                      		pop     ds
  2309 000005AD 0F823C01                		jc      Failed
  2310 000005B1 A3[F860]                		mov     [FileHandle], ax
  2311                                  
  2312                                  ReadHeader:     
  2313 000005B4 B8003F                  		mov     ax, 3F00h
  2314 000005B7 8B1E[F860]              		mov     bx, [FileHandle]
  2315 000005BB B93C04                  		mov     cx, ModHeader.size
  2316                                  		;lea    dx, [Header]
  2317 000005BE BA[FC60]                		mov	dx, Header
  2318 000005C1 CD21                    		int     21h
  2319 000005C3 0F821D01                		jc      CloseFile
  2320                                  CheckMK:        
  2321 000005C7 813E[3465]4D2E          		cmp     word [Header+ModHeader.mhSign], 'M.'
  2322 000005CD 7508                    		jne     short CheckFLT4
  2323 000005CF 813E[3665]4B2E          		cmp     word [Header+ModHeader.mhSign+2], 'K.'
  2324 000005D5 7439                    		je      short IsModFile
  2325                                  CheckFLT4:
  2326 000005D7 813E[3465]464C          		cmp     word [Header+ModHeader.mhSign], 'FL'
  2327 000005DD 7508                    		jne     short Is15Inst
  2328 000005DF 813E[3665]5434          		cmp     word [Header+ModHeader.mhSign+2], 'T4'
  2329 000005E5 7429                    		je      short IsModFile
  2330                                  Is15Inst:
  2331 000005E7 BE[D262]                		mov     si, (Header+ModHeader.mhSamples) + (15*ModSample.size)
  2332 000005EA BF[B264]                		mov     di, Header+ModHeader.mhOrderLen
  2333 000005ED 8CD8                    		mov     ax, ds
  2334 000005EF 8EC0                    		mov     es, ax
  2335 000005F1 FC                      		cld
  2336 000005F2 B98200                  		mov     cx, 130
  2337 000005F5 F3A4                    		rep     movsb
  2338 000005F7 BF[D262]                		mov     di, Header+ModHeader.mhSamples + (15*ModSample.size)
  2339 000005FA 31C0                    		xor     ax, ax
  2340 000005FC B9E001                  		mov     cx, 16*ModSample.size
  2341 000005FF F3AA                    		rep     stosb
  2342                                  SeekPatterns:   
  2343 00000601 B80042                  		mov     ax, 4200h
  2344 00000604 8B1E[F860]              		mov     bx, [FileHandle]
  2345 00000608 B90000                  		mov     cx, 0
  2346 0000060B BA5802                  		mov     dx, 600
  2347 0000060E CD21                    		int     21h
  2348                                  IsModFile:  
  2349 00000610 A0[B264]                		mov     al, [Header+ModHeader.mhOrderLen]
  2350 00000613 A2[3A65]                		mov     [ModInfo.OrderLen], al
  2351                                  
  2352 00000616 A0[B364]                		mov     al, [Header+ModHeader.mhReStart]
  2353 00000619 3A06[B264]              		cmp     al, [Header+ModHeader.mhOrderLen]
  2354 0000061D 7202                    		jb      short SetReStart
  2355 0000061F B07F                    		mov     al, 7Fh
  2356                                  SetReStart:
  2357 00000621 A2[3B65]                		mov     [ModInfo.ReStart], al
  2358                                  
  2359 00000624 B98000                  		mov     cx, 128
  2360 00000627 31C0                    		xor     ax, ax
  2361 00000629 31DB                    		xor     bx, bx
  2362                                  CopyOrder:
  2363 0000062B 8AA7[B464]              		mov     ah, [Header+ModHeader.mhOrder+bx]
  2364 0000062F 88A7[3C65]              		mov     [ModInfo.Order+bx], ah
  2365 00000633 38C4                    		cmp     ah, al
  2366 00000635 7202                    		jb      short NextOrder
  2367 00000637 88E0                    		mov     al, ah
  2368                                  NextOrder:
  2369 00000639 43                      		inc     bx
  2370 0000063A E2EF                    		loop    CopyOrder
  2371                                  AllocPatterns:  
  2372                                  		; Erdogan Tan (13/02/2017)
  2373 0000063C 30E4                    		xor	ah, ah
  2374 0000063E FEC0                    		inc	al
  2375                                  		; al = count of 1024 bytes
  2376 00000640 89C3                    		mov	bx, ax
  2377                                  		; count of paragraphs = al*64
  2378 00000642 C1E006                  		shl	ax, 6 ; *64
  2379 00000645 89C5                    		mov	bp, ax
  2380 00000647 8CCA                    		mov	dx, cs ; current (code) segment
  2381 00000649 81C20010                		add	dx, 1000h ; next 64K (4096*16)
  2382                                  		;
  2383 0000064D C706[BC65]0000          		mov	word [ModInfo.Patterns], 0
  2384 00000653 8916[BE65]              		mov	[ModInfo.Patterns+2], dx
  2385                                  		;
  2386 00000657 01D5                    		add	bp, dx ; next segment for samples
  2387                                  ReadPatterns:   
  2388 00000659 1E                      		push    ds
  2389 0000065A B8003F                  		mov     ax, 3F00h
  2390 0000065D 89D9                    		mov     cx, bx ; count of 1024 bytes
  2391 0000065F C1E10A                  		shl     cx, 10 ; byte count (cx*1024)
  2392 00000662 8B1E[F860]              		mov     bx, [FileHandle]
  2393                                  		;lds    dx, [ModInfo.Patterns]
  2394 00000666 8EDA                    		mov	ds, dx
  2395 00000668 31D2                    		xor	dx, dx
  2396 0000066A CD21                    		int     21h
  2397 0000066C 1F                      		pop     ds
  2398 0000066D 7275                    		jc      CloseFile
  2399                                  
  2400                                  		;lea	si, [Header+ModHeader.mhSamples]
  2401 0000066F BE[1061]                		mov	si, Header+ModHeader.mhSamples
  2402 00000672 31FF                    		xor     di, di
  2403                                  CopySamples:
  2404 00000674 8B4416                  		mov     ax, [si+ModSample.msLength]
  2405 00000677 86C4                    		xchg    al, ah
  2406 00000679 D1E0                    		shl     ax, 1
  2407 0000067B 8985[3C66]              		mov     [ModInfo.SampLen+di], ax
  2408 0000067F 8A4419                  		mov     al, [si+ModSample.msVolume]
  2409 00000682 30E4                    		xor     ah, ah
  2410 00000684 8985[F666]              		mov     [ModInfo.SampVol+di], ax
  2411 00000688 8B441A                  		mov     ax, [si+ModSample.msRepeat]
  2412 0000068B 86C4                    		xchg    al, ah
  2413 0000068D D1E0                    		shl     ax, 1
  2414 0000068F 8985[7A66]              		mov     [ModInfo.SampRep+di], ax
  2415 00000693 8B441C                  		mov     ax, [si+ModSample.msRepLen]
  2416 00000696 86C4                    		xchg    al, ah
  2417 00000698 D1E0                    		shl     ax, 1
  2418 0000069A 8985[B866]              		mov     [ModInfo.SampRepLen+di], ax
  2419 0000069E 83C61E                  		add     si, ModSample.size
  2420 000006A1 83C702                  		add     di, 2
  2421 000006A4 83FF3E                  		cmp     di, 2*31
  2422 000006A7 72CB                    		jb      short CopySamples
  2423                                  
  2424 000006A9 31F6                    		xor     si, si
  2425                                  AllocSamples:
  2426                                  		; Erdogan Tan (13/02/2017)
  2427                                  		;mov	bx, [ModInfo.SampLen+si]
  2428 000006AB 8B8C[3C66]              		mov	cx, [ModInfo.SampLen+si]
  2429 000006AF 89CB                    		mov	bx, cx
  2430 000006B1 C1EB04                  		shr     bx, 4 ; byte count / 16
  2431 000006B4 7420                    		jz      short NextSample
  2432 000006B6 43                      		inc	bx ; number of paragraphs
  2433 000006B7 C784[C065]0000          		mov	word [ModInfo.SampOfs+si], 0
  2434 000006BD 89AC[FE65]              		mov     [ModInfo.SampSeg+si], bp
  2435 000006C1 89EA                    		mov	dx, bp
  2436 000006C3 01DD                    		add	bp, bx ; next segment for sample 
  2437                                  ReadSample:
  2438 000006C5 1E                      		push    ds
  2439 000006C6 B8003F                  		mov     ax, 3F00h
  2440 000006C9 8B1E[F860]              		mov     bx, [FileHandle]
  2441                                  		;mov    cx, [ModInfo.SampLen+si]
  2442                                  		;mov    dx, [ModInfo.SampOfs+si]
  2443                                  		;mov    ds, [ModInfo.SampSeg+si]
  2444 000006CD 8EDA                    		mov	ds, dx
  2445 000006CF 31D2                    		xor	dx, dx
  2446 000006D1 CD21                    		int     21h
  2447 000006D3 1F                      		pop     ds
  2448 000006D4 720E                    		jc      short CloseFile
  2449                                  NextSample:
  2450 000006D6 83C602                  		add     si, 2
  2451 000006D9 83FE3E                  		cmp     si, 2*31
  2452 000006DC 72CD                    		jb      short AllocSamples
  2453                                  
  2454 000006DE C706[FA60]0000          		mov     word [ErrorInfo], 0
  2455                                  CloseFile:      
  2456 000006E4 B8003E                  		mov     ax, 3E00h
  2457 000006E7 8B1E[F860]              		mov     bx, [FileHandle]
  2458 000006EB CD21                    		int     21h
  2459                                  Failed:         
  2460 000006ED 07                      		pop     es
  2461 000006EE 1F                      		pop     ds
  2462 000006EF 61                      		popa
  2463 000006F0 5D                      		pop     bp
  2464 000006F1 C20400                  		ret	4
  2465                                  
  2466                                  FreeModule:
  2467                                  		; Erdogan Tan (13/02/2017)
  2468                                  		; nothing to do here for memory de-allocation
  2469                                  ClearModInfo:
  2470 000006F4 60                      		pusha
  2471 000006F5 06                      		push    es
  2472 000006F6 8CD8                    		mov     ax, ds
  2473 000006F8 8EC0                    		mov     es, ax
  2474                                  		;lea    di, [ModInfo]
  2475 000006FA BF[3A65]                		mov	di, ModInfo
  2476 000006FD B9FA01                  		mov     cx, ModInfoRec.size
  2477 00000700 FC                      		cld
  2478 00000701 31C0                    		xor     ax, ax
  2479 00000703 F3AA                    		rep     stosb
  2480 00000705 07                      		pop     es
  2481 00000706 61                      		popa
  2482 00000707 C3                      		retn
  2483                                  
  2484                                  ;=============================================================================
  2485                                  ;               MODPLAY.ASM
  2486                                  ;=============================================================================
  2487                                  
  2488                                  ; Amiga Module Player v0.3b by Carlos Hasan.
  2489                                  ;		July 23th, 1993.
  2490                                  
  2491                                  ; EQUATES
  2492                                  
  2493                                  NumTracks       equ 4
  2494                                  DefTempo        equ 6
  2495                                  DefBpm          equ 125
  2496                                  MidCRate        equ 8448
  2497                                  MixBufSize      equ 4096
  2498                                  
  2499                                  ; STRUCTURES
  2500                                  
  2501                                  struc TrackInfo
  2502 00000000 ????????                .Samples:	resd 1
  2503 00000004 ????                    .Position:	resw 1
  2504 00000006 ????                    .Len:		resw 1
  2505 00000008 ????                    .Repeat:	resw 1
  2506 0000000A ????                    .RepLen:	resw 1
  2507 0000000C ??                      .Volume: 	resb 1
  2508 0000000D ??                      .Error:		resb 1
  2509 0000000E ????                    .Period:	resw 1
  2510 00000010 ????                    .Pitch:		resw 1
  2511 00000012 ????                    .Effect:	resw 1
  2512 00000014 ????                    .PortTo:	resw 1
  2513 00000016 ??                      .PortParm:	resb 1
  2514 00000017 ??                      .VibPos:	resb 1
  2515 00000018 ??                      .VibParm:	resb 1
  2516 00000019 ??                      .OldSampOfs:	resb 1
  2517 0000001A ????????????            .Arp:		resw 3
  2518 00000020 ????                    .ArpIndex:	resw 1
  2519                                  .size:
  2520                                  endstruc
  2521                                  
  2522                                  ; CODE
  2523                                  
  2524                                  ;--------------------------------------------------------------------------
  2525                                  ; BeatTrack:  Process the next beat in one track.
  2526                                  ;  In:
  2527                                  ;    ds:di -  Track info Address.
  2528                                  ;--------------------------------------------------------------------------
  2529                                  
  2530                                  BeatTrack:
  2531 00000708 8B5512                  		mov     dx, [di+TrackInfo.Effect]
  2532 0000070B 85D2                    		test    dx, dx
  2533 0000070D 7430                    		je      short None
  2534 0000070F 80FE00                  		cmp     dh, 00h
  2535 00000712 742C                    		je      short Arpeggio
  2536 00000714 80FE01                  		cmp     dh, 01h
  2537 00000717 743E                    		je      short PortUp
  2538 00000719 80FE02                  		cmp     dh, 02h
  2539 0000071C 7455                    		je      short PortDown
  2540 0000071E 80FE03                  		cmp     dh, 03h
  2541 00000721 746D                    		je      short TonePort
  2542 00000723 80FE04                  		cmp     dh, 04h
  2543 00000726 0F849100                		je      Vibrato
  2544 0000072A 80FE05                  		cmp     dh, 05h
  2545 0000072D 0F84D600                		je      PortSlide
  2546 00000731 80FE06                  		cmp     dh, 06h
  2547 00000734 0F84D700                		je      VibSlide
  2548 00000738 80FE0A                  		cmp     dh, 0Ah
  2549 0000073B 0F84D800                		je      VolSlide
  2550                                  None:           
  2551 0000073F C3                      		retn
  2552                                  Arpeggio:
  2553 00000740 8B5D20                  		mov     bx, [di+TrackInfo.ArpIndex]
  2554 00000743 8B411A                  		mov     ax, [di+TrackInfo.Arp+bx]
  2555 00000746 894510                  		mov     [di+TrackInfo.Pitch], ax
  2556 00000749 83C302                  		add     bx, 2
  2557 0000074C 83FB06                  		cmp     bx, 6
  2558 0000074F 7202                    		jb      short SetArpIndex
  2559 00000751 31DB                    		xor     bx,bx
  2560                                  SetArpIndex:
  2561 00000753 895D20                  		mov     [di+TrackInfo.ArpIndex], bx
  2562 00000756 C3                      		retn
  2563                                  PortUp:
  2564 00000757 30F6                    		xor     dh, dh
  2565 00000759 8B5D0E                  		mov     bx, [di+TrackInfo.Period]
  2566 0000075C 29D3                    		sub     bx, dx
  2567 0000075E 83FB71                  		cmp     bx, 113
  2568 00000761 7D03                    		jge     short NotSmall
  2569 00000763 BB7100                  		mov     bx, 113
  2570                                  NotSmall:
  2571 00000766 895D0E                  		mov     [di+TrackInfo.Period], bx
  2572 00000769 01DB                    		add     bx, bx
  2573 0000076B 8B87[3467]              		mov     ax, [PitchTable+bx]
  2574 0000076F 894510                  		mov     [di+TrackInfo.Pitch], ax
  2575 00000772 C3                      		retn
  2576                                  PortDown:
  2577 00000773 30F6                    		xor     dh, dh
  2578 00000775 8B5D0E                  		mov     bx, [di+TrackInfo.Period]
  2579 00000778 01D3                    		add     bx, dx
  2580 0000077A 81FB5803                		cmp     bx, 856
  2581 0000077E 7E03                    		jle     short NotBig
  2582 00000780 BB5803                  		mov     bx, 856
  2583 00000783 895D0E                  NotBig:         mov     [di+TrackInfo.Period], bx
  2584 00000786 01DB                    		add     bx, bx
  2585 00000788 8B87[3467]              		mov     ax, [PitchTable+bx]
  2586 0000078C 894510                  		mov     [di+TrackInfo.Pitch], ax
  2587 0000078F C3                      		retn
  2588                                  TonePort:
  2589 00000790 30F6                    		xor     dh, dh
  2590 00000792 8B4514                  		mov     ax, [di+TrackInfo.PortTo]
  2591 00000795 8B5D0E                  		mov     bx, [di+TrackInfo.Period]
  2592 00000798 39C3                    		cmp     bx, ax
  2593 0000079A 741E                    		je      short NoPort
  2594 0000079C 7F0A                    		jg      short PortToUp
  2595                                  PortToDown:     
  2596 0000079E 01D3                    		add     bx, dx
  2597 000007A0 39C3                    		cmp     bx, ax
  2598 000007A2 7E0A                    		jle     short SetPort
  2599                                  FixPort:        
  2600 000007A4 89C3                    		mov     bx, ax
  2601 000007A6 EB06                    		jmp     short SetPort
  2602                                  PortToUp:
  2603 000007A8 29D3                    		sub     bx, dx
  2604 000007AA 39C3                    		cmp     bx, ax
  2605 000007AC 7CF6                    		jl      short FixPort
  2606                                  SetPort:        
  2607 000007AE 895D0E                  		mov     [di+TrackInfo.Period], bx
  2608 000007B1 01DB                    		add     bx, bx
  2609 000007B3 8B87[3467]              		mov     ax, [PitchTable+bx]
  2610 000007B7 894510                  		mov     [di+TrackInfo.Pitch], ax
  2611                                  NoPort:         
  2612 000007BA C3                      		retn
  2613                                  Vibrato:
  2614 000007BB 88D6                    		mov     dh, dl
  2615 000007BD 80E20F                  		and     dl, 0Fh
  2616 000007C0 C0EE04                  		shr     dh, 4
  2617 000007C3 C0E602                  		shl     dh, 2
  2618 000007C6 007517                  		add     [di+TrackInfo.VibPos], dh
  2619 000007C9 8A7517                  		mov     dh, [di+TrackInfo.VibPos]
  2620 000007CC 88F3                    		mov     bl, dh
  2621 000007CE C0EB02                  		shr     bl, 2
  2622 000007D1 83E31F                  		and     bx, 1Fh
  2623 000007D4 8A87[5F0E]              		mov     al, [SinTable+bx]
  2624 000007D8 F6E2                    		mul     dl
  2625 000007DA D1C0                    		rol     ax, 1
  2626 000007DC 86C4                    		xchg    al, ah
  2627 000007DE 80E401                  		and     ah, 1
  2628 000007E1 84F6                    		test    dh, dh
  2629 000007E3 7902                    		jns     short VibUp
  2630 000007E5 F7D8                    		neg     ax
  2631                                  VibUp:          
  2632 000007E7 03450E                  		add     ax, [di+TrackInfo.Period]
  2633 000007EA 89C3                    		mov     bx, ax
  2634 000007EC 83FB71                  		cmp     bx, 113
  2635 000007EF 7D03                    		jge     short NoLoVib
  2636 000007F1 BB7100                  		mov     bx, 113
  2637                                  NoLoVib:        
  2638 000007F4 81FB5803                		cmp     bx, 856
  2639 000007F8 7E03                    		jle     short NoHiVib
  2640 000007FA BB5803                  		mov     bx, 856
  2641                                  NoHiVib:        
  2642 000007FD 01DB                    		add     bx, bx
  2643 000007FF 8B87[3467]              		mov     ax, [PitchTable+bx]
  2644 00000803 894510                  		mov     [di+TrackInfo.Pitch], ax
  2645 00000806 C3                      		retn
  2646                                  PortSlide:
  2647 00000807 E80D00                  		call    VolSlide
  2648 0000080A 8A5516                  		mov     dl, [di+TrackInfo.PortParm]
  2649 0000080D EB81                    		jmp     short TonePort
  2650                                  VibSlide:
  2651 0000080F E80500                  		call    VolSlide
  2652 00000812 8A5518                  		mov     dl, [di+TrackInfo.VibParm]
  2653 00000815 EBA4                    		jmp     short Vibrato
  2654                                  VolSlide:
  2655 00000817 88D6                    		mov     dh, dl
  2656 00000819 80E20F                  		and     dl, 0Fh
  2657 0000081C C0EE04                  		shr     dh, 4
  2658 0000081F 8A450C                  		mov     al, [di+TrackInfo.Volume]
  2659 00000822 28D0                    		sub     al, dl
  2660 00000824 7D02                    		jge     short NoLoVol
  2661 00000826 30C0                    		xor     al, al
  2662                                  NoLoVol:        
  2663 00000828 00F0                    		add     al, dh
  2664 0000082A 3C40                    		cmp     al, 64
  2665 0000082C 7602                    		jbe     short NoHiVol
  2666 0000082E B040                    		mov     al, 64
  2667                                  NoHiVol:        
  2668 00000830 88450C                  		mov     [di+TrackInfo.Volume], al
  2669 00000833 C3                      		retn
  2670                                  
  2671                                  ;--------------------------------------------------------------------------
  2672                                  ; GetTrack:   Get the next Note from a pattern.
  2673                                  ;  In:
  2674                                  ;    ds:di -  Track info Address.
  2675                                  ;    es:si -  Pattern Note Address.
  2676                                  ; Out:
  2677                                  ;    es:si -  The Next Pattern Note address.
  2678                                  ;--------------------------------------------------------------------------
  2679                                  
  2680                                  GetTrack:
  2681 00000834 26AD                    		es lodsw
  2682 00000836 86C4                    		xchg    al, ah
  2683 00000838 88E3                    		mov     bl, ah
  2684 0000083A 80E40F                  		and     ah, 0Fh
  2685 0000083D 89C1                    		mov     cx, ax
  2686 0000083F 26AD                    		es lodsw
  2687 00000841 86C4                    		xchg    al, ah
  2688 00000843 88E7                    		mov     bh, ah
  2689 00000845 80E40F                  		and     ah, 0Fh
  2690 00000848 89C2                    		mov     dx, ax
  2691 0000084A 895512                  		mov     [di+TrackInfo.Effect], dx
  2692 0000084D 80E3F0                  		and     bl, 0F0h
  2693 00000850 C0EF04                  		shr     bh, 4
  2694 00000853 08FB                    		or      bl, bh
  2695 00000855 742E                    		je      short SetPeriod
  2696                                  SetSample:
  2697 00000857 30FF                    		xor     bh, bh
  2698 00000859 4B                      		dec     bx
  2699 0000085A 01DB                    		add     bx, bx
  2700 0000085C 8B87[F666]              		mov     ax, [ModInfo.SampVol+bx]
  2701 00000860 88450C                  		mov     [di+TrackInfo.Volume], al
  2702 00000863 8B87[C065]              		mov     ax, [ModInfo.SampOfs+bx]
  2703 00000867 8905                    		mov     [di+TrackInfo.Samples], ax
  2704 00000869 8B87[FE65]              		mov     ax, [ModInfo.SampSeg+bx]
  2705 0000086D 894502                  		mov     [di+TrackInfo.Samples+2], ax
  2706 00000870 8B87[3C66]              		mov     ax, [ModInfo.SampLen+bx]
  2707 00000874 894506                  		mov     [di+TrackInfo.Len], ax
  2708 00000877 8B87[7A66]              		mov     ax, [ModInfo.SampRep+bx]
  2709 0000087B 894508                  		mov     [di+TrackInfo.Repeat], ax
  2710 0000087E 8B87[B866]              		mov     ax, [ModInfo.SampRepLen+bx]
  2711 00000882 89450A                  		mov     [di+TrackInfo.RepLen], ax
  2712                                  SetPeriod:      
  2713 00000885 85C9                    		test    cx, cx
  2714 00000887 741B                    		je      short SetEffect
  2715                                  
  2716 00000889 894D14                  		mov     [di+TrackInfo.PortTo], cx
  2717 0000088C 80FE03                  		cmp     dh, 03h
  2718 0000088F 7413                    		je      short SetEffect
  2719                                  
  2720 00000891 894D0E                  		mov     [di+TrackInfo.Period], cx
  2721 00000894 89CB                    		mov     bx, cx
  2722 00000896 01DB                    		add     bx, bx
  2723 00000898 8B87[3467]              		mov     ax, [PitchTable+bx]
  2724 0000089C 894510                  		mov     [di+TrackInfo.Pitch], ax
  2725 0000089F C745040000              		mov     word [di+TrackInfo.Position], 0
  2726                                  SetEffect:
  2727 000008A4 85D2                    		test    dx, dx
  2728 000008A6 742A                    		je      short InitNone
  2729 000008A8 80FE00                  		cmp     dh, 00h
  2730 000008AB 0F84C400                		je      InitArpeggio
  2731 000008AF 80FE03                  		cmp     dh, 03h
  2732 000008B2 741F                    		je      short InitTonePort
  2733 000008B4 80FE04                  		cmp     dh, 04h
  2734 000008B7 7428                    		je      short InitVibrato
  2735 000008B9 80FE09                  		cmp     dh, 09h
  2736 000008BC 744A                    		je      short SampleOfs
  2737 000008BE 80FE0B                  		cmp     dh, 0Bh
  2738 000008C1 7457                    		je      short PosJump
  2739 000008C3 80FE0C                  		cmp     dh, 0Ch
  2740 000008C6 745C                    		je      short SetVolume
  2741 000008C8 80FE0D                  		cmp     dh, 0Dh
  2742 000008CB 7462                    		je      short Break
  2743 000008CD 80FE0F                  		cmp     dh, 0Fh
  2744 000008D0 7478                    		je      short SetSpeed
  2745                                  InitNone:
  2746 000008D2 C3                      		retn
  2747                                  InitTonePort:
  2748 000008D3 84D2                    		test    dl, dl
  2749 000008D5 7503                    		jne     short SetPortParm
  2750 000008D7 8A5516                  		mov     dl, [di+TrackInfo.PortParm]
  2751                                  SetPortParm:    
  2752 000008DA 885516                  		mov     [di+TrackInfo.PortParm], dl
  2753 000008DD 895512                  		mov     [di+TrackInfo.Effect], dx
  2754 000008E0 C3                      		retn
  2755                                  InitVibrato:
  2756 000008E1 8A4518                  		mov     al, [di+TrackInfo.VibParm]
  2757 000008E4 88C4                    		mov     ah, al
  2758 000008E6 240F                    		and     al, 0Fh
  2759 000008E8 80E4F0                  		and     ah, 0F0h
  2760 000008EB F6C20F                  		test    dl, 0Fh
  2761 000008EE 7502                    		jne     short OkDepth
  2762 000008F0 08C2                    		or      dl, al
  2763                                  OkDepth:        
  2764 000008F2 F6C2F0                  		test    dl, 0F0h
  2765 000008F5 7502                    		jne     short OkRate
  2766 000008F7 08E2                    		or      dl, ah
  2767                                  OkRate:         
  2768 000008F9 885518                  		mov     [di+TrackInfo.VibParm], dl
  2769 000008FC 895512                  		mov     [di+TrackInfo.Effect], dx
  2770 000008FF 85C9                    		test    cx, cx
  2771 00000901 7404                    		je      short OkPos
  2772 00000903 C6451700                		mov     byte [di+TrackInfo.VibPos], 0
  2773                                  OkPos:          
  2774 00000907 C3                      		retn
  2775                                  SampleOfs:      
  2776 00000908 84D2                    		test    dl, dl
  2777 0000090A 7503                    		jne     short SetSampleOfs
  2778 0000090C 8A5519                  		mov     dl, [di+TrackInfo.OldSampOfs]
  2779                                  SetSampleOfs:
  2780 0000090F 885519                  		mov     [di+TrackInfo.OldSampOfs], dl
  2781 00000912 88D6                    		mov     dh, dl
  2782 00000914 30D2                    		xor     dl, dl
  2783 00000916 895504                  		mov     [di+TrackInfo.Position], dx
  2784 00000919 C3                      		retn
  2785                                  PosJump:
  2786 0000091A 8816[E6BE]              		mov     [OrderPos], dl
  2787 0000091E C606[EABE]40            		mov     byte [Row], 64
  2788 00000923 C3                      		retn
  2789                                  SetVolume:
  2790 00000924 80FA40                  		cmp     dl, 64
  2791 00000927 7602                    		jbe     short OkVol
  2792 00000929 B240                    		mov     dl, 64
  2793                                  OkVol:
  2794 0000092B 88550C                  		mov     [di+TrackInfo.Volume], dl
  2795 0000092E C3                      		retn
  2796                                  Break:
  2797 0000092F 88D6                    		mov     dh, dl
  2798 00000931 80E20F                  		and     dl, 0Fh
  2799 00000934 C0EE04                  		shr     dh, 4
  2800 00000937 00F6                    		add     dh, dh
  2801 00000939 00F2                    		add     dl, dh
  2802 0000093B C0E602                  		shl     dh, 2
  2803 0000093E 00F2                    		add     dl, dh
  2804 00000940 8816[EBBE]              		mov     [BreakRow], dl
  2805 00000944 C606[EABE]40            		mov     byte [Row], 64
  2806 00000949 C3                      		retn
  2807                                  SetSpeed:
  2808 0000094A 84D2                    		test    dl,dl
  2809 0000094C 7424                    		je      Skip
  2810 0000094E 80FA1F                  		cmp     dl,31
  2811 00000951 7709                    		ja      short SetBpm
  2812                                  SetTempo:       
  2813 00000953 8816[E7BE]              		mov     [Tempo], dl
  2814 00000957 8816[E8BE]              		mov     [TempoWait], dl
  2815 0000095B C3                      		retn
  2816                                  SetBpm:
  2817 0000095C 8816[E9BE]              		mov     [Bpm], dl
  2818 00000960 B067                    		mov     al, 103
  2819 00000962 F6E2                    		mul     dl
  2820 00000964 88E3                    		mov     bl, ah
  2821 00000966 30FF                    		xor     bh, bh
  2822 00000968 A1[3865]                		mov     ax, [MixSpeed]
  2823 0000096B 31D2                    		xor     dx, dx
  2824 0000096D F7F3                    		div     bx
  2825 0000096F A3[ECBE]                		mov     [BpmSamples], ax
  2826                                  Skip:           
  2827 00000972 C3                      		retn
  2828                                  InitArpeggio:
  2829 00000973 88D6                    		mov     dh, dl
  2830 00000975 80E20F                  		and     dl, 0Fh
  2831 00000978 C0EE04                  		shr     dh, 4
  2832 0000097B B92400                  		mov     cx, 36
  2833 0000097E 31DB                    		xor     bx, bx
  2834 00000980 8B450E                  		mov     ax, [di+TrackInfo.Period]
  2835                                  gt_ScanPeriod:
  2836 00000983 3B87[7F0E]              		cmp     ax, [PeriodTable+bx]
  2837 00000987 7305                    		jae     short SetArp
  2838 00000989 83C302                  		add     bx, 2
  2839 0000098C E2F5                    		loop    gt_ScanPeriod
  2840                                  SetArp:         
  2841 0000098E 01D2                    		add     dx, dx
  2842 00000990 00DE                    		add     dh, bl
  2843 00000992 00DA                    		add     dl, bl
  2844 00000994 8B9F[7F0E]              		mov     bx, [PeriodTable+bx]
  2845 00000998 01DB                    		add     bx, bx
  2846 0000099A 8B87[3467]              		mov     ax, [PitchTable+bx]
  2847 0000099E 89451A                  		mov     [di+TrackInfo.Arp], ax
  2848 000009A1 88F3                    		mov     bl, dh
  2849 000009A3 30FF                    		xor     bh, bh
  2850 000009A5 8B9F[7F0E]              		mov     bx, [PeriodTable+bx]
  2851 000009A9 01DB                    		add     bx, bx
  2852 000009AB 8B87[3467]              		mov     ax, [PitchTable+bx]
  2853 000009AF 89451C                  		mov     [di+TrackInfo.Arp+2], ax
  2854 000009B2 88D3                    		mov     bl, dl
  2855 000009B4 30FF                    		xor     bh, bh
  2856 000009B6 8B9F[7F0E]              		mov     bx, [PeriodTable+bx]
  2857 000009BA 01DB                    		add     bx, bx
  2858 000009BC 8B87[3467]              		mov     ax, [PitchTable+bx]
  2859 000009C0 89451E                  		mov     [di+TrackInfo.Arp+4], ax
  2860 000009C3 C745200000              		mov     word [di+TrackInfo.ArpIndex], 0
  2861 000009C8 C3                      		retn
  2862                                  
  2863                                  ;--------------------------------------------------------------------------
  2864                                  ; UpdateTracks:  Main code to process the next tick to be played.
  2865                                  ;--------------------------------------------------------------------------
  2866                                  
  2867                                  UpdateTracks:
  2868 000009C9 FE0E[E8BE]              		dec     byte [TempoWait]
  2869 000009CD 740F                    		jz      short GetTracks
  2870                                  
  2871 000009CF B90400                  		mov	cx, NumTracks
  2872 000009D2 BF[F8BE]                		mov	di, Tracks
  2873                                  BeatTracks:
  2874 000009D5 E830FD                  		call	BeatTrack
  2875 000009D8 83C722                  		add	di, TrackInfo.size
  2876 000009DB E2F8                    		loop	BeatTracks
  2877 000009DD C3                      		retn
  2878                                  GetTracks:
  2879 000009DE A0[E7BE]                		mov     al, [Tempo]
  2880 000009E1 A2[E8BE]                		mov     [TempoWait], al
  2881                                  
  2882 000009E4 C436[F4BE]              		les     si, [Note]
  2883 000009E8 803E[EABE]40            		cmp     byte [Row], 64
  2884 000009ED 7246                    		jb      short NoPattWrap
  2885                                  
  2886 000009EF C436[BC65]              		les     si, [ModInfo.Patterns]
  2887 000009F3 8A1E[E6BE]              		mov     bl, [OrderPos]
  2888 000009F7 3A1E[3A65]              		cmp     bl, [ModInfo.OrderLen]
  2889 000009FB 720E                    		jb      short NoOrderWrap
  2890 000009FD 8A1E[3B65]              		mov     bl, [ModInfo.ReStart]
  2891 00000A01 881E[E6BE]              		mov     [OrderPos], bl
  2892 00000A05 3A1E[3A65]              		cmp     bl, [ModInfo.OrderLen]
  2893 00000A09 7343                    		jae     short NoUpdate
  2894                                  NoOrderWrap:    
  2895 00000A0B 30FF                    		xor     bh, bh
  2896 00000A0D 8A9F[3C65]              		mov     bl, [ModInfo.Order+bx]
  2897 00000A11 C1E30A                  		shl     bx, 10
  2898 00000A14 01DE                    		add     si, bx
  2899 00000A16 8A1E[EBBE]              		mov     bl, [BreakRow]
  2900 00000A1A 881E[EABE]              		mov     [Row], bl
  2901 00000A1E 30FF                    		xor     bh, bh
  2902 00000A20 883E[EBBE]              		mov     [BreakRow], bh
  2903 00000A24 C1E304                  		shl     bx, 4
  2904 00000A27 01DE                    		add     si, bx
  2905 00000A29 8936[F4BE]              		mov     [Note], si
  2906 00000A2D 8C06[F6BE]              		mov     [Note+2], es
  2907 00000A31 FE06[E6BE]              		inc     byte [OrderPos]
  2908                                  NoPattWrap:     
  2909 00000A35 FE06[EABE]              		inc     byte [Row]
  2910                                  
  2911 00000A39 FC                      		cld
  2912 00000A3A B90400                  		mov	cx, NumTracks
  2913 00000A3D BF[F8BE]                		mov	di, Tracks
  2914                                  GetTracks_next:
  2915 00000A40 51                      		push	cx		
  2916 00000A41 E8F0FD                  		call	GetTrack
  2917 00000A44 59                      		pop	cx
  2918 00000A45 83C722                  		add	di, TrackInfo.size
  2919 00000A48 E2F6                    		loop	GetTracks_next
  2920                                  
  2921 00000A4A 8936[F4BE]              		mov     [Note], si
  2922                                  NoUpdate:
  2923 00000A4E C3                      		retn
  2924                                  
  2925                                  ;--------------------------------------------------------------------------
  2926                                  ; MixTrack:  Mixes one track into a CLEAN buffer.
  2927                                  ;  In:
  2928                                  ;   ds:si -  Track Info Address.
  2929                                  ;   ds:di -  Buffer Address.
  2930                                  ;    cx   -  Buffer Size.
  2931                                  ;--------------------------------------------------------------------------
  2932                                  
  2933                                  MixTrack:
  2934 00000A4F 837C0A02                		cmp     word [si+TrackInfo.RepLen], 2
  2935 00000A53 7742                    		ja      short MixLooped
  2936                                  MixNonLooped:   
  2937 00000A55 C414                    		les     dx, [si+TrackInfo.Samples]
  2938 00000A57 8B5C04                  		mov     bx, [si+TrackInfo.Position]
  2939 00000A5A 8B6C06                  		mov     bp, [si+TrackInfo.Len]
  2940 00000A5D 52                      		push    dx
  2941 00000A5E 56                      		push    si
  2942 00000A5F 01D3                    		add     bx, dx
  2943 00000A61 01D5                    		add     bp, dx
  2944 00000A63 8B5410                  		mov     dx, [si+TrackInfo.Pitch]
  2945 00000A66 8A440C                  		mov     al, [si+TrackInfo.Volume]
  2946 00000A69 8A640D                  		mov     ah, [si+TrackInfo.Error]
  2947 00000A6C 89DE                    		mov     si, bx
  2948 00000A6E 88C7                    		mov     bh, al
  2949 00000A70 88D0                    		mov     al, dl
  2950 00000A72 88F2                    		mov     dl, dh
  2951 00000A74 30F6                    		xor     dh, dh
  2952                                  nlMixSamp:      
  2953 00000A76 39EE                    		cmp     si, bp
  2954 00000A78 7310                    		jae     short nlMixBye
  2955 00000A7A 268A1C                  		mov     bl, [es:si]
  2956 00000A7D 8A9F[E66D]              		mov     bl, [VolTable+bx]
  2957 00000A81 001D                    		add     [di], bl
  2958 00000A83 47                      		inc     di
  2959 00000A84 00C4                    		add     ah, al
  2960 00000A86 11D6                    		adc     si, dx
  2961 00000A88 E2EC                    		loop    nlMixSamp
  2962                                  nlMixBye:       
  2963 00000A8A 89F3                    		mov     bx, si
  2964 00000A8C 5E                      		pop     si
  2965 00000A8D 5A                      		pop     dx
  2966 00000A8E 29D3                    		sub     bx, dx
  2967 00000A90 895C04                  		mov     [si+TrackInfo.Position], bx
  2968 00000A93 88640D                  		mov     [si+TrackInfo.Error], ah
  2969 00000A96 C3                      		retn
  2970                                  MixLooped:
  2971 00000A97 C414                    		les     dx, [si+TrackInfo.Samples]
  2972 00000A99 8B5C04                  		mov     bx, [si+TrackInfo.Position]
  2973 00000A9C 8B6C0A                  		mov     bp, [si+TrackInfo.RepLen]
  2974 00000A9F 892E[F2BE]              		mov     [BufRep], bp
  2975 00000AA3 036C08                  		add     bp, [si+TrackInfo.Repeat]
  2976 00000AA6 52                      		push    dx
  2977 00000AA7 56                      		push    si
  2978 00000AA8 01D3                    		add     bx, dx
  2979 00000AAA 01D5                    		add     bp, dx
  2980 00000AAC 8B5410                  		mov     dx, [si+TrackInfo.Pitch]
  2981 00000AAF 8A440C                  		mov     al, [si+TrackInfo.Volume]
  2982 00000AB2 8A640D                  		mov     ah, [si+TrackInfo.Error]
  2983 00000AB5 89DE                    		mov     si, bx
  2984 00000AB7 88C7                    		mov     bh, al
  2985 00000AB9 88D0                    		mov     al, dl
  2986 00000ABB 88F2                    		mov     dl, dh
  2987 00000ABD 30F6                    		xor     dh, dh
  2988                                  lpMixSamp:      
  2989 00000ABF 39EE                    		cmp     si, bp
  2990 00000AC1 7204                    		jb      short lpMixNow
  2991 00000AC3 2B36[F2BE]              		sub     si, [BufRep]
  2992                                  lpMixNow:       
  2993 00000AC7 268A1C                  		mov     bl, [es:si]
  2994 00000ACA 8A9F[E66D]              		mov     bl, [VolTable+bx]
  2995 00000ACE 001D                    		add     [di], bl
  2996 00000AD0 47                      		inc     di
  2997 00000AD1 00C4                    		add     ah, al
  2998 00000AD3 11D6                    		adc     si, dx
  2999 00000AD5 E2E8                    		loop    lpMixSamp
  3000                                  lpMixBye:       
  3001 00000AD7 89F3                    		mov     bx, si
  3002 00000AD9 5E                      		pop     si
  3003 00000ADA 5A                      		pop     dx
  3004 00000ADB 29D3                    		sub     bx, dx
  3005 00000ADD 895C04                  		mov     [si+TrackInfo.Position], bx
  3006 00000AE0 88640D                  		mov     [si+TrackInfo.Error], ah
  3007 00000AE3 C3                      		retn
  3008                                  
  3009                                  GetSamples_ICH:
  3010                                  		; 11/05/2024
  3011                                  		; 18/02/2017
  3012                                  		; 8 bit mono samples 
  3013                                  		; must be converted to 16 bit, stereo samples (for ICH) !
  3014                                  		; (ICH AC97 Modification by Erdogan Tan)
  3015 00000AE4 8936[00C4]              		mov	[_si_], si ; DMA Buff Addr, [DMA_BUFFER1] or [DMA_BUFFER2]
  3016                                  		; 11/05/2024
  3017                                  		;mov	si, MOD_BUFFER
  3018                                  		;shr	cx, 2 ; mod buffer size = dma (half) buffer size / 4 (*)
  3019                                  
  3020                                  ;--------------------------------------------------------------------------
  3021                                  ; GetSamples:  Returns the next chunk of samples to be played.
  3022                                  ;  In:
  3023                                  ;    Buffer  - Buffer Address.
  3024                                  ;    Count   - Buffer Size.
  3025                                  ;--------------------------------------------------------------------------
  3026                                  
  3027                                  GetSamples:
  3028                                  		;ds:si = buffer address
  3029                                  		;cx = count
  3030                                  
  3031                                  		; 11/05/2024
  3032                                  		;
  3033                                  		;;[sp+6] = ds
  3034                                  		;;[sp+4] = si
  3035                                  		;;[sp+2] = count
  3036                                  		;
  3037                                  		;Count	equ 4
  3038                                  		;Buffer	equ 6 
  3039                                  		;
  3040                                  		;push	bp
  3041                                  		;mov	bp, sp
  3042                                  		;
  3043                                  		;push    es
  3044                                  		;;;push  ds
  3045                                  		;;;pusha
  3046                                  		;
  3047                                  		;cld
  3048                                  		;
  3049                                  		;les	di, [bp+Buffer]
  3050                                  		;mov    bx, [bp+Count]
  3051                                  
  3052                                  		; 11/05/2024
  3053                                  		; ds = cs
  3054 00000AE8 06                      		push	es ; +
  3055                                  
  3056 00000AE9 1E                      		push	ds
  3057 00000AEA 07                      		pop	es
  3058                                  
  3059                                  		; 11/05/2024
  3060 00000AEB BF[02C4]                		mov	di, MOD_BUFFER
  3061 00000AEE BB000A                  		mov	bx, (BUFFERSIZE/4) ; (*) ; 2048
  3062                                  NextChunk:
  3063 00000AF1 833E[F0BE]00            		cmp     word [BufLen], 0
  3064 00000AF6 7534                    		jne     short CopyChunk
  3065                                  
  3066                                  		; 11/05/2024
  3067 00000AF8 06                      		push	es
  3068 00000AF9 53                      		push	bx
  3069 00000AFA 57                      		push	di
  3070                                  MixChunk:       
  3071                                  		;lea    di, [MixBuffer]
  3072 00000AFB BF[E6AE]                		mov	di, MixBuffer
  3073 00000AFE 8B0E[ECBE]              		mov     cx, [BpmSamples]
  3074 00000B02 893E[EEBE]              		mov     [BufPtr], di
  3075 00000B06 890E[F0BE]              		mov     [BufLen], cx
  3076                                  
  3077                                  		; 12/05/2024
  3078                                  		; es = ds
  3079                                  		;mov    ax, ds
  3080                                  		;mov    es, ax
  3081                                  
  3082 00000B0A B080                    		mov    al, 80h
  3083 00000B0C F3AA                    		rep    stosb
  3084                                  
  3085 00000B0E B90400                  		mov	cx, NumTracks
  3086 00000B11 BE[D6BE]                		mov	si, Tracks - TrackInfo.size
  3087                                  GetSamples_next:
  3088 00000B14 51                      		push	cx
  3089 00000B15 83C622                  		add	si, TrackInfo.size
  3090 00000B18 8B0E[F0BE]              		mov	cx, [BufLen]
  3091 00000B1C 8B3E[EEBE]              		mov	di, [BufPtr]
  3092 00000B20 E82CFF                  		call	MixTrack
  3093 00000B23 59                      		pop	cx
  3094 00000B24 E2EE                    		loop	GetSamples_next
  3095                                  
  3096 00000B26 E8A0FE                  		call    UpdateTracks
  3097                                  
  3098 00000B29 5F                      		pop	di
  3099 00000B2A 5B                      		pop	bx
  3100 00000B2B 07                      		pop	es ; es = ds ; 12/05/2024
  3101                                  CopyChunk:      
  3102 00000B2C 8B0E[F0BE]              		mov     cx, [BufLen]
  3103 00000B30 39D9                    		cmp     cx, bx
  3104 00000B32 7602                    		jbe     short MoveChunk
  3105 00000B34 89D9                    		mov     cx, bx
  3106                                  MoveChunk:
  3107 00000B36 8B36[EEBE]              		mov     si, [BufPtr]
  3108 00000B3A 010E[EEBE]              		add     [BufPtr], cx
  3109 00000B3E 290E[F0BE]              		sub     [BufLen], cx
  3110 00000B42 29CB                    		sub     bx, cx
  3111 00000B44 F3A4                    		rep     movsb
  3112 00000B46 85DB                    		test    bx, bx
  3113 00000B48 75A7                    		jnz     short NextChunk
  3114                                  
  3115                                  		;;popa
  3116                                  		;;pop	ds
  3117                                  		;pop	es
  3118                                  		;pop	bp
  3119                                  		;ret	6
  3120                                  
  3121                                  ; GetSamples_ICH_convert_samples:
  3122                                  		; 11/05/2024
  3123                                  		; es = ds = cs
  3124                                  		; 18/02/2017
  3125                                  		;mov	di, ds
  3126                                  		;mov	es, di
  3127 00000B4A 8B3E[00C4]              		mov	di, [_si_] ; DMA Buffer Address (16 bit, stereo)
  3128 00000B4E BE[01C4]                		mov	si, MOD_BUFFER - 1 ; buffer for 8 bit mono samples
  3129 00000B51 B9000A                  		mov	cx, (BUFFERSIZE/4) ; (*) ; 2048 ; 11/04/2024
  3130 00000B54 30C0                    		xor	al, al
  3131                                  gscs_loop:		
  3132 00000B56 46                      		inc	si
  3133 00000B57 8A24                    		mov	ah, [si] ; convert 8 bit sample to 16 bit sample
  3134                                  		; 11/05/2024
  3135 00000B59 80EC80                  		sub	ah, 80h
  3136                                  
  3137 00000B5C AB                      		stosw	; left channel
  3138 00000B5D AB                      		stosw	; right channel
  3139 00000B5E E2F6                    		loop	gscs_loop
  3140                                  
  3141                                  		; 11/05/2024
  3142 00000B60 07                      		pop	es ; +
  3143                                  		;pop	bp
  3144                                  		;ret	6
  3145 00000B61 C3                      		retn
  3146                                  
  3147                                  ;--------------------------------------------------------------------------
  3148                                  ; StartPlaying: Initializes the Sound System.
  3149                                  ;  In:
  3150                                  ;   Module Information Resources.
  3151                                  ;--------------------------------------------------------------------------
  3152                                  
  3153                                  StartPlaying:
  3154 00000B62 60                      		pusha
  3155 00000B63 1E                      		push    ds
  3156 00000B64 06                      		push    es
  3157                                  SetModParms:    
  3158 00000B65 C606[E6BE]00            		mov     byte [OrderPos], 0
  3159 00000B6A C606[E7BE]06            		mov     byte [Tempo], DefTempo
  3160 00000B6F C606[E8BE]06            		mov     byte [TempoWait], DefTempo
  3161 00000B74 C606[E9BE]7D            		mov     byte [Bpm], DefBpm
  3162 00000B79 C606[EABE]40            		mov     byte [Row], 64
  3163 00000B7E C606[EBBE]00            		mov     byte [BreakRow], 0
  3164 00000B83 A1[3865]                		mov     ax, [MixSpeed]
  3165 00000B86 31D2                    		xor     dx, dx
  3166 00000B88 BB3200                  		mov     bx, 24*DefBpm/60
  3167 00000B8B F7F3                    		div     bx
  3168 00000B8D A3[ECBE]                		mov     [BpmSamples], ax
  3169                                  ClearTracks:    
  3170 00000B90 BF[F8BE]                		mov     di, Tracks
  3171 00000B93 8CD8                    		mov     ax, ds
  3172 00000B95 8EC0                    		mov     es, ax
  3173 00000B97 B98800                  		mov     cx, NumTracks*TrackInfo.size
  3174 00000B9A 31C0                    		xor     ax, ax
  3175 00000B9C FC                      		cld
  3176 00000B9D F3AA                    		rep     stosb
  3177                                  
  3178 00000B9F A3[EEBE]                		mov     [BufPtr], ax
  3179 00000BA2 A3[F0BE]                		mov     [BufLen], ax
  3180                                  MakePitch:
  3181 00000BA5 B80021                  		mov     ax, MidCRate
  3182 00000BA8 BBAC01                  		mov     bx, 428
  3183 00000BAB F7E3                    		mul     bx
  3184 00000BAD F736[3865]              		div     word [MixSpeed]
  3185 00000BB1 30F6                    		xor     dh, dh
  3186 00000BB3 88E2                    		mov     dl, ah
  3187 00000BB5 88C4                    		mov     ah, al
  3188 00000BB7 30C0                    		xor     al, al
  3189 00000BB9 B95903                  		mov     cx, 857
  3190 00000BBC 31DB                    		xor     bx, bx
  3191 00000BBE BF[3467]                		mov     di, PitchTable
  3192                                  PitchLoop:      
  3193 00000BC1 50                      		push    ax
  3194 00000BC2 52                      		push    dx
  3195 00000BC3 39DA                    		cmp     dx, bx
  3196 00000BC5 7302                    		jae     short NoDiv
  3197 00000BC7 F7F3                    		div     bx
  3198                                  NoDiv:          
  3199 00000BC9 AB                      		stosw
  3200 00000BCA 5A                      		pop     dx
  3201 00000BCB 58                      		pop     ax
  3202 00000BCC 43                      		inc     bx
  3203 00000BCD E2F2                    		loop    PitchLoop
  3204                                  MakeVolume:     
  3205 00000BCF B90041                  		mov     cx, 16640
  3206 00000BD2 89CB                    		mov     bx, cx
  3207                                  VolLoop:
  3208 00000BD4 4B                      		dec     bx
  3209 00000BD5 88D8                    		mov     al, bl
  3210 00000BD7 F6EF                    		imul    bh
  3211 00000BD9 88A7[E66D]              		mov     [VolTable+bx], ah
  3212 00000BDD E2F5                    		loop    VolLoop
  3213                                  
  3214 00000BDF 07                      		pop     es
  3215 00000BE0 1F                      		pop     ds
  3216 00000BE1 61                      		popa
  3217 00000BE2 C3                      		retn	; 12/05/2024
  3218                                  
  3219                                  ;--------------------------------------------------------------------------
  3220                                  ; StopPlaying: ShutDown the Sound System.
  3221                                  ;--------------------------------------------------------------------------
  3222                                  
  3223                                  StopPlaying:
  3224                                  	; 08/05/2024
  3225                                  	; 04/11/2023
  3226                                  	; finished with song, stop everything
  3227 00000BE3 E8A801                  	call	ac97_stop
  3228                                  
  3229                                  ; 12/05/2024 (tuneloop version)
  3230                                  %if 0
  3231                                  	; 11/11/2023
  3232                                  irq_restore:	
  3233                                  	; restore previous interrupt vector and interrupt_status
  3234                                  	cli
  3235                                  	in	al, 0A1h ; irq 8-15
  3236                                  	mov	al, [IRQ_status+1]
  3237                                  	out	0A1h, al 
  3238                                  	in	al, 021h ; irq 0-7
  3239                                  	mov	al, [IRQ_status]
  3240                                  	out	21h, al 
  3241                                  	; ...
  3242                                  	push	es
  3243                                  	xor	ax, ax
  3244                                  	mov	es, ax
  3245                                  	mov	ax, [IRQ_vector]
  3246                                  	mov	[es:bx], ax
  3247                                  	mov	ax, [IRQ_vector+2]
  3248                                  	mov	[es:bx+2], ax
  3249                                  	pop	es
  3250                                  
  3251                                  	sti
  3252                                  %endif
  3253 00000BE6 C3                      	retn
  3254                                  
  3255                                  ;=============================================================================
  3256                                  ;               PLAYER.ASM
  3257                                  ;=============================================================================
  3258                                  
  3259                                  ; UTILS.ASM
  3260                                  ;----------------------------------------------------------------------------
  3261                                  ;       delay1_4ms - Delay for 1/4 millisecond.
  3262                                  ;		    1mS = 1000us
  3263                                  ;       Entry:
  3264                                  ;         None
  3265                                  ;       Exit:
  3266                                  ;	  None
  3267                                  ;
  3268                                  ;       Modified:
  3269                                  ;         None
  3270                                  ;
  3271                                  PORTB			EQU	061h
  3272                                    REFRESH_STATUS	EQU	010h		; Refresh signal status
  3273                                  
  3274                                  delay1_4ms:
  3275 00000BE7 50                              push    ax 
  3276 00000BE8 51                              push    cx
  3277 00000BE9 B91000                          mov     cx, 16			; close enough.
  3278 00000BEC E461                    	in	al,PORTB
  3279 00000BEE 2410                    	and	al,REFRESH_STATUS
  3280 00000BF0 88C4                    	mov	ah,al			; Start toggle state
  3281 00000BF2 09C9                    	or	cx, cx
  3282 00000BF4 7401                    	jz	short _d4ms1
  3283 00000BF6 41                      	inc	cx			; Throwaway first toggle
  3284                                  _d4ms1:	
  3285 00000BF7 E461                    	in	al,PORTB		; Read system control port
  3286 00000BF9 2410                    	and	al,REFRESH_STATUS	; Refresh toggles 15.085 microseconds
  3287 00000BFB 38C4                    	cmp	ah,al
  3288 00000BFD 74F8                    	je	short _d4ms1		; Wait for state change
  3289                                  
  3290 00000BFF 88C4                    	mov	ah,al			; Update with new state
  3291 00000C01 49                      	dec	cx
  3292 00000C02 75F3                    	jnz	short _d4ms1
  3293                                  
  3294 00000C04 59                              pop     cx
  3295 00000C05 58                              pop     ax
  3296 00000C06 C3                              retn
  3297                                  
  3298                                  print_msg:
  3299                                  	; 13/11/2016 - Erdogan Tan 
  3300                                  	; esi = ASCIIZ text address
  3301                                  	;
  3302 00000C07 BB0700                  	mov	bx, 7h
  3303 00000C0A B40E                    	mov	ah, 0Eh 
  3304                                  pm_next_char:
  3305 00000C0C AC                      	lodsb
  3306 00000C0D 20C0                    	and	al, al
  3307 00000C0F 7404                    	jz	short pm_retn
  3308 00000C11 CD10                    	int	10h
  3309 00000C13 EBF7                    	jmp	short pm_next_char
  3310                                  pm_retn:
  3311 00000C15 C3                      	retn
  3312                                  
  3313                                  dword2str:
  3314                                  	; 13/11/2016 - Erdogan Tan 
  3315                                  	; eax = dword value
  3316                                  	;
  3317 00000C16 E84400                  	call	dwordtohex
  3318 00000C19 668916[C90F]            	mov	[dword_str], edx
  3319 00000C1E 66A3[CD0F]              	mov	[dword_str+4], eax
  3320 00000C22 BE[C90F]                	mov	si, dword_str
  3321 00000C25 C3                      	retn
  3322                                  
  3323                                  	; trdos386.s (unix386.s) - 10/05/2015
  3324                                  	; Convert binary number to hexadecimal string
  3325                                  
  3326                                  bytetohex:
  3327                                  	; INPUT ->
  3328                                  	; 	AL = byte (binary number)
  3329                                  	; OUTPUT ->
  3330                                  	;	AX = hexadecimal string
  3331                                  	;
  3332 00000C26 53                      	push	bx
  3333 00000C27 30FF                    	xor	bh, bh
  3334 00000C29 88C3                    	mov	bl, al
  3335 00000C2B C0EB04                  	shr	bl, 4
  3336 00000C2E 8A9F[2B0F]              	mov	bl, [bx+hex_chars]
  3337 00000C32 86D8                    	xchg	bl, al
  3338 00000C34 80E30F                  	and	bl, 0Fh
  3339 00000C37 8AA7[2B0F]              	mov	ah, [bx+hex_chars]
  3340 00000C3B 5B                      	pop	bx	
  3341 00000C3C C3                      	retn
  3342                                  
  3343                                  wordtohex:
  3344                                  	; INPUT ->
  3345                                  	; 	AX = word (binary number)
  3346                                  	; OUTPUT ->
  3347                                  	;	EAX = hexadecimal string
  3348                                  	;
  3349 00000C3D 53                      	push	bx
  3350 00000C3E 30FF                    	xor	bh, bh
  3351 00000C40 86E0                    	xchg	ah, al
  3352 00000C42 50                      	push	ax
  3353 00000C43 88E3                    	mov	bl, ah
  3354 00000C45 C0EB04                  	shr	bl, 4
  3355 00000C48 8A87[2B0F]              	mov	al, [bx+hex_chars]
  3356 00000C4C 88E3                    	mov	bl, ah
  3357 00000C4E 80E30F                  	and	bl, 0Fh
  3358 00000C51 8AA7[2B0F]              	mov	ah, [bx+hex_chars]
  3359 00000C55 66C1E010                	shl	eax, 16
  3360 00000C59 58                      	pop	ax
  3361 00000C5A 5B                      	pop	bx
  3362 00000C5B EBC9                    	jmp	short bytetohex
  3363                                  
  3364                                  dwordtohex:
  3365                                  	; INPUT ->
  3366                                  	; 	EAX = dword (binary number)
  3367                                  	; OUTPUT ->
  3368                                  	;	EDX:EAX = hexadecimal string
  3369                                  	;
  3370 00000C5D 6650                    	push	eax
  3371 00000C5F 66C1E810                	shr	eax, 16
  3372 00000C63 E8D7FF                  	call	wordtohex
  3373 00000C66 6689C2                  	mov	edx, eax
  3374 00000C69 6658                    	pop	eax
  3375 00000C6B E8CFFF                  	call	wordtohex
  3376 00000C6E C3                      	retn
  3377                                  
  3378                                  	; 13/11/2016 - Erdogan Tan
  3379                                  write_ac97_dev_info:
  3380                                  	; BUS/DEV/FN
  3381                                  	;	00000000BBBBBBBBDDDDDFFF00000000
  3382                                  	; DEV/VENDOR
  3383                                  	;	DDDDDDDDDDDDDDDDVVVVVVVVVVVVVVVV
  3384                                  
  3385 00000C6F 30FF                    	xor	bh, bh
  3386 00000C71 668B36[F20F]            	mov	esi, [dev_vendor]
  3387 00000C76 89F0                    	mov	ax, si
  3388 00000C78 88C3                    	mov	bl, al
  3389 00000C7A 88DA                    	mov	dl, bl
  3390 00000C7C 80E30F                  	and	bl, 0Fh
  3391 00000C7F 8A87[2B0F]              	mov	al, [bx+hex_chars]
  3392 00000C83 A2[6E0F]                	mov	[msgVendorId+3], al
  3393 00000C86 88D3                    	mov	bl, dl
  3394 00000C88 C0EB04                  	shr	bl, 4
  3395 00000C8B 8A87[2B0F]              	mov	al, [bx+hex_chars]
  3396 00000C8F A2[6D0F]                	mov	[msgVendorId+2], al
  3397 00000C92 88E3                    	mov	bl, ah
  3398 00000C94 88DA                    	mov	dl, bl
  3399 00000C96 80E30F                  	and	bl, 0Fh
  3400 00000C99 8A87[2B0F]              	mov	al, [bx+hex_chars]
  3401 00000C9D A2[6C0F]                	mov	[msgVendorId+1], al
  3402 00000CA0 88D3                    	mov	bl, dl
  3403 00000CA2 C0EB04                  	shr	bl, 4
  3404 00000CA5 8A87[2B0F]              	mov	al, [bx+hex_chars]
  3405 00000CA9 A2[6B0F]                	mov	[msgVendorId], al
  3406 00000CAC 66C1EE10                	shr	esi, 16
  3407 00000CB0 89F0                    	mov	ax, si
  3408 00000CB2 88C3                    	mov	bl, al
  3409 00000CB4 88DA                    	mov	dl, bl
  3410 00000CB6 80E30F                  	and	bl, 0Fh
  3411 00000CB9 8A87[2B0F]              	mov	al, [bx+hex_chars]
  3412 00000CBD A2[7F0F]                	mov	[msgDevId+3], al
  3413 00000CC0 88D3                    	mov	bl, dl
  3414 00000CC2 C0EB04                  	shr	bl, 4
  3415 00000CC5 8A87[2B0F]              	mov	al, [bx+hex_chars]
  3416 00000CC9 A2[7E0F]                	mov	[msgDevId+2], al
  3417 00000CCC 88E3                    	mov	bl, ah
  3418 00000CCE 88DA                    	mov	dl, bl
  3419 00000CD0 80E30F                  	and	bl, 0Fh
  3420 00000CD3 8A87[2B0F]              	mov	al, [bx+hex_chars]
  3421 00000CD7 A2[7D0F]                	mov	[msgDevId+1], al
  3422 00000CDA 88D3                    	mov	bl, dl
  3423 00000CDC C0EB04                  	shr	bl, 4
  3424 00000CDF 8A87[2B0F]              	mov	al, [bx+hex_chars]
  3425 00000CE3 A2[7C0F]                	mov	[msgDevId], al
  3426                                  
  3427 00000CE6 668B36[EE0F]            	mov	esi, [bus_dev_fn]
  3428 00000CEB 66C1EE08                	shr	esi, 8
  3429 00000CEF 89F0                    	mov	ax, si
  3430 00000CF1 88C3                    	mov	bl, al
  3431 00000CF3 88DA                    	mov	dl, bl
  3432 00000CF5 80E307                  	and	bl, 7 ; bit 0,1,2
  3433 00000CF8 8A87[2B0F]              	mov	al, [bx+hex_chars]
  3434 00000CFC A2[A30F]                	mov	[msgFncNo+1], al
  3435 00000CFF 88D3                    	mov	bl, dl
  3436 00000D01 C0EB03                  	shr	bl, 3
  3437 00000D04 88DA                    	mov	dl, bl
  3438 00000D06 80E30F                  	and	bl, 0Fh
  3439 00000D09 8A87[2B0F]              	mov	al, [bx+hex_chars]
  3440 00000D0D A2[950F]                	mov	[msgDevNo+1], al
  3441 00000D10 88D3                    	mov	bl, dl
  3442 00000D12 C0EB04                  	shr	bl, 4
  3443 00000D15 8A87[2B0F]              	mov	al, [bx+hex_chars]
  3444 00000D19 A2[940F]                	mov	[msgDevNo], al
  3445 00000D1C 88E3                    	mov	bl, ah
  3446 00000D1E 88DA                    	mov	dl, bl
  3447 00000D20 80E30F                  	and	bl, 0Fh
  3448 00000D23 8A87[2B0F]              	mov	al, [bx+hex_chars]
  3449 00000D27 A2[890F]                	mov	[msgBusNo+1], al
  3450 00000D2A 88D3                    	mov	bl, dl
  3451 00000D2C C0EB04                  	shr	bl, 4
  3452 00000D2F 8A87[2B0F]              	mov	al, [bx+hex_chars]
  3453 00000D33 A2[880F]                	mov	[msgBusNo], al
  3454                                  
  3455                                  	;mov	ax, [ac97_io_base]
  3456                                  	; 08/05/2024
  3457 00000D36 A1[DA0F]                	mov	ax, [NABMBAR]
  3458 00000D39 88C3                    	mov	bl, al
  3459 00000D3B 88DA                    	mov	dl, bl
  3460 00000D3D 80E30F                  	and	bl, 0Fh
  3461 00000D40 8A87[2B0F]              	mov	al, [bx+hex_chars]
  3462 00000D44 A2[BC0F]                	mov	[msgIOBaseAddr+3], al
  3463 00000D47 88D3                    	mov	bl, dl
  3464 00000D49 C0EB04                  	shr	bl, 4
  3465 00000D4C 8A87[2B0F]              	mov	al, [bx+hex_chars]
  3466 00000D50 A2[BB0F]                	mov	[msgIOBaseAddr+2], al
  3467 00000D53 88E3                    	mov	bl, ah
  3468 00000D55 88DA                    	mov	dl, bl
  3469 00000D57 80E30F                  	and	bl, 0Fh
  3470 00000D5A 8A87[2B0F]              	mov	al, [bx+hex_chars]
  3471 00000D5E A2[BA0F]                	mov	[msgIOBaseAddr+1], al
  3472 00000D61 88D3                    	mov	bl, dl
  3473 00000D63 C0EB04                  	shr	bl, 4
  3474 00000D66 8A87[2B0F]              	mov	al, [bx+hex_chars]
  3475 00000D6A A2[B90F]                	mov	[msgIOBaseAddr], al
  3476                                  
  3477                                  	; 24/11/2016
  3478 00000D6D 30E4                    	xor	ah, ah
  3479 00000D6F A0[EC0F]                	mov	al, [ac97_int_ln_reg]
  3480 00000D72 B10A                    	mov	cl, 10
  3481 00000D74 F6F1                    	div	cl
  3482 00000D76 0106[C40F]              	add	[msgIRQ], ax
  3483 00000D7A 20C0                    	and	al, al
  3484 00000D7C 7508                    	jnz	short _pmi
  3485 00000D7E A0[C50F]                	mov	al, [msgIRQ+1]
  3486 00000D81 B420                    	mov	ah, ' '
  3487 00000D83 A3[C40F]                	mov	[msgIRQ], ax
  3488                                  _pmi:
  3489 00000D86 BA[3C0F]                        mov	dx, msgAC97Info
  3490 00000D89 B409                            mov     ah, 9
  3491 00000D8B CD21                            int     21h
  3492                                  
  3493 00000D8D C3                              retn
  3494                                  
  3495                                  	; 08/05/2024
  3496                                  ac97_stop:
  3497                                  	; 11/11/2023
  3498                                  	; 09/11/2023
  3499                                  	; 05/11/2023
  3500                                  	; 04/11/2023 
  3501                                  	; 28/05/2017 (TRDOS 386 v2, 'audio.s')
  3502                                  	;mov	byte [tLoop], 0 ; stop ! ; 05/11/2023
  3503                                  ;_ac97_stop:
  3504                                  
  3505                                  	; 11/11/2023
  3506 00000D8E 8B16[D80F]              	mov	dx, [NAMBAR]
  3507                                  	;add	dx, 0 ; ac_reg_0 ; reset register
  3508 00000D92 EF                      	out	dx, ax
  3509                                  
  3510                                  	; 04/11/2023
  3511                                  	; 09/10/2017 (TRDOS 386 v2, 'audio.s')
  3512                                  	; 11/06/2017
  3513 00000D93 30C0                    	xor	al, al ; 0
  3514 00000D95 E80D00                  	call	ac97_po_cmd
  3515                                  
  3516                                  	; (Ref: KolibriOS, intelac97.asm, 'stop:')
  3517                                  	; Clear FIFOE, BCIS, LVBCI (Ref: Intel ICH hub manual)
  3518 00000D98 B81C00                  	mov     ax, 1Ch
  3519 00000D9B 8B16[DA0F]              	mov     dx, [NABMBAR]
  3520 00000D9F 83C216                  	add     dx, PO_SR_REG
  3521 00000DA2 EF                      	out     dx, ax
  3522                                  
  3523                                  	; 11/06/2017
  3524 00000DA3 B002                    	mov     al, RR
  3525                                  ac97_po_cmd:
  3526                                  	; 11/06/2017
  3527                                  	; 29/05/2017
  3528 00000DA5 8B16[DA0F]              	mov     dx, [NABMBAR]
  3529 00000DA9 83C21B                          add     dx, PO_CR_REG		; PCM out control register
  3530 00000DAC EE                      	out	dx, al
  3531 00000DAD C3                      	retn
  3532                                  
  3533                                  ;=============================================================================
  3534                                  ;               preinitialized data
  3535                                  ;=============================================================================
  3536                                  
  3537                                  ;=============================================================================
  3538                                  ;               PLAY.ASM - DATA
  3539                                  ;=============================================================================
  3540                                  
  3541                                  msg_2017:
  3542 00000DAE 54696E79204D4F4420-     		db	'Tiny MOD Player by Erdogan Tan. May 2024.',10,13
  3542 00000DB7 506C61796572206279-
  3542 00000DC0 204572646F67616E20-
  3542 00000DC9 54616E2E204D617920-
  3542 00000DD2 323032342E0A0D     
  3543 00000DD9 75736167653A20706C-     		db	'usage: playmodm filename.mod', 10, 13, '$'
  3543 00000DE2 61796D6F646D206669-
  3543 00000DEB 6C656E616D652E6D6F-
  3543 00000DF4 640A0D24           
  3544 00000DF8 31382F30322F323031-     		db	'18/02/2017',0
  3544 00000E01 3700               
  3545 00000E03 32302F30352F323032-     		db	'20/05/2024',0
  3545 00000E0C 3400               
  3546                                  
  3547 00000E0E 54696E79204D4F4420-     Credits:	db	'Tiny MOD Player v0.1b by Carlos Hasan. July 1993.'
  3547 00000E17 506C61796572207630-
  3547 00000E20 2E3162206279204361-
  3547 00000E29 726C6F732048617361-
  3547 00000E32 6E2E204A756C792031-
  3547 00000E3B 3939332E           
  3548                                  CRLF:		; 13/05/2024
  3549 00000E3F 0A0D24                  		db	10,13,'$'
  3550 00000E42 4572726F72206C6F61-     ErrorMesg:	db	'Error loading Module file.',10,13,'$'
  3550 00000E4B 64696E67204D6F6475-
  3550 00000E54 6C652066696C652E0A-
  3550 00000E5D 0D24               
  3551                                  
  3552                                  ;=============================================================================
  3553                                  ;               MODPLAY.ASM - DATA
  3554                                  ;=============================================================================
  3555                                  
  3556                                  ;Credits:	db	'Amiga Module Player v0.3b by Carlos Hasan.'
  3557                                  
  3558 00000E5F 0019324A62788EA2B4-     SinTable:	db	0,25,50,74,98,120,142,162,180,197,212,225
  3558 00000E68 C5D4E1             
  3559 00000E6B ECF4FAFEFFFEFAF4EC-     		db	236,244,250,254,255,254,250,244,236,225
  3559 00000E74 E1                 
  3560 00000E75 D4C5B4A28E78624A32-     		db	212,197,180,162,142,120,98,74,50,25
  3560 00000E7E 19                 
  3561                                  
  3562 00000E7F 58032803FA02D002A6-     PeriodTable:	dw	856,808,762,720,678,640,604,570,538,508,480,453
  3562 00000E88 0280025C023A021A02-
  3562 00000E91 FC01E001C501       
  3563 00000E97 AC0194017D01680153-     		dw	428,404,381,360,339,320,302,285,269,254,240,226
  3563 00000EA0 0140012E011D010D01-
  3563 00000EA9 FE00F000E200       
  3564 00000EAF D600CA00BE00B400AA-     		dw	214,202,190,180,170,160,151,143,135,127,120,113
  3564 00000EB8 00A00097008F008700-
  3564 00000EC1 7F0078007100       
  3565                                  
  3566                                  ;=============================================================================
  3567                                  ;               PLAYWAV.ASM / PLAYER.ASM - DATA
  3568                                  ;=============================================================================
  3569                                  
  3570                                  ; 24/11/2016
  3571                                  ;	       IRQ  0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15 
  3572 00000EC7 08090A0B0C0D0E0F70-     irq_int:	db 08h,09h,0Ah,0Bh,0Ch,0Dh,0Eh,0Fh,70h,71h,72h,73h,74h,75h,76h,77h
  3572 00000ED0 71727374757677     
  3573                                  
  3574                                  ; 17/02/2017
  3575                                  ; Valid ICH device IDs
  3576                                  
  3577                                  valid_ids:
  3578 00000ED7 86801524                dd	(ICH_DID << 16) + INTEL_VID  	 ; 8086h:2415h
  3579 00000EDB 86802524                dd	(ICH0_DID << 16) + INTEL_VID 	 ; 8086h:2425h
  3580 00000EDF 86804524                dd	(ICH2_DID << 16) + INTEL_VID 	 ; 8086h:2445h
  3581 00000EE3 86808524                dd	(ICH3_DID << 16) + INTEL_VID 	 ; 8086h:2485h
  3582 00000EE7 8680C524                dd	(ICH4_DID << 16) + INTEL_VID 	 ; 8086h:24C5h
  3583 00000EEB 8680D524                dd	(ICH5_DID << 16) + INTEL_VID 	 ; 8086h:24D5h
  3584 00000EEF 86806E26                dd	(ICH6_DID << 16) + INTEL_VID 	 ; 8086h:266Eh
  3585 00000EF3 8680A625                dd	(ESB6300_DID << 16) + INTEL_VID  ; 8086h:25A6h
  3586 00000EF7 86809826                dd	(ESB631X_DID << 16) + INTEL_VID  ; 8086h:2698h
  3587 00000EFB 8680DE27                dd	(ICH7_DID << 16) + INTEL_VID 	 ; 8086h:27DEh
  3588                                  ; 03/11/2023 - Erdogan Tan
  3589 00000EFF 86809571                dd	(MX82440_DID << 16) + INTEL_VID  ; 8086h:7195h
  3590 00000F03 39101270                dd	(SI7012_DID << 16)  + SIS_VID	 ; 1039h:7012h
  3591 00000F07 DE10B101                dd 	(NFORCE_DID << 16)  + NVIDIA_VID ; 10DEh:01B1h
  3592 00000F0B DE106A00                dd 	(NFORCE2_DID << 16) + NVIDIA_VID ; 10DEh:006Ah
  3593 00000F0F 22106D74                dd 	(AMD8111_DID << 16) + AMD_VID 	 ; 1022h:746Dh
  3594 00000F13 22104574                dd 	(AMD768_DID << 16)  + AMD_VID 	 ; 1022h:7445h
  3595 00000F17 DE105900                dd 	(CK804_DID << 16) + NVIDIA_VID	 ; 10DEh:0059h
  3596 00000F1B DE103A00                dd 	(MCP04_DID << 16) + NVIDIA_VID	 ; 10DEh:003Ah
  3597 00000F1F DE108A00                dd 	(CK8_DID << 16) + NVIDIA_VID	 ; 1022h:008Ah
  3598 00000F23 DE10DA00                dd 	(NFORCE3_DID << 16) + NVIDIA_VID ; 10DEh:00DAh
  3599 00000F27 DE10EA00                dd 	(CK8S_DID << 16) + NVIDIA_VID	 ; 10DEh:00EAh
  3600                                  
  3601                                  valid_id_count:	equ ($ - valid_ids)>>2 ; 05/11/2023
  3602                                  
  3603                                  ; 13/11/2016
  3604 00000F2B 303132333435363738-     hex_chars	db "0123456789ABCDEF", 0
  3604 00000F34 3941424344454600   
  3605 00000F3C 414339372041756469-     msgAC97Info	db "AC97 Audio Controller & Codec Info", 0Dh, 0Ah
  3605 00000F45 6F20436F6E74726F6C-
  3605 00000F4E 6C6572202620436F64-
  3605 00000F57 656320496E666F0D0A 
  3606 00000F60 56656E646F72204944-     		db "Vendor ID: "
  3606 00000F69 3A20               
  3607 00000F6B 303030306820446576-     msgVendorId	db "0000h Device ID: "
  3607 00000F74 6963652049443A20   
  3608 00000F7C 30303030680D0A          msgDevId	db "0000h", 0Dh, 0Ah
  3609 00000F83 4275733A20              		db "Bus: "
  3610 00000F88 303068204465766963-     msgBusNo	db "00h Device: "
  3610 00000F91 653A20             
  3611 00000F94 3030682046756E6374-     msgDevNo	db "00h Function: "
  3611 00000F9D 696F6E3A20         
  3612 00000FA2 303068                  msgFncNo	db "00h"
  3613 00000FA5 0D0A                    		db 0Dh, 0Ah
  3614 00000FA7 492F4F204261736520-     		db "I/O Base Address: "
  3614 00000FB0 416464726573733A20 
  3615 00000FB9 303030306820495251-     msgIOBaseAddr	db "0000h IRQ: "
  3615 00000FC2 3A20               
  3616 00000FC4 3030                    msgIRQ		dw 3030h
  3617 00000FC6 0D0A24                  		db 0Dh, 0Ah, "$"
  3618                                  
  3619                                  ;msgSampleRate	db "Sample Rate: "
  3620                                  ;msgHertz	db "00000 Hz ", "$" 
  3621                                  ;msg8Bits	db "8 bits ", "$" 
  3622                                  ;msgMono	db "Mono", 0Dh, 0Ah, "$"
  3623                                  ;msg16Bits	db "16 bits ", "$" 
  3624                                  ;msgStereo	db "Stereo", 0Dh, 0Ah, "$"
  3625                                  
  3626                                  ;; 13/11/2016 - Erdogan Tan (Ref: KolibriOS, codec.inc)
  3627                                  ;codec_id	dd 0
  3628                                  ;codec_chip_id	dd 0
  3629                                  ;codec_vendor_ids dw 0
  3630                                  ;codec_chip_ids	dw 0
  3631                                  
  3632 00000FC9 3030303030303030        dword_str	 dd 30303030h, 30303030h
  3633 00000FD1 680D0A00                		 db 'h', 0Dh, 0Ah, 0
  3634                                  
  3635                                  ;=============================================================================
  3636                                  ;        	uninitialized data
  3637                                  ;=============================================================================
  3638                                  
  3639                                  bss_start:
  3640                                  
  3641                                  ABSOLUTE bss_start
  3642                                  
  3643 00000FD5 ??????                  alignb 4
  3644                                  
  3645                                  ; 17/02/2017
  3646                                  ; NAMBAR:  Native Audio Mixer Base Address Register
  3647                                  ;    (ICH, Audio D31:F5, PCI Config Space) Address offset: 10h-13h
  3648                                  ; NABMBAR: Native Audio Bus Mastering Base Address register
  3649                                  ;    (ICH, Audio D31:F5, PCI Config Space) Address offset: 14h-17h
  3650 00000FD8 ????                    NAMBAR:		resw 1			; BAR for mixer
  3651 00000FDA ????                    NABMBAR         resw 1			; BAR for bus master regs
  3652                                  
  3653 00000FDC ??                      tBuff:		resb	1
  3654                                  ;irq_status:	resb 	1
  3655 00000FDD ??                      pcm_irq_status:	resb	1 ; 08/05/2024
  3656                                  
  3657 00000FDE ??                      inside:		resb	1 
  3658 00000FDF ??                      tLoop:		resb 	1
  3659                                  
  3660                                  ; 08/05/2024
  3661 00000FE0 ????                    IRQ_status:	resw 1	; IRQ status before enabling audio interrupt
  3662 00000FE2 ????????                IRQ_vector:	resd 1  ; Previous interrupt handler address
  3663                                  
  3664                                  ; 256 byte buffer for descriptor list
  3665 00000FE6 ????                    BDL_BUFFER:	resw	1		; segment of our 256byte BDL buffer
  3666 00000FE8 ????                    DMA_BUFFER1:	resw 	1		; Pointer to 1st half of DMA Buffer
  3667 00000FEA ????                    DMA_BUFFER2:	resw	1		; Pointer to 2nd half of DMA Buffer
  3668                                  
  3669                                  ; 12/11/2016 - Erdogan Tan
  3670                                  
  3671 00000FEC ??                      ac97_int_ln_reg: resb 1 
  3672 00000FED ??                      err_num:	resb 1
  3673                                  
  3674 00000FEE ????????                bus_dev_fn:	resd 1
  3675 00000FF2 ????????                dev_vendor:	resd 1
  3676                                  ; 08/05/2024
  3677                                  ;stats_cmd:	resd 1
  3678                                  ;ac97_io_base:	resw 1
  3679 00000FF6 ??                      LVI:		resb 1
  3680                                  ; 12/05/2024
  3681 00000FF7 ??                      volume:		resb 1
  3682                                  
  3683                                  alignb 4
  3684                                  
  3685 00000FF8 <res 100h>              BdlBuffer:	resb	BDL_SIZE ; 13/02/2017
  3686 000010F8 <res 5000h>             DmaBuffer:	resb	2*BUFFERSIZE ; 13/02/2017
  3687                                  
  3688                                  ; MODLOAD.ASM
  3689 000060F8 ????                    FileHandle:	resw	1
  3690 000060FA ????                    ErrorInfo:	resw	1
  3691 000060FC <res 43Ch>              Header:		resb	ModHeader.size
  3692                                  
  3693                                  sample_rate: ; PLAYER.ASM (22050Hz)
  3694                                  ; MODPLAY.ASM
  3695 00006538 ????                    MixSpeed:	resw 1
  3696                                  
  3697                                  ModInfo:
  3698 0000653A ??                      ModInfo.OrderLen:   resb 1
  3699 0000653B ??                      ModInfo.ReStart:    resb 1
  3700 0000653C <res 80h>               ModInfo.Order:	    resb 128
  3701 000065BC ????????                ModInfo.Patterns:   resd 1
  3702                                  
  3703 000065C0 <res 3Eh>               ModInfo.SampOfs:    resw 31
  3704 000065FE <res 3Eh>               ModInfo.SampSeg:    resw 31
  3705 0000663C <res 3Eh>               ModInfo.SampLen:    resw 31
  3706 0000667A <res 3Eh>               ModInfo.SampRep:    resw 31
  3707 000066B8 <res 3Eh>               ModInfo.SampRepLen: resw 31
  3708 000066F6 <res 3Eh>               ModInfo.SampVol:    resw 31
  3709                                  
  3710                                  ; MODPLAY.ASM
  3711 00006734 <res 6B2h>              PitchTable:	resw	857
  3712 00006DE6 <res 4100h>             VolTable:	resb	16640
  3713 0000AEE6 <res 1000h>             MixBuffer       resb	MixBufSize
  3714                                  
  3715                                  ; MODPLAY.ASM
  3716 0000BEE6 ??                      OrderPos:	resb 1
  3717 0000BEE7 ??                      Tempo:		resb 1
  3718 0000BEE8 ??                      TempoWait:	resb 1
  3719 0000BEE9 ??                      Bpm:		resb 1
  3720 0000BEEA ??                      Row:		resb 1
  3721 0000BEEB ??                      BreakRow:	resb 1
  3722 0000BEEC ????                    BpmSamples:	resw 1
  3723 0000BEEE ????                    BufPtr:		resw 1
  3724 0000BEF0 ????                    BufLen:		resw 1
  3725 0000BEF2 ????                    BufRep:		resw 1
  3726 0000BEF4 ????????                Note:		resd 1
  3727 0000BEF8 <res 88h>               Tracks:		resb TrackInfo.size*NumTracks
  3728                                  
  3729                                  alignb 16
  3730                                  
  3731                                  ; PLAY.ASM
  3732 0000BF80 <res 280h>              Scope:		resw	320
  3733 0000C200 <res 200h>              RowOfs:		resw	256
  3734                                  
  3735                                  ; 18/02/2017
  3736 0000C400 ????                    _si_:		resw 1
  3737 0000C402 <res A00h>              MOD_BUFFER:	resb BUFFERSIZE/4 ; 2048 ; 11/05/2024
  3738                                  EOF:
