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