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