     1                                  ; ****************************************************************************
     2                                  ; cgaplay2.asm - Retro DOS (MSDOS/PCDOS) WAV PLAYER - Video Mode 13h
     3                                  ; ----------------------------------------------------------------------------
     4                                  ; CGAPLAY2.COM ! Sound Blaster 16 .WAV PLAYER program by Erdogan TAN
     5                                  ;
     6                                  ; 02/01/2025				- play music from multiple wav files -
     7                                  ;
     8                                  ; [ Last Modification: 07/02/2025 ]
     9                                  ;
    10                                  ; Modified from CGAPLAY.COM .wav player program by Erdogan Tan, 01/01/2025
    11                                  ;	        SB16PLAY.COM, 20/12/2024
    12                                  ;
    13                                  ; ****************************************************************************
    14                                  ; nasm cgaplay2.asm -l cgaplay2.lst -o CGAPLAY2.COM -Z error.txt
    15                                  
    16                                  ; 01/01/2025
    17                                  ; cgaplay.asm  : Video Mode 13h (320*200, 256 colors) -NASM-
    18                                  ; 20/12/2024
    19                                  ; sb16play.asm : Video Mode 03h (80x25 text mode) -FASM-
    20                                  
    21                                  ; vgaplay.s (26/12/2024) - play music from multiple wav files -
    22                                  ; dplayvga.s (25/12/2024) - play music from single wav file -
    23                                  ; ac97play.s (18/12/2024) - play music from multiple wav files -
    24                                  
    25                                  ; 07/12/2024 - playwav9.s - interrupt (srb) + tuneloop version
    26                                  ; ------------------------------------------------------------
    27                                  ; INTERRUPT (SRB) + TUNELOOP version ; 24/11/2024 (PLAYWAV9.ASM)
    28                                  ;	(running in DOSBOX, VIRTUALBOX, QEMU is ok)
    29                                  ; Signal Response Byte = message/signal to user about an event/interrupt
    30                                  ;	    as requested (TuneLoop procedure continuously checks this SRB)
    31                                  ; (TRDOS 386 v2 feature is used here as very simple interrupt handler output)
    32                                  
    33                                  ; ------------------------------------------------------------
    34                                  
    35                                  ; 01/01/2025
    36                                  %macro	sys_msg	2
    37                                  	mov	si, %1	; message
    38                                  	mov	bl, %2	; text color
    39                                  	xor	bh, bh	; video page 0
    40                                  	mov	ah, 0Eh
    41                                  	call	p_msg	
    42                                  %endmacro
    43                                  
    44                                  ; 02/01/2025
    45                                  %macro SbOut 1
    46                                  %%wait:
    47                                  	in	al, dx
    48                                  	or	al, al
    49                                  	js	short %%wait
    50                                  	mov	al, %1	; command
    51                                  	out	dx, al
    52                                  %endmacro
    53                                  
    54                                  ; ------------------------------------------------------------
    55                                  
    56                                  ; player internal variables and other equates.
    57                                  ; -------------------------
    58                                  ; 02/01/2025 - cgaplay2.asm
    59                                  ; -------------------------
    60                                  ; 20/12/2024 - sb16play.asm
    61                                  ;--------------------------
    62                                  ; 17/11/2024
    63                                  ;BUFFERSIZE	equ 65520
    64                                  ; 24/11/2024
    65                                  ;dma_buffer_size equ 32768
    66                                  ;LOADSIZE	equ 16384
    67                                  ENDOFFILE	equ 1		; flag for knowing end of file
    68                                  ; 27/11/2024
    69                                  dma_buffer_size equ 44100
    70                                  LOADSIZE	equ 22050
    71                                  
    72                                  ; ------------------------------------------------------------
    73                                  
    74                                  [BITS 16] ; 16-bit intructions
    75                                  
    76                                  [ORG 100h]
    77                                  
    78                                  	; 02/01/2025
    79                                  START_CODE:
    80                                  	; 30/05/2024
    81                                  	; Prints the Credits Text.
    82                                  	sys_msg Credits, 0Bh
    37 00000000 BE[3A0C]            <1>  mov si, %1
    38 00000003 B30B                <1>  mov bl, %2
    39 00000005 30FF                <1>  xor bh, bh
    40 00000007 B40E                <1>  mov ah, 0Eh
    41 00000009 E8D801              <1>  call p_msg
    83                                  
    84                                  	; 01/01/2025
    85                                  	; (setFree is required before memAlloc)
    86                                  	; 30/05/2024
    87 0000000C E81505                          call    setFree		; deallocate unused DOS mem
    88                                  
    89                                  	; 17/02/2017
    90                                  	; Clear BSS (uninitialized data) area
    91 0000000F 31C0                    	xor	ax, ax ; 0
    92 00000011 B9BD57                  	mov	cx, (bss_end - bss_start)/2
    93 00000014 BF[AA11]                	mov	di, bss_start
    94 00000017 F3AB                    	rep	stosw
    95                                  
    96                                  ; -------------------------------------------------------------
    97                                  
    98                                  	; 02/01/2025
    99                                  	; 24/11/2024
   100                                  	; Detect (& Reset) Sound Blaster 16 Audio Device
   101 00000019 E8EC02                  	call	DetectSB16
   102                                  	;jnc	short GetFileName
   103                                  	; 02/01/2025
   104 0000001C 730F                    	jnc	short set_video_mode_13h
   105                                  
   106                                  	; 30/11/2024
   107                                  	; 30/05/2024
   108                                  _dev_not_ready:
   109                                  	; couldn't find the audio device!
   110                                  	sys_msg noDevMsg, 0Fh
    37 0000001E BE[F40C]            <1>  mov si, %1
    38 00000021 B30F                <1>  mov bl, %2
    39 00000023 30FF                <1>  xor bh, bh
    40 00000025 B40E                <1>  mov ah, 0Eh
    41 00000027 E8BA01              <1>  call p_msg
   111 0000002A E98901                          jmp     Exit
   112                                  
   113                                  ; -------------------------------------------------------------
   114                                  
   115                                  	; 02/01/2025
   116                                  set_video_mode_13h:
   117                                  	; 01/01/2025
   118                                  	; set VGA/CGA mode (320*200 pixels, 256 colors)
   119 0000002D B81300                  	mov	ax, 13h
   120 00000030 CD10                    	int	10h
   121                                  
   122                                  ; -------------------------------------------------------------
   123                                  
   124                                  mode_13h_set_ok:
   125                                  	; 01/01/2025
   126                                  	;mov	word [graphstart], (11*8*320)+(4*320)
   127                                  
   128                                  ; -------------------------------------------------------------
   129                                  
   130                                  	; 01/01/2025
   131                                  Player_ParseParameters:
   132                                  	; 28/11/2024
   133 00000032 BE8100                  	mov	si, 81h
   134 00000035 8936[7014]              	mov	[PSP_CurrentOffset], si
   135 00000039 803C0D                  	cmp	byte [si], 0Dh		; "CR": No command line parameters
   136 0000003C 7737                    	ja	short Player_ParseNextParameter ; 01/01/2025
   137 0000003E E97C01                  	jmp	pmsg_usage
   138                                  
   139                                  	; 30/12/2024
   140                                  	; 29/11/2024
   141                                  check_p_command:
   142 00000041 803E[3C14]50              	cmp	byte [command], 'P'
   143 00000046 740C                    	je	short Player_ParsePreviousParameter
   144                                      
   145 00000048 8B36[7014]              	mov	si, [PSP_CurrentOffset]
   146 0000004C 803C0D                  	cmp	byte [si], 0Dh
   147 0000004F 7724                    	ja	short Player_ParseNextParameter
   148                                  jmp_Player_Quit:
   149 00000051 E9D101                  	jmp	Player_Quit
   150                                  
   151                                  Player_ParsePreviousParameter:
   152                                  	; 29/11/2024
   153                                  	;mov	byte [command], 0
   154                                  
   155 00000054 8B36[7014]              	mov	si, [PSP_CurrentOffset]
   156                                  
   157 00000058 81FE8100                	cmp	si, 81h
   158 0000005C 7417                    	je	short Player_ParseNextParameter
   159                                  
   160                                  	;; Search for previous space character
   161 0000005E 4E                      	dec	si
   162 0000005F B90200                  	mov	cx, 2
   163                                  PSPParsePrev_Search:
   164 00000062 4E                      	dec	si
   165 00000063 8A04                    	mov	al, [si]
   166 00000065 3C20                    	cmp	al, 20h
   167 00000067 75F9                    	jne	short PSPParsePrev_Search
   168                                  
   169 00000069 81FE8100                	cmp	si, 81h
   170 0000006D 7602                    	jna	PSPParsePrev_Copy
   171 0000006F E2F1                    	loop	PSPParsePrev_Search
   172                                  
   173                                  PSPParsePrev_Copy:
   174 00000071 8936[7014]              	mov	[PSP_CurrentOffset], si
   175                                  	
   176                                  Player_ParseNextParameter:
   177                                  	; 29/11/2024
   178 00000075 E82600                  	call	GetFileName
   179 00000078 E3D7                    	jcxz	jmp_Player_Quit
   180                                  
   181                                  	; 01/01/2025
   182                                  	; 28/11/2024
   183 0000007A BA[7214]                	mov	dx, wav_file_name
   184                                  
   185                                  	; 30/12/2024
   186                                          ; open existing file
   187 0000007D E85104                          call	openFile ; no error? ok.
   188 00000080 736C                            jnc	getwavparms	; 14/11/2024
   189                                  
   190                                  	; 29/11/2024
   191 00000082 803E[3D14]00            	cmp	byte [filecount], 0
   192 00000087 77B8                    	ja	short check_p_command
   193                                  
   194                                  	; 25/12/2024
   195                                  	; 21/12/2024
   196 00000089 E88401                  	call	set_text_mode
   197                                  	; file not found!
   198                                  	; 01/01/2025
   199                                  	; 30/11/2024
   200                                  	sys_msg	noFileErrMsg, 0Ch
    37 0000008C BE[2B0D]            <1>  mov si, %1
    38 0000008F B30C                <1>  mov bl, %2
    39 00000091 30FF                <1>  xor bh, bh
    40 00000093 B40E                <1>  mov ah, 0Eh
    41 00000095 E84C01              <1>  call p_msg
   201 00000098 E91B01                          jmp     Exit
   202                                  
   203                                  _exit_:
   204 0000009B E91501                  	jmp	terminate
   205                                  
   206                                  ; -------------------------------------------------------------
   207                                  
   208                                  	; 29/11/2024
   209                                  	; 30/05/2024
   210                                  GetFileName:
   211 0000009E BF[7214]                	mov	di, wav_file_name 
   212 000000A1 8B36[7014]              	mov	si, [PSP_CurrentOffset]
   213 000000A5 31C9                    	xor	cx, cx ; 0
   214                                  ScanName:
   215 000000A7 AC                      	lodsb
   216                                  	;test	al, al
   217                                  	;jz	short a_4
   218                                  	; 29/11/2024
   219 000000A8 3C0D                    	cmp	al, 0Dh
   220 000000AA 7639                    	jna	short a_4
   221 000000AC 3C20                    	cmp	al, 20h
   222 000000AE 74F7                    	je	short ScanName	; scan start of name.
   223 000000B0 AA                      	stosb
   224 000000B1 B4FF                    	mov	ah, 0FFh
   225                                  	;;;
   226                                  	; 14/11/2024
   227                                  	; (max. path length = 64 bytes for MSDOS ?) (*)
   228                                  	;xor	cx, cx ; 0
   229                                  	;;;
   230                                  a_0:	
   231 000000B3 FEC4                    	inc	ah
   232                                  a_1:
   233                                  	;;;
   234                                  	; 14/11/2024
   235 000000B5 41                      	inc	cx
   236                                  	;;;
   237 000000B6 AC                      	lodsb
   238 000000B7 AA                      	stosb
   239 000000B8 3C2E                    	cmp	al, '.'
   240 000000BA 74F7                    	je	short a_0
   241                                  	; 29/11/2024
   242 000000BC 3C20                    	cmp	al, 20h
   243                                  	;and	al, al
   244                                  	;jnz	short a_1
   245                                  	;;;
   246                                  	; 14/11/2024
   247 000000BE 7613                    	jna	short a_3
   248 000000C0 20E4                    	and	ah, ah
   249 000000C2 7406                    	jz	short a_2
   250 000000C4 3C5C                    	cmp	al, '\'
   251 000000C6 7502                    	jne	short a_2
   252 000000C8 B400                    	mov	ah, 0
   253                                  a_2:
   254 000000CA 80F94B                  	cmp	cl, 75	; 64+8+'.'+3 -> offset 75 is the last chr
   255 000000CD 72E6                    	jb	short a_1
   256                                  	; 29/11/2024
   257 000000CF 29C9                    	sub	cx, cx
   258 000000D1 EB12                    	jmp	short a_4
   259                                  a_3:
   260                                  	; 29/11/2024
   261 000000D3 4F                      	dec	di
   262                                  	;;;
   263 000000D4 08E4                    	or	ah, ah		; if period NOT found,
   264 000000D6 750D                    	jnz	short a_4 	; then add a .WAV extension.
   265                                  SetExt:
   266                                  	; 29/11/2024
   267                                  	;dec	di
   268 000000D8 66C7052E574156          	mov	dword [di], '.WAV' ; ! 64+12 is DOS limit
   269                                  				   ;   but writing +4 must not
   270                                  				   ;   destroy the following data	 
   271                                  	;mov	byte [di+4], 0	   ; so, 80 bytes path + 0 is possible here
   272                                  	; 29/11/2024
   273 000000DF 83C104                  	add	cx, 4
   274 000000E2 83C704                  	add	di, 4
   275                                  a_4:	
   276 000000E5 C60500                  	mov	byte [di], 0
   277 000000E8 4E                      	dec	si
   278 000000E9 8936[7014]              	mov	[PSP_CurrentOffset], si
   279 000000ED C3                      	retn
   280                                  
   281                                  ; -------------------------------------------------------------
   282                                  
   283                                  getwavparms:
   284                                  	; 14/11/2024
   285 000000EE E8FF03                         	call    getWAVParameters
   286 000000F1 72A8                    	jc	short _exit_		; nothing to do
   287                                  
   288                                  	; 17/11/2024
   289 000000F3 B304                    	mov	bl, 4
   290 000000F5 2A1E[6014]              	sub	bl, byte [WAVE_BlockAlign]
   291                                  			; = 0 for 16 bit stereo
   292                                  			; = 2 for 8 bit stereo or 16 bit mono
   293                                  			; = 3 for 8 bit mono	
   294                                  
   295 000000F9 D0EB                    	shr	bl, 1	;  0 -->  0,  2 -->  1,  3 -->  1
   296                                  	; 15/11/2024
   297 000000FB 80D300                  	adc	bl, 0	; 3 --> 1 --> 2
   298 000000FE 881E[C414]              	mov	byte [fbs_shift], bl	; = 2 mono and 8 bit
   299                                  					; = 0 stereo and 16 bit
   300                                  					; = 1 mono or 8 bit
   301                                  	; 02/01/2025
   302                                  
   303                                  ; -------------------------------------------------------------
   304                                  
   305                                  	; 02/01/2025
   306                                  StartPlay:
   307                                  	; 30/12/2024
   308 00000102 C606[3714]01            	mov	byte [wpoints], 1
   309                                  
   310                                  	; 02/01/2025
   311 00000107 A1[5814]                	mov	ax, [WAVE_SampleRate]
   312 0000010A B90A00                  	mov	cx, 10
   313 0000010D F7E1                    	mul	cx
   314 0000010F B1B6                    	mov	cl, 182
   315 00000111 F7F1                    	div	cx
   316                                  	; ax = samples per 1/18.2 second
   317 00000113 8A0E[6014]              	mov	cl, byte [WAVE_BlockAlign]
   318 00000117 F7E1                    	mul	cx
   319                                  _w:
   320 00000119 A3[A611]                	mov	[wpoints_dif], ax ; buffer read differential (distance)
   321                                  				; for wave volume leds update
   322                                  				; (byte stream per 1/18.2 second)
   323                                  
   324                                  ; -------------------------------------------------------------
   325                                  
   326                                  	; 02/01/2025 (cgaplay2.asm)
   327                                  	;;;
   328                                  	; 23/11/2024 (sb16play.asm, [turn_on_leds])
   329 0000011C 803E[5614]01            	cmp	byte [WAVE_NumChannels], 1
   330 00000121 7717                    	ja	short stolp_s
   331                                  stolp_m:
   332 00000123 803E[6214]08            	cmp	byte [WAVE_BitsPerSample], 8
   333 00000128 7708                    	ja	short stolp_m16
   334                                  stolp_m8:
   335 0000012A C706[C814][6309]        	mov	word [UpdateWavePoints], UpdateWavePoints_8m
   336 00000130 EB1F                    	jmp	short stolp_ok
   337                                  stolp_m16:
   338 00000132 C706[C814][6308]        	mov	word [UpdateWavePoints], UpdateWavePoints_16m
   339 00000138 EB17                    	jmp	short stolp_ok
   340                                  stolp_s:
   341 0000013A 803E[6214]08            	cmp	byte [WAVE_BitsPerSample], 8
   342 0000013F 7708                    	ja	short stolp_s16
   343                                  stolp_s8:
   344 00000141 C706[C814][DF08]        	mov	word [UpdateWavePoints], UpdateWavePoints_8s
   345 00000147 EB08                    	jmp	short stolp_ok
   346                                  stolp_s16:
   347 00000149 C706[C814][DD07]        	mov	word [UpdateWavePoints], UpdateWavePoints_16s
   348 0000014F EB00                    	jmp	short stolp_ok
   349                                  stolp_ok:
   350                                  	;;;
   351                                  
   352                                  	; 25/12/2024 (vgaplay.s)
   353 00000151 FE06[3D14]              	inc	byte [filecount]
   354 00000155 C606[3C14]00            	mov	byte [command], 0
   355                                  	; 30/12/2024 (cgaplay.s)
   356 0000015A C606[A911]FF            	mov	byte [pbprev], -1
   357                                  
   358                                  ; -------------------------------------------------------------
   359                                  
   360                                  	; 02/01/2025
   361                                  	; 01/01/2025 (cgaplay.asm)
   362                                  	; 30/12/2024
   363                                  Player_Template:
   364                                  	; 21/12/2024
   365 0000015F E88C00                  	call	clearscreen
   366 00000162 E89A00                  	call	drawplayingscreen
   367                                  	; 14/11/2024
   368 00000165 E8D508                  	call	SetTotalTime
   369 00000168 E87509                  	call	UpdateFileInfo
   370                                  
   371                                  ; -------------------------------------------------------------
   372                                  
   373                                  	; 02/01/2025 (cgaplay2.asm) -SB16-
   374                                  	; 01/01/2025 (cgaplay.asm) -AC97-
   375                                  	; 30/12/2024 (cgaplay.s) -AC97- 	
   376                                  	; 29/12/2024 (vgaplay3.s) -AC97-
   377                                  	; 20/12/2024 (sb16play.asm) 
   378                                  	; 18/12/2024 (ac97play.s)
   379                                  PlayNow:
   380                                  	; 01/12/2024 (32bit)
   381                                  	; 14/11/2024
   382                                  	;;mov	al, 3	; 0 = max, 31 = min
   383                                  	; 24/11/2024
   384                                  	;mov	al, 5	; 15 = max, 0 = min
   385                                  	; 27/11/2024
   386                                  	;mov	[volume], al
   387                                  	; 14/12/2024
   388 0000016B A0[350A]                	mov	al, [volume]
   389                                  	;call	SetPCMOutVolume@
   390                                  	; 02/01/2025
   391 0000016E E87E01                  	call	SetMasterVolume@
   392                                  	; 15/11/2024
   393                                  	;call	SetMasterVolume
   394                                  	;;call	SetPCMOutVolume
   395                                  
   396                                  	;;;
   397                                  	; 14/11/2024
   398 00000171 E8EF09                  	call	UpdateProgressBar
   399                                  	;;;
   400                                  
   401                                   	; 30/05/2024
   402                                  	; playwav4.asm
   403                                  _2:	
   404 00000174 E86908                  	call	check4keyboardstop	; flush keyboard buffer
   405 00000177 72FB                    	jc	short _2		; 07/11/2023
   406                                  
   407                                  	; 01/01/2025 (cgaplay.asm)
   408                                  
   409                                  ; play the .wav file. Most of the good stuff is in here.
   410                                  
   411 00000179 E8AB00                  	call    PlayWav
   412                                  
   413                                  	; 30/12/2024
   414                                  	; 29/12/2024 (vgaplay3.s)
   415                                  	; 27/12/2024 (vgaplay.s)
   416                                  _3:
   417                                  
   418                                  ; close the .wav file and exit.
   419                                  
   420                                  	; 25/12/2024
   421 0000017C E86003                  	call	closeFile
   422                                  
   423                                  	; 01/01/2025 (16bit modifications)
   424                                  	; 25/12/2024
   425                                  	;;;
   426                                  	; reset file loading and EOF parameters
   427                                  	; 18/12/2024
   428 0000017F C706[CE14]0000          	mov	word [count], 0
   429                                  	;mov	dword [LoadedDataBytes], 0
   430 00000185 C706[D014]0000          	mov	word [LoadedDataBytes], 0
   431 0000018B C706[D214]0000          	mov	word [LoadedDataBytes+2], 0
   432 00000191 C606[6C14]00            	mov	byte [flags], 0
   433 00000196 C606[3514]00            	mov	byte [stopped], 0
   434                                  	; 29/12/2024
   435 0000019B C706[3A14]0000          	mov	word [pbuf_s], 0
   436                                  	;;;
   437                                  
   438 000001A1 803E[3C14]51            	cmp	byte [command], 'Q'
   439                                  	;je	short terminate
   440                                  	; 02/01/2025
   441 000001A6 7403                    	je	short terminate@
   442 000001A8 E996FE                  	jmp	check_p_command
   443                                  
   444                                  	; 02/01/2025
   445                                  terminate@:
   446                                  	; 27/11/2024
   447                                  	; 24/11/2024
   448                                  	; restore old interrupt vector
   449                                  	;mov	al, [IRQnum]
   450                                  	; 07/02/2025 (BugFix)
   451 000001AB A0[3314]                	mov	al, [audio_intr]
   452 000001AE 30E4                    	xor	ah, ah ; reset
   453 000001B0 E8ED01                  	call	set_hardware_int_vector
   454                                  
   455                                  terminate:
   456 000001B3 E85A00                  	call	set_text_mode
   457                                  	
   458                                  Exit:	; 01/01/2025
   459 000001B6 B8004C                  	mov	ax, 4C00h	; bye !
   460 000001B9 CD21                    	int	21h
   461                                  halt:
   462 000001BB EBFE                    	jmp	short halt
   463                                  
   464                                  ; -------------------------------------------------------------
   465                                  
   466                                  	; 30/05/2024
   467                                  pmsg_usage:
   468                                  	; 21/12/2024
   469 000001BD E85000                  	call	set_text_mode
   470                                  	; 01/01/2025
   471                                  	; 01/12/2024
   472                                  	sys_msg msg_usage, 0Fh
    37 000001C0 BE[C40C]            <1>  mov si, %1
    38 000001C3 B30F                <1>  mov bl, %2
    39 000001C5 30FF                <1>  xor bh, bh
    40 000001C7 B40E                <1>  mov ah, 0Eh
    41 000001C9 E81800              <1>  call p_msg
   473 000001CC EBE8                    	jmp	short Exit
   474                                  
   475                                  ; -------------------------------------------------------------
   476                                  
   477                                  	; 30/05/2024
   478                                  init_err:
   479                                  	; 21/12/2024
   480 000001CE E83F00                  	call	set_text_mode
   481                                  	; 01/01/2025
   482                                  	; 01/12/2024
   483                                  	sys_msg msg_init_err, 0Fh
    37 000001D1 BE[440D]            <1>  mov si, %1
    38 000001D4 B30F                <1>  mov bl, %2
    39 000001D6 30FF                <1>  xor bh, bh
    40 000001D8 B40E                <1>  mov ah, 0Eh
    41 000001DA E80700              <1>  call p_msg
   484 000001DD EBD7                    	jmp	short Exit
   485                                  
   486                                  ; -------------------------------------------------------------
   487                                  
   488                                  	; 01/01/2025 (cgaplay.asm)
   489                                  	; 21/12/2024
   490                                  	; 14/11/2024
   491                                  PrintString:
   492 000001DF B40E                    	mov	ah, 0Eh
   493 000001E1 BB0F00                  	mov	bx, 0Fh ; char attribute & color (white)
   494                                  p_msg:
   495                                  	; ah = 0Eh
   496                                  	; bh = 0
   497                                  	; bl = color
   498                                  	; ds:si = msg address
   499                                  p_next_chr:
   500 000001E4 AC                      	lodsb
   501 000001E5 08C0                    	or	al, al
   502 000001E7 7404                    	jz	short p_retn ; retn
   503 000001E9 CD10                    	int	10h
   504 000001EB EBF7                    	jmp	short p_next_chr
   505                                  p_retn:
   506 000001ED C3                      	retn
   507                                  
   508                                  ; -------------------------------------------------------------
   509                                  
   510                                  	; 01/01/2025 (cgaplay.asm)
   511                                  clearscreen:
   512                                  	; fast clear
   513                                  	; 320*200, 256 colors
   514 000001EE 06                      	push	es
   515 000001EF BF00A0                  	mov	di, 0A000h
   516 000001F2 8EC7                    	mov	es, di
   517 000001F4 31FF                    	xor	di, di
   518 000001F6 B9007D                  	mov	cx, 320*200*1/2
   519 000001F9 31C0                    	xor	ax, ax
   520 000001FB F3AB                    	rep	stosw
   521 000001FD 07                      	pop	es
   522 000001FE C3                      	retn
   523                                  
   524                                  ; -------------------------------------------------------------
   525                                  
   526                                  	; 01/01/2025v (cgaplay.asm)
   527                                  drawplayingscreen:
   528                                  	;push	es
   529                                  	;push	bp
   530                                  	;push	ds
   531                                  	;pop	es
   532                                  	; es = ds
   533 000001FF BD[DC0D]                	mov	bp, PlayingScreen
   534 00000202 B80013                  	mov	ax, 1300h ; write character string
   535 00000205 BB0F00                  	mov	bx, 0Fh
   536 00000208 B9C003                  	mov	cx, 24*40
   537 0000020B 31D2                    	xor	dx, dx ; row 0, columns 0
   538 0000020D CD10                    	int	10h
   539                                  	;pop	bp
   540                                  	;pop	es
   541 0000020F C3                      	retn
   542                                  
   543                                  ; -------------------------------------------------------------
   544                                  
   545                                  	; 01/01/2025
   546                                  set_text_mode:
   547 00000210 B80300                  	mov	ax, 03h
   548 00000213 CD10                    	int	10h
   549                                  	;retn
   550                                  
   551                                  	sys_msg Credits, 0Bh
    37 00000215 BE[3A0C]            <1>  mov si, %1
    38 00000218 B30B                <1>  mov bl, %2
    39 0000021A 30FF                <1>  xor bh, bh
    40 0000021C B40E                <1>  mov ah, 0Eh
    41 0000021E E8C3FF              <1>  call p_msg
   552                                  	;call	write_audio_dev_info
   553                                  	;retn
   554 00000221 E95C03                  	jmp	write_audio_dev_info
   555                                  
   556                                  ; -------------------------------------------------------------
   557                                  
   558                                  	; 01/01/2025 (16bit pop)
   559                                  	; 02/12/2024
   560                                  Player_Quit@:
   561 00000224 58                      	pop	ax ; return addr (call PlayWav@)
   562                                  	
   563                                  	; 29/11/2024
   564                                  Player_Quit:
   565                                  	;jmp	terminate
   566                                  	; 02/01/2025
   567 00000225 EB84                    	jmp	terminate@  ; reset hardware interrupt
   568                                  
   569                                  ; -------------------------------------------------------------
   570                                  
   571                                  	; 02/01/2025 (cgaplay2.asm) -SB16-
   572                                  	; 01/01/2025 (cgaplay.asm) -AC97-
   573                                  	; 20/12/2024 (sb16play.asm)
   574                                  PlayWav:
   575                                  	; 24/11/2024
   576 00000227 B8[E014]                	mov     ax, wav_buffer1
   577 0000022A E80803                  	call	loadFromFile
   578 0000022D A1[CE14]                	mov	ax, [count]
   579 00000230 0106[D014]              	add	[LoadedDataBytes], ax
   580 00000234 8316[D214]00            	adc	word [LoadedDataBytes+2], 0
   581                                  
   582 00000239 B8[026B]                	mov     ax, wav_buffer2
   583 0000023C E8F602                  	call	loadFromFile
   584 0000023F A1[CE14]                	mov	ax, [count]
   585 00000242 0106[D014]              	add	[LoadedDataBytes], ax
   586 00000246 8316[D214]00            	adc	word [LoadedDataBytes+2], 0
   587                                  
   588                                  	; 25/11/2024
   589 0000024B E88403                  	call	SB16Init_play	; initialize SB16 card
   590                                  				; set sample rate, start to play
   591 0000024E 0F827CFF                	jc	init_err
   592                                  
   593                                  	; 02/01/2025
   594                                  	; 27/11/2024
   595                                  	; set audio interrupt vector (to user's handler)
   596 00000252 A0[3214]                	mov	al, [IRQnum]
   597 00000255 B401                    	mov	ah, 1 ; set
   598 00000257 BA[2604]                	mov	dx, IRQ_service
   599 0000025A E84301                  	call	set_hardware_int_vector
   600                                  
   601                                  	; 26/11/2024
   602 0000025D E88007                  	call	check4keyboardstop
   603 00000260 7273                    	jc	_exitt_
   604                                  
   605                                  	; 27/11/2024
   606 00000262 C606[3214]00            	mov	byte [IRQnum], 0
   607                                  
   608                                  	; 02/01/2025
   609                                  
   610                                  ; -------------------------------------------
   611                                  
   612                                  	; 02/01/2025 (cgaplay2.asm) -SB16-
   613                                  	; 01/01/2025 (cgaplay.asm) -AC97-
   614                                  	; 20/12/2024 (sb16play.asm)
   615                                  	; ----------
   616                                  	; 29/11/2024
   617                                  	; 27/11/2024
   618                                  	; 24/11/2024
   619                                  TuneLoop: 
   620                                  	; 30/05/2024
   621                                  	; 18/11/2023 (ich_wav4.asm)
   622                                  	; 08/11/2023
   623                                  	; 06/11/2023
   624                                  tLWait:
   625                                  	; 18/11/2024
   626 00000267 803E[3514]00            	cmp	byte [stopped], 0
   627                                  	; 24/11/2024
   628 0000026C 7624                    	jna	short tL1
   629                                  tLWait@:	; 21/11/2024
   630 0000026E E87F04                  	call	checkUpdateEvents
   631 00000271 7262                    	jc	_exitt_
   632                                  	;;;
   633                                  	; 29/11/2024
   634 00000273 803E[3C14]4E            	cmp	byte [command], 'N'
   635 00000278 745B                    	je	_exitt_
   636 0000027A 803E[3C14]50            	cmp	byte [command], 'P'
   637 0000027F 7454                    	je	_exitt_
   638                                  	;;;
   639 00000281 803E[3614]30            	cmp	byte [tLO], '0'
   640 00000286 74DF                    	je	short tLWait
   641 00000288 E85000                  	call	tLZ
   642 0000028B C606[3614]30            	mov	byte [tLO], '0'
   643 00000290 EBD5                    	jmp	short tLWait
   644                                  tL1:
   645                                  	; 27/11/2024
   646                                  	; Check SB 16 interrupt status
   647 00000292 803E[3214]00            	cmp	byte [IRQnum], 0
   648 00000297 7707                    	ja	short tL3
   649                                  tL2:
   650 00000299 E85404                  	call	checkUpdateEvents
   651 0000029C 7237                    	jc	_exitt_
   652 0000029E EBC7                    	jmp	short tLWait
   653                                  tL3:
   654 000002A0 8036[A411]01            	xor	byte [half_buffer], 1
   655                                  
   656 000002A5 C606[3214]00            	mov	byte [IRQnum], 0
   657                                  
   658                                  	; load buffer 1
   659                                  	;mov	ax, wav_buffer1
   660 000002AA B8[E014]                	mov     ax, dma_buffer  ; wav_buffer1
   661 000002AD 803E[A411]00            	cmp	byte [half_buffer], 0
   662 000002B2 7603                    	jna	short tL4
   663                                  
   664                                  	; load buffer 2
   665                                  	;mov	ax, wav_buffer2
   666 000002B4 052256                  	add     ax, LOADSIZE ; dma_buffer_size/2
   667                                  tL4:
   668 000002B7 E87B02                  	call	loadFromFile
   669 000002BA 7219                    	jc	short _exitt_	; end of file
   670                                  
   671                                  	; 26/11/2024
   672 000002BC A0[A411]                	mov	al, [half_buffer]
   673 000002BF 0431                    	add	al, '1'
   674                                  	; 19/11/2024
   675 000002C1 A2[3614]                	mov	[tLO], al
   676 000002C4 E81600                  	call	tL0
   677                                  	; 24/11/2024
   678                                  	; 14/11/2024
   679 000002C7 A1[CE14]                	mov	ax, [count]
   680 000002CA 0106[D014]              	add	[LoadedDataBytes], ax
   681 000002CE 8316[D214]00            	adc	word [LoadedDataBytes+2], 0
   682                                  
   683                                  	; 27/11/2024
   684 000002D3 EBC4                    	jmp	short tL2
   685                                  
   686                                  _exitt_:
   687                                  	; 24/11/2024
   688 000002D5 E87101                  	call	sb16_stop
   689                                  
   690                                  	;;;
   691                                  	; 14/11/2024
   692 000002D8 E88808                  	call	UpdateProgressBar
   693                                  	;;;
   694                                  
   695                                  	; 18/11/2024
   696                                  tLZ:
   697                                  	; 30/05/2024
   698 000002DB B030                    	mov	al, '0'
   699                                  tL0:
   700                                  	; 01/01/2025 (cgaplay.asm)
   701                                  	; 31/12/2024
   702 000002DD 50                      	push	ax
   703 000002DE 31D2                    	xor	dx, dx ; row 0, column 0
   704 000002E0 E85307                  	call	setCursorPosition
   705 000002E3 58                      	pop	ax
   706                                  	;
   707 000002E4 B40E                    	mov	ah, 0Eh
   708 000002E6 BB0E00                  	mov	bx, 0Eh
   709 000002E9 CD10                    	int	10h
   710                                  	
   711 000002EB C3                      	retn
   712                                  
   713                                  ; -------------------------------------------
   714                                  
   715                                  	; 02/01/2025
   716                                  SetMasterVolume:
   717 000002EC A2[350A]                	mov	[volume], al  ; max = 15, min = 0
   718                                  	; 02/01/2025
   719                                  	; 24/11/2024
   720                                  SetMasterVolume@:
   721                                  	; al = sound volume (15 = max, 0 = min)
   722 000002EF 50                      	push	ax
   723                                  	; Tell the SB 16 card which register to write
   724 000002F0 8B16[C614]              	mov	dx, [audio_io_base]
   725                                  	;add	dx, 4 ; Mixer chip address port
   726 000002F4 80C204                  	add	dl, 4
   727 000002F7 B022                    	mov	al, 22h
   728 000002F9 EE                      	out	dx, al
   729 000002FA 58                      	pop	ax
   730                                  	;and	al, 0Fh
   731                                  	; Set the volume for both L and R
   732 000002FB B311                    	mov	bl, 11h
   733 000002FD F6E3                    	mul	bl
   734                                  	; Set new volume
   735 000002FF 8B16[C614]              	mov	dx, [audio_io_base]
   736                                  	;add	dx, 5
   737 00000303 80C205                  	add	dl, 5
   738 00000306 EE                      	out	dx, al
   739 00000307 C3                      	retn
   740                                  
   741                                  ; -------------------------------------------
   742                                  	; 24/11/2024
   743                                  	; Ref: TRDOS 386 Kernel v2.0.9 audio.s (06/06/2024)
   744                                  	;      DetectSB procedure (06/08/2022, v2.0.5)	 
   745                                  DetectSB16:
   746                                  	; 06/08/2022 - TRDOS 386 v2.0.5
   747                                  	; 24/04/2017
   748                                  ScanPort:
   749 00000308 BB1002                  	mov	bx, 0210h	; start scanning ports
   750                                  				; 210h, 220h, .. 260h
   751                                  ResetDSP:       
   752                                  	; 26/11/2024
   753 0000030B 89DA                    	mov	dx, bx		; try to reset the DSP.
   754 0000030D 80C206                  	add	dl, 06h
   755                                  
   756 00000310 B001                    	mov	al, 1
   757 00000312 EE                      	out	dx, al
   758                                  
   759 00000313 EC                      	in	al, dx
   760 00000314 EC                      	in	al, dx
   761 00000315 EC                      	in	al, dx
   762 00000316 EC                      	in	al, dx
   763                                  
   764 00000317 30C0                    	xor     al, al
   765 00000319 EE                      	out	dx, al
   766                                  
   767                                  	;add	dx, 08h
   768 0000031A 80C208                  	add	dl, 08h
   769 0000031D B96400                  	mov	cx, 100
   770                                  WaitID:
   771 00000320 EC                      	in	al, dx
   772 00000321 08C0                    	or      al, al
   773 00000323 7804                    	js      short GetID
   774 00000325 E2F9                    	loop    WaitID
   775 00000327 EB0D                    	jmp     short NextPort
   776                                  GetID:          
   777                                  	;sub	dx, 04h
   778 00000329 80EA04                  	sub	dl, 04h
   779 0000032C EC                      	in	al, dx
   780 0000032D 3CAA                    	cmp     al, 0AAh
   781 0000032F 740F                    	je      short Found
   782                                  	;add	dx, 04h
   783 00000331 80C204                  	add	dl, 04h
   784 00000334 E2EA                    	loop    WaitID
   785                                  NextPort:
   786                                  	;add	bx, 10h		; if not response,
   787 00000336 80C310                  	add	bl, 10h
   788                                  	;cmp	bx, 260h	; try the next port.
   789 00000339 80FB60                  	cmp	bl, 60h
   790 0000033C 76CD                    	jbe     short ResetDSP
   791 0000033E F9                      	stc
   792 0000033F C3                      	retn
   793                                  Found:
   794 00000340 891E[C614]              	mov     [audio_io_base], bx ; SB Port Address Found!
   795                                  ScanIRQ:
   796                                  SetIrqs:
   797 00000344 28C0                    	sub 	al, al ; 0
   798 00000346 A2[3214]                	mov 	[IRQnum], al ; reset
   799                                  	; 27/11/2024
   800                                  	;mov	[audio_intr], al
   801                                  
   802                                  	; 25/11/2024
   803                                  	; save IRQ status
   804 00000349 E421                    	in      al, 21h		; save the IMR.
   805 0000034B A2[3414]                	mov	[IRQstatus], al
   806                                  
   807                                  	; ah > 0 -> set IRQ vector
   808                                  	; al = IRQ number
   809 0000034E B80501                  	mov	ax, 105h ; IRQ 5
   810                                  	; 26/11/2024
   811 00000351 BA[1804]                	mov	dx, IRQ5_service
   812 00000354 E84900                  	call	set_hardware_int_vector
   813 00000357 B80701                  	mov	ax, 107h ; IRQ 7
   814                                  	; 26/11/2024
   815 0000035A BA[1F04]                	mov	dx, IRQ7_service
   816 0000035D E84000                  	call	set_hardware_int_vector
   817                                  
   818 00000360 8B16[C614]              	mov     dx, [audio_io_base] ; tells to the SB to
   819                                  	;add	dx, 0Ch		    ; generate a IRQ!
   820 00000364 80C20C                  	add	dl, 0Ch
   821                                  WaitSb:
   822 00000367 EC                      	in	al, dx
   823 00000368 08C0                    	or      al, al
   824 0000036A 78FB                    	js      short WaitSb
   825 0000036C B0F2                    	mov     al, 0F2h
   826 0000036E EE                      	out	dx, al
   827                                  	; 24/11/2024
   828 0000036F 31C9                    	xor     cx, cx	; wait until IRQ level
   829                                  WaitIRQ: 
   830 00000371 A0[3214]                	mov	al, [IRQnum]
   831 00000374 3C00                    	cmp     al, 0 ; is changed or timeout.
   832 00000376 7705                    	ja	short IrqOk
   833 00000378 49                      	dec	cx
   834 00000379 75F6                    	jnz	short WaitIRQ
   835 0000037B EB11                    	jmp	short RestoreIrqs
   836                                  IrqOk:
   837                                  	;;;
   838                                  	; 27/11/2024
   839 0000037D A2[3314]                	mov	[audio_intr], al
   840 00000380 8B16[C614]              	mov 	dx, [audio_io_base]
   841                                  	;add	dx, 0Eh
   842 00000384 80C20E                  	add	dl, 0Eh ; 8bit DMA-mode int ack
   843 00000387 EC                      	in	al, dx	; SB acknowledge.
   844 00000388 42                      	inc	dx ; 0Fh ; 16bit DMA-mode int ack
   845 00000389 EC                      	in	al, dx	; SB 16 acknowledge.
   846                                  	;;;
   847 0000038A B020                    	mov	al, 20h
   848 0000038C E620                    	out	20h, al	; Hardware acknowledge.
   849                                  RestoreIrqs:
   850                                  	; ah = 0 -> reset IRQ vector
   851                                  	; al = IRQ number
   852 0000038E B80500                  	mov	ax, 5 ; IRQ 5
   853 00000391 E80C00                  	call	set_hardware_int_vector
   854 00000394 B80700                  	mov	ax, 7 ; IRQ 7
   855 00000397 E80600                  	call	set_hardware_int_vector
   856                                  
   857 0000039A 803E[3214]01            	cmp     byte [IRQnum], 1 ; IRQ level was changed?
   858                                  	
   859 0000039F C3                      	retn
   860                                  
   861                                  ; ----------------------------------
   862                                  
   863                                  	; 24/11/2024
   864                                  set_hardware_int_vector:
   865 000003A0 08E4                    	or	ah, ah
   866 000003A2 753F                    	jnz	short shintv_1 ; set user's audio interrupt handler
   867                                  
   868                                  rhintv_1:		
   869                                  	; reset the interrupt vector to the old interrupt handler
   870 000003A4 1E                      	push	ds
   871 000003A5 3C05                    	cmp	al, 5
   872 000003A7 751D                    	jne	short rhintv_2
   873                                  
   874                                  	; 25/11/2024
   875                                  	; restore IRQ 5 status
   876 000003A9 8A26[3414]              	mov	ah, [IRQstatus]
   877 000003AD E421                    	in	al, 21h
   878 000003AF 80E420                  	and	ah, 00100000b ; 20h
   879 000003B2 08E0                    	or	al, ah
   880 000003B4 E621                    	out     21h, al
   881                                  
   882 000003B6 8B16[2A14]              	mov	dx, [old_irq5v_o]
   883 000003BA 8E1E[2C14]              	mov	ds, [old_irq5v_s]
   884                                  shintv_3:
   885 000003BE B00D                    	mov	al, 0Dh
   886 000003C0 B425                    	mov	ah, 25h
   887 000003C2 CD21                    	int	21h
   888 000003C4 1F                      	pop	ds
   889 000003C5 C3                      	retn
   890                                  
   891                                  rhintv_2:
   892                                  	; 25/11/2024
   893                                  	; restore IRQ 7 status
   894 000003C6 8A26[3414]              	mov	ah, [IRQstatus]
   895 000003CA E421                    	in	al, 21h
   896 000003CC 80E480                  	and	ah, 10000000b ; 80h
   897 000003CF 08E0                    	or	al, ah
   898 000003D1 E621                    	out     21h, al
   899                                  
   900 000003D3 8B16[2E14]              	mov	dx, [old_irq7v_o]
   901 000003D7 8E1E[3014]              	mov	ds, [old_irq7v_s]
   902                                  shintv_4:
   903 000003DB B00F                    	mov	al, 0Fh
   904 000003DD B425                    	mov	ah, 25h
   905 000003DF CD21                    	int	21h
   906 000003E1 1F                      	pop	ds
   907 000003E2 C3                      	retn
   908                                  
   909                                  shintv_1:
   910 000003E3 06                      	push	es
   911                                  
   912 000003E4 3C05                    	cmp	al, 5
   913 000003E6 7518                    	jne	short shintv_2
   914                                  
   915                                  	; INT 0Dh = IRQ 5 (default) interrupt number
   916                                  
   917                                  	; 25/11/2024
   918                                  	; enable IRQ 5
   919                                  	; 26/11/2024
   920 000003E8 E421                    	in	al, 21h
   921 000003EA 24DF                    	and	al, 11011111b
   922 000003EC E621                    	out     21h, al
   923                                  
   924 000003EE B00F                    	mov	al, 0Fh
   925 000003F0 B435                    	mov	ah, 35h	; Get Interrupt Vector 
   926 000003F2 CD21                    	int	21h
   927 000003F4 8C06[2C14]              	mov	[old_irq5v_s], es
   928 000003F8 891E[2A14]              	mov	[old_irq5v_o], bx
   929 000003FC 07                      	pop	es
   930 000003FD 1E                      	push	ds
   931                                  	; 27/11/2024
   932                                  	;mov	dx, IRQ5_service
   933 000003FE EBBE                    	jmp	short shintv_3
   934                                  
   935                                  shintv_2:	
   936                                  	; al = 7
   937                                  	; INT 0Fh = IRQ 7 (default) interrupt number
   938                                  
   939                                  	; 25/11/2024
   940                                  	; enable IRQ 7
   941                                  	; 26/11/2024
   942 00000400 E421                    	in	al, 21h
   943 00000402 247F                    	and	al, 01111111b
   944 00000404 E621                    	out     21h, al
   945                                  	
   946 00000406 B00F                    	mov	al, 0Fh
   947 00000408 B435                    	mov	ah, 35h	; Get Interrupt Vector 
   948 0000040A CD21                    	int	21h
   949 0000040C 8C06[3014]              	mov	[old_irq7v_s], es
   950 00000410 891E[2E14]              	mov	[old_irq7v_o], bx
   951 00000414 07                      	pop	es
   952 00000415 1E                      	push	ds
   953                                  	; 27/11/2024
   954                                  	;mov	dx, IRQ7_service
   955 00000416 EBC3                    	jmp	short shintv_4
   956                                  
   957                                  IRQ5_service:
   958 00000418 2EC606[3214]05          	mov	byte [cs:IRQnum], 5
   959 0000041E CF                      	iret
   960                                  
   961                                  IRQ7_service:
   962 0000041F 2EC606[3214]07          	mov	byte [cs:IRQnum], 7
   963 00000425 CF                      	iret
   964                                  
   965                                  	; 27/11/2024
   966                                  IRQ_service:
   967 00000426 1E                      	push	ds
   968 00000427 52                      	push	dx
   969 00000428 50                      	push	ax
   970                                  	;
   971 00000429 0E                      	push	cs
   972 0000042A 1F                      	pop	ds
   973 0000042B C606[3214]05            	mov	byte [IRQnum], 5
   974 00000430 8B16[C614]              	mov     dx, [audio_io_base]
   975                                  	;add	dx, 0Eh
   976 00000434 80C20E                  	add	dl, 0Eh ; 8bit DMA-mode int ack
   977 00000437 803E[6214]08            	cmp	byte [WAVE_BitsPerSample], 8
   978 0000043C 7602                    	jna	short irq_ack_@
   979 0000043E FEC2                    	inc	dl ; 0Fh ; 16bit DMA-mode int ack
   980                                  irq_ack_@:
   981 00000440 EC                      	in	al, dx	; SB acknowledge.
   982                                  	;
   983 00000441 B020                    	mov	al, 20h
   984 00000443 E620                    	out	20h, al	; Hardware acknowledge
   985                                  	;
   986 00000445 58                      	pop	ax
   987 00000446 5A                      	pop	dx
   988 00000447 1F                      	pop	ds
   989 00000448 CF                      	iret
   990                                  
   991                                  ; ----------------------------------
   992                                  
   993                                  	; 02/01/2025
   994                                  	; 24/11/2024
   995                                  	; Ref: TRDOS 386 Kernel v2.0.9 audio.s (06/06/2024)
   996                                  	;      sb16_stop procedure (06/08/2022, v2.0.5)	
   997                                  sb16_stop:
   998                                  	; 02/01/2025
   999 00000449 C606[3514]02            	mov	byte [stopped], 2
  1000                                  	;
  1001 0000044E 8B16[C614]              	mov	dx, [audio_io_base]
  1002                                  	;add	dx, 0Ch
  1003 00000452 80C20C                  	add	dl, 0Ch
  1004                                  
  1005 00000455 B3D9                    	mov	bl, 0D9h ; exit auto-initialize 16 bit transfer
  1006                                  	; stop  autoinitialized DMA transfer mode 
  1007 00000457 803E[6214]10            	cmp	byte [WAVE_BitsPerSample], 16 ; 16 bit samples
  1008 0000045C 7402                    	je	short sb16_stop_1
  1009                                  	;mov	bl, 0DAh ; exit auto-initialize 8 bit transfer
  1010 0000045E FEC3                    	inc	bl
  1011                                  sb16_stop_1:
  1012                                  	SbOut	bl ; exit auto-initialize transfer command
    46                              <1> %%wait:
    47 00000460 EC                  <1>  in al, dx
    48 00000461 08C0                <1>  or al, al
    49 00000463 78FB                <1>  js short %%wait
    50 00000465 88D8                <1>  mov al, %1
    51 00000467 EE                  <1>  out dx, al
  1013                                  
  1014 00000468 30C0                    	xor     al, al ; stops all DMA processes on selected channel
  1015                                  
  1016 0000046A 803E[6214]10            	cmp	byte [WAVE_BitsPerSample], 16 ; 16 bit samples
  1017 0000046F 7404                    	je	short sb16_stop_2
  1018 00000471 E60C                    	out	0Ch, al ; clear selected channel register
  1019 00000473 EB02                    	jmp	short sb16_stop_3
  1020                                  
  1021                                  sb16_stop_2:
  1022 00000475 E6D8                    	out	0D8h, al ; clear selected channel register
  1023                                  
  1024                                  sb16_stop_3:
  1025                                  	; 24/11/2024
  1026 00000477 C606[3514]02            	mov	byte [stopped], 2 ; stop !
  1027                                  SbDone:
  1028                                  	;mov	dx, [audio_io_base]
  1029                                  	;add	dx, 0Ch
  1030                                  	SbOut   0D0h
    46                              <1> %%wait:
    47 0000047C EC                  <1>  in al, dx
    48 0000047D 08C0                <1>  or al, al
    49 0000047F 78FB                <1>  js short %%wait
    50 00000481 B0D0                <1>  mov al, %1
    51 00000483 EE                  <1>  out dx, al
  1031                                  	SbOut   0D3h
    46                              <1> %%wait:
    47 00000484 EC                  <1>  in al, dx
    48 00000485 08C0                <1>  or al, al
    49 00000487 78FB                <1>  js short %%wait
    50 00000489 B0D3                <1>  mov al, %1
    51 0000048B EE                  <1>  out dx, al
  1032                                  sb16_stop_4:
  1033 0000048C C3                      	retn
  1034                                  
  1035                                  ; ----------------------------------
  1036                                  
  1037                                  	; 02/01/2025
  1038                                  	; 24/11/2024
  1039                                  	; Ref: TRDOS 386 Kernel v2.0.9 audio.s (06/06/2024)
  1040                                  	;      sb16_pause procedure (06/08/2022, v2.0.5)	
  1041                                  sb16_pause:
  1042                                  	; 02/01/2025
  1043 0000048D C606[3514]01            	mov	byte [stopped], 1 ; paused
  1044                                  	;
  1045 00000492 8B16[C614]              	mov	dx, [audio_io_base]
  1046                                  	;add	dx, 0Ch ; Command & Data Port
  1047 00000496 80C20C                  	add	dl, 0Ch
  1048 00000499 803E[6214]10            	cmp	byte [WAVE_BitsPerSample], 16 ; 16 bit samples
  1049 0000049E 7404                    	je	short sb_pause_1
  1050                                  	; 8 bit samples
  1051 000004A0 B3D0                    	mov	bl, 0D0h ; 8 bit DMA mode
  1052 000004A2 EB02                    	jmp	short sb_pause_2
  1053                                  sb_pause_1:
  1054                                  	; 16 bit samples
  1055 000004A4 B3D5                    	mov	bl, 0D5h ; 16 bit DMA mode
  1056                                  sb_pause_2:
  1057                                  	SbOut   bl ; bCommand
    46                              <1> %%wait:
    47 000004A6 EC                  <1>  in al, dx
    48 000004A7 08C0                <1>  or al, al
    49 000004A9 78FB                <1>  js short %%wait
    50 000004AB 88D8                <1>  mov al, %1
    51 000004AD EE                  <1>  out dx, al
  1058                                  sb_pause_3:
  1059 000004AE C3                      	retn
  1060                                  
  1061                                  ; ----------------------------------
  1062                                  
  1063                                  	; 02/01/2025
  1064                                  	; 24/11/2024
  1065                                  	; Ref: TRDOS 386 Kernel v2.0.9 audio.s (06/06/2024)
  1066                                  	;      sb16_continue procedure (06/08/2022, v2.0.5)
  1067                                  sb16_play:
  1068                                  sb16_continue:
  1069                                  	; 02/01/2025
  1070                                  	; continue to play (after pause)
  1071 000004AF C606[3514]00            	mov	byte [stopped], 0
  1072                                  	;
  1073 000004B4 8B16[C614]              	mov	dx, [audio_io_base]
  1074                                  	;add	dx, 0Ch ; Command & Data Port
  1075 000004B8 80C20C                  	add	dl, 0Ch
  1076 000004BB 803E[6214]10            	cmp	byte [WAVE_BitsPerSample], 16 ; 16 bit samples
  1077 000004C0 7404                    	je	short sb_cont_1
  1078                                  	; 8 bit samples
  1079 000004C2 B3D4                    	mov	bl, 0D4h ; 8 bit DMA mode
  1080 000004C4 EB02                    	jmp	short sb_cont_2
  1081                                  sb_cont_1:
  1082                                  	; 16 bit samples
  1083 000004C6 B3D6                    	mov	bl, 0D6h ; 16 bit DMA mode
  1084                                  sb_cont_2:     
  1085                                  	SbOut   bl ; bCommand
    46                              <1> %%wait:
    47 000004C8 EC                  <1>  in al, dx
    48 000004C9 08C0                <1>  or al, al
    49 000004CB 78FB                <1>  js short %%wait
    50 000004CD 88D8                <1>  mov al, %1
    51 000004CF EE                  <1>  out dx, al
  1086                                  sb_cont_3:
  1087 000004D0 C3                      	retn
  1088                                  
  1089                                  ; ----------------------------------
  1090                                  
  1091                                  	; 14/11/2024
  1092                                  	; INPUT: ds:dx = file name address
  1093                                  	; OUTPUT: [filehandle] = ; -1 = not open
  1094                                  openFile:
  1095 000004D1 B8003D                  	mov	ax, 3D00h	; open File for read
  1096 000004D4 CD21                    	int	21h
  1097 000004D6 7303                    	jnc	short _of1
  1098 000004D8 B8FFFF                  	mov	ax, -1
  1099                                  	; cf = 1 -> not found or access error
  1100                                  _of1:
  1101 000004DB A3[6E14]                	mov	[filehandle], ax
  1102 000004DE C3                      	retn
  1103                                  
  1104                                  ; ----------------------------------
  1105                                  
  1106                                  ; close the currently open file
  1107                                  
  1108                                  	; 14/11/2024
  1109                                  	; INPUT: [filehandle] ; -1 = not open
  1110                                  	; OUTPUT: none
  1111                                  closeFile:
  1112 000004DF 833E[6E14]FF            	cmp	word [filehandle], -1
  1113 000004E4 7409                    	jz	short _cf1
  1114 000004E6 8B1E[6E14]              	mov     bx, [filehandle]
  1115 000004EA B8003E                  	mov     ax, 3E00h
  1116 000004ED CD21                            int     21h              ; close file
  1117                                  _cf1:
  1118 000004EF C3                      	retn
  1119                                  
  1120                                  ; ----------------------------------
  1121                                  
  1122                                  	; 04/02/2025
  1123                                  	; 14/11/2024 - Erdogan Tan
  1124                                  getWAVParameters:
  1125                                  ; reads WAV file header(s) (44 bytes) from the .wav file.
  1126                                  ; entry: none - assumes file is already open
  1127                                  ; exit: ax = sample rate (11025, 22050, 44100, 48000)
  1128                                  ;	cx = number of channels (mono=1, stereo=2)
  1129                                  ;	dx = bits per sample (8, 16)
  1130                                  ;	bx = number of bytes per sample (1 to 4)
  1131                                  
  1132 000004F0 BA[4014]                        mov     dx, WAVFILEHEADERbuff
  1133 000004F3 8B1E[6E14]              	mov	bx, [filehandle]
  1134 000004F7 B92C00                          mov     cx, 44			; 44 bytes
  1135 000004FA B43F                    	mov	ah, 3Fh
  1136 000004FC CD21                            int     21h
  1137 000004FE 7223                    	jc	short gwavp_retn
  1138                                  
  1139 00000500 83F82C                  	cmp	ax, 44
  1140 00000503 721E                    	jb	short gwavp_retn
  1141                                  
  1142 00000505 66813E[4814]574156-     	cmp	dword [RIFF_Format], 'WAVE'
  1142 0000050D 45                 
  1143 0000050E 7512                    	jne	short gwavp_stc_retn
  1144                                  
  1145 00000510 833E[5414]01            	cmp	word [WAVE_AudioFormat], 1 ; Offset 20, must be 1 (= PCM)
  1146                                  	; 04/02/2025
  1147 00000515 750B                    	jne	short gwavp_stc_retn
  1148                                  	;je	short gwavp_retn ; 15/11/2024
  1149                                  
  1150                                  	; 04/02/2025
  1151                                  	; (Open MPT creates wav files with a new type header,
  1152                                  	;  this program can not use the new type
  1153                                  	;  because of 'data' offset is not at DATA_SubchunkID.)
  1154                                  	; ((GoldWave creates common type wav file.))
  1155 00000517 66813E[6414]646174-     	cmp	dword [DATA_SubchunkID], 'data'
  1155 0000051F 61                 
  1156 00000520 7401                    	je	short gwavp_retn
  1157                                  
  1158                                  	; 15/11/2024
  1159                                  	;mov	cx, [WAVE_NumChannels]	; return num of channels in CX
  1160                                          ;mov    ax, [WAVE_SampleRate]	; return sample rate in AX
  1161                                  	;mov	dx, [WAVE_BitsPerSample] 
  1162                                  					; return bits per sample value in DX
  1163                                  	;mov	bx, [WAVE_BlockAlign]	; return bytes per sample in BX
  1164                                  ;gwavp_retn:
  1165                                          ;retn
  1166                                  
  1167                                  gwavp_stc_retn:
  1168 00000522 F9                      	stc
  1169                                  gwavp_retn:
  1170 00000523 C3                      	retn
  1171                                  
  1172                                  ; --------------------------------------------------------
  1173                                  ; ----	30/05/2024 (playwav4.asm, 19/05/2024)
  1174                                  ; --------------------------------------------------------
  1175                                  
  1176                                  ; MEMALLOC.ASM
  1177                                  ;-- SETFREE: Release memory not used  --------------------
  1178                                  ;-- Input    : ES = address of PSP
  1179                                  ;-- Output   : none
  1180                                  ;-- Register : AX, BX, CL and FLAGS are changed 
  1181                                  ;-- Info     : Since the stack-segment is always the last segment in an 
  1182                                  ;              EXE-file, ES:0000 points to the beginning and SS:SP
  1183                                  ;              to the end of the program in memory. Through this the
  1184                                  ;              length of the program can be calculated 
  1185                                  ; call this routine once at the beginning of the program to free up memory
  1186                                  ; assigned to it by DOS.
  1187                                  
  1188                                  setFree:
  1189 00000524 BB0010                  	mov	bx, 65536/16	; 4K paragraphs ; 17/02/2017 (Erdogan Tan)		
  1190                                  
  1191 00000527 B44A                    	mov	ah, 4Ah		; pass new length to DOS
  1192 00000529 CD21                    	int	21h
  1193                                  
  1194 0000052B C3                      	retn			; back to caller 
  1195                                  				; new size (allocated memory) = 64KB
  1196                                  
  1197                                  ; --------------------------------------------------------
  1198                                  
  1199                                  memAlloc:
  1200                                  ; input: AX = # of paragraphs required
  1201                                  ; output: AX = segment of block to use
  1202                                  
  1203 0000052C 53                      	push	bx
  1204 0000052D 89C3                    	mov	bx, ax
  1205 0000052F B448                    	mov	ah, 48h
  1206 00000531 CD21                    	int	21h
  1207 00000533 5B                      	pop	bx
  1208 00000534 C3                      	retn
  1209                                  
  1210                                  ; --------------------------------------------------------
  1211                                  ; 02/01/2025
  1212                                  ; --------------------------------------------------------
  1213                                  
  1214                                  ; /////
  1215                                  	; 24/11/2024 (SB16 version of playwav8.asm -> playwav9.asm)
  1216                                  	; 30/05/2024 (ich_wav4.asm, 19/05/2024)
  1217                                  loadFromFile:
  1218                                  	; 18/12/2024
  1219 00000535 C706[CE14]0000          	mov	word [count], 0
  1220                                  
  1221                                  	; 07/11/2023
  1222 0000053B F606[6C14]01                    test    byte [flags], ENDOFFILE	; have we already read the
  1223                                  					; last of the file?
  1224 00000540 7402                    	jz	short lff_0		; no
  1225 00000542 F9                      	stc
  1226 00000543 C3                      	retn
  1227                                  
  1228                                  lff_0:
  1229                                  	; 24/11/2024
  1230                                  	; 08/11/2023
  1231 00000544 89C7                    	mov	di, ax ; save buffer address
  1232                                  	; 17/11/2024
  1233 00000546 8B1E[6E14]              	mov	bx, [filehandle]
  1234                                  
  1235                                  	; 24/11/2024
  1236 0000054A B92256                  	mov	cx, LOADSIZE
  1237 0000054D 89C2                    	mov	dx, ax ; buffer address
  1238                                  
  1239                                  	; 24/11/2024
  1240                                  	; load/read file
  1241                                  	; bx = file handle
  1242                                  	; ds = cs
  1243                                  	; ds:dx = buffer
  1244                                  	; cx = read count
  1245 0000054F B43F                           	mov	ah, 3Fh
  1246 00000551 CD21                    	int	21h
  1247 00000553 7212                    	jc	short lff_4 ; error !
  1248                                  
  1249                                  	; 14/11/2024
  1250 00000555 A3[CE14]                	mov	[count], ax
  1251                                  
  1252 00000558 39C8                    	cmp	ax, cx
  1253 0000055A 740A                    	je	short endLFF
  1254                                  	; 24/11/2024
  1255                                  	; di = buffer address
  1256 0000055C 01C7                    	add	di, ax
  1257                                  lff_3:
  1258 0000055E E80F00                  	call    padfill			; blank pad the remainder
  1259                                          ;clc				; don't exit with CY yet.
  1260 00000561 800E[6C14]01                    or	byte [flags], ENDOFFILE	; end of file flag
  1261                                  endLFF:
  1262 00000566 C3                              retn
  1263                                  lff_4:
  1264                                  	; 08/11/2023
  1265 00000567 B021                    	mov	al, '!'  ; error
  1266 00000569 E871FD                  	call	tL0
  1267                                  
  1268 0000056C 31C0                    	xor	ax, ax
  1269 0000056E EBEE                    	jmp	short lff_3
  1270                                  
  1271                                  ; entry ds:ax points to last byte in file
  1272                                  ; cx = target size
  1273                                  ; note: must do byte size fill
  1274                                  ; destroys bx, cx
  1275                                  ;
  1276                                  padfill:
  1277                                  	; 24/11/2024
  1278                                  	;   di = offset (to be filled with ZEROs)
  1279                                  	;   es = ds = cs
  1280                                  	;   ax = di = number of bytes loaded
  1281                                  	;   cx = buffer size (> loaded bytes)
  1282 00000570 29C1                    	sub	cx, ax
  1283 00000572 31C0                    	xor	ax, ax
  1284 00000574 803E[6214]08            	cmp	byte [WAVE_BitsPerSample], 8
  1285 00000579 7702                    	ja	short padfill@
  1286 0000057B B080                    	mov	al, 80h
  1287                                  padfill@:
  1288 0000057D F3AA                    	rep	stosb
  1289 0000057F C3                      	retn
  1290                                  ; /////
  1291                                  	
  1292                                  write_audio_dev_info:
  1293                                  	; 30/05/2024
  1294                                       	sys_msg msgAudioCardInfo, 0Fh
    37 00000580 BE[9F0C]            <1>  mov si, %1
    38 00000583 B30F                <1>  mov bl, %2
    39 00000585 30FF                <1>  xor bh, bh
    40 00000587 B40E                <1>  mov ah, 0Eh
    41 00000589 E858FC              <1>  call p_msg
  1295 0000058C C3                      	retn
  1296                                  
  1297                                  	; 02/01/2025
  1298                                  write_sb16_dev_info:
  1299                                  	; 24/11/2024
  1300 0000058D A1[C614]                	mov	ax, [audio_io_base]
  1301 00000590 88C3                    	mov	bl, al
  1302 00000592 88DA                    	mov	dl, bl
  1303 00000594 80E30F                  	and	bl, 0Fh
  1304 00000597 8A87[790D]              	mov	al, [bx+hex_chars]
  1305 0000059B A2[C20D]                	mov	[msgBasePort+2], al
  1306 0000059E 88D3                    	mov	bl, dl
  1307 000005A0 C0EB04                  	shr	bl, 4
  1308 000005A3 8A87[790D]              	mov	al, [bx+hex_chars]
  1309 000005A7 A2[C10D]                	mov	[msgBasePort+1], al
  1310 000005AA 88E3                    	mov	bl, ah
  1311                                  	; 20/12/2024
  1312                                  	;mov	dl, bl
  1313                                  	;and	bl, 0Fh
  1314 000005AC 8A87[790D]              	mov	al, [bx+hex_chars]
  1315 000005B0 A2[C00D]                	mov	[msgBasePort], al
  1316                                  
  1317                                  	; 07/02/2025
  1318                                  	;xor	ax, ax
  1319                                  	;mov	al, [IRQnum]
  1320                                  	; 27/11/2024
  1321 000005B3 A0[3314]                	mov	al, [audio_intr]
  1322                                  	;mov	cl, 10
  1323                                  	;div	cl
  1324                                  	;add	ah, 30h
  1325                                  	;mov	[msgIRQ], ah
  1326                                  	; 25/11/2024
  1327 000005B6 0430                    	add	al, 30h
  1328 000005B8 A2[D70D]                	mov	[msgIRQ], al
  1329                                  
  1330 000005BB E86706                  	call 	clear_window
  1331                                  	;mov	dh, 13
  1332                                  	; 02/01/2025
  1333 000005BE B60C                    	mov	dh, 12
  1334 000005C0 B200                    	mov	dl, 0
  1335 000005C2 E87104                  	call	setCursorPosition
  1336                                  
  1337                                  	sys_msg msgSB16Info, 07h
    37 000005C5 BE[8A0D]            <1>  mov si, %1
    38 000005C8 B307                <1>  mov bl, %2
    39 000005CA 30FF                <1>  xor bh, bh
    40 000005CC B40E                <1>  mov ah, 0Eh
    41 000005CE E813FC              <1>  call p_msg
  1338                                  
  1339 000005D1 C3                      	retn
  1340                                  
  1341                                  ; --------------------------------------------------------
  1342                                  ; 24/11/2024 - Sound Blaster 16 initialization
  1343                                  ; --------------------------------------------------------
  1344                                  
  1345                                  	; 25/11/2024
  1346                                  	; 24/11/2024
  1347                                  	; Ref: TRDOS 386 Kernel v2.0.9, audio.s (06/06/2024)
  1348                                  	;      SbInit_play procedure (06/08/2022, v2.0.5)	 
  1349                                  SB16Init_play:
  1350 000005D2 8CD8                    	mov	ax, ds
  1351 000005D4 89C2                    	mov	dx, ax
  1352 000005D6 C1EA0C                  	shr	dx, 12
  1353 000005D9 C1E004                  	shl	ax, 4
  1354 000005DC 05[E014]                	add	ax, dma_buffer
  1355 000005DF 83D200                  	adc	dx, 0
  1356 000005E2 89C3                    	mov	bx, ax	; linear address
  1357                                  	; dx = page number
  1358                                  
  1359 000005E4 B944AC                  	mov     cx, dma_buffer_size
  1360                                  
  1361 000005E7 803E[6214]10            	cmp	byte [WAVE_BitsPerSample], 16
  1362 000005EC 7532                    	jne	short sbInit_0 ; set 8 bit DMA buffer
  1363                                  
  1364                                  	; 26/11/2024
  1365 000005EE 89D0                    	mov	ax, dx	; page number
  1366                                  	
  1367                                  	; convert byte count to word count
  1368                                  	; 26/11/2024
  1369                                  	;dec	cx
  1370 000005F0 D1E9                    	shr	cx, 1
  1371 000005F2 49                      	dec	cx	; word count - 1
  1372                                  
  1373                                  	; convert byte offset to word offset
  1374 000005F3 D1E8                    	shr	ax, 1
  1375 000005F5 D1DB                    	rcr	bx, 1
  1376                                  	; 26/11/2024
  1377                                  	;shr	bx, 1
  1378                                  
  1379                                  	; 16 bit DMA buffer setting (DMA channel 5)
  1380 000005F7 B005                    	mov	al, 05h  ; set mask bit for channel 5 (4+1)
  1381 000005F9 E6D4                    	out	0D4h, al
  1382                                  	
  1383 000005FB 30C0                    	xor	al, al   ; stops all DMA processes on selected channel
  1384 000005FD E6D8                    	out	0D8h, al ; clear selected channel register
  1385                                  
  1386 000005FF 88D8                    	mov	al, bl	 ; byte 0 of DMA buffer offset in words (physical)
  1387 00000601 E6C4                    	out	0C4h, al ; DMA channel 5 port number
  1388                                  
  1389 00000603 88F8                    	mov	al, bh   ; byte 1 of DMA buffer offset in words (physical)
  1390 00000605 E6C4                    	out	0C4h, al
  1391                                  	
  1392                                  	; 26/11/2024
  1393 00000607 80E2FE                  	and	dl, 0FEh ; clear bit 0 (not necessary, it will be ignored)
  1394                                  
  1395 0000060A 88D0                    	mov	al, dl   ; byte 2 of DMA buffer address (physical)
  1396 0000060C E68B                    	out	8Bh, al  ; page register port addr for channel 5
  1397                                  
  1398 0000060E 88C8                    	mov	al, cl   ; low byte of DMA count - 1
  1399 00000610 E6C6                    	out	0C6h, al ; count register port addr for channel 5
  1400                                  
  1401 00000612 88E8                    	mov	al, ch   ; high byte of DMA count - 1
  1402 00000614 E6C6                    	out	0C6h, al
  1403                                  
  1404                                  	; channel 5, read, autoinitialized, single mode
  1405 00000616 B059                    	mov	al, 59h
  1406 00000618 E6D6                    	out	0D6h, al ; DMA mode register port address
  1407                                  
  1408 0000061A B001                    	mov	al, 01h  ; clear mask bit for channel 5
  1409 0000061C E6D4                    	out	0D4h, al ; DMA mask register port address
  1410                                  
  1411 0000061E EB25                    	jmp	short ResetDsp
  1412                                  
  1413                                  sbInit_0:    
  1414 00000620 49                      	dec	cx	; byte count - 1
  1415                                  
  1416                                  	; 8 bit DMA buffer setting (DMA channel 1)
  1417 00000621 B005                    	mov	al, 05h ; set mask bit for channel 1 (4+1)
  1418 00000623 E60A                    	out	0Ah, al ; DMA mask register
  1419                                  
  1420 00000625 30C0                    	xor	al, al  ; stops all DMA processes on selected channel
  1421 00000627 E60C                    	out	0Ch, al ; clear selected channel register
  1422                                  
  1423 00000629 88D8                    	mov	al, bl	; byte 0 of DMA buffer address (physical)
  1424 0000062B E602                    	out	02h, al ; DMA channel 1 port number
  1425                                  
  1426 0000062D 88F8                    	mov	al, bh  ; byte 1 of DMA buffer address (physical)
  1427 0000062F E602                    	out	02h, al
  1428                                  
  1429 00000631 88D0                    	mov	al, dl  ; byte 2 of DMA buffer address (physical)
  1430 00000633 E683                    	out	83h, al ; page register port addr for channel 1
  1431                                  
  1432 00000635 88C8                    	mov	al, cl  ; low byte of DMA count - 1
  1433 00000637 E603                    	out	03h, al ; count register port addr for channel 1
  1434                                  
  1435 00000639 88E8                    	mov	al, ch  ; high byte of DMA count - 1
  1436 0000063B E603                    	out	03h, al
  1437                                  
  1438                                  	; channel 1, read, autoinitialized, single mode
  1439 0000063D B059                    	mov	al, 59h
  1440 0000063F E60B                    	out	0Bh, al ; DMA mode register port address
  1441                                  
  1442 00000641 B001                    	mov	al, 01h ; clear mask bit for channel 1
  1443 00000643 E60A                    	out	0Ah, al ; DMA mask register port address
  1444                                  
  1445                                  ResetDsp:
  1446 00000645 8B16[C614]              	mov	dx, [audio_io_base]
  1447                                  	;add	dx, 06h
  1448 00000649 80C206                  	add	dl, 06h
  1449 0000064C B001                    	mov	al, 1
  1450 0000064E EE                      	out	dx, al
  1451                                  
  1452 0000064F EC                      	in	al, dx
  1453 00000650 EC                      	in	al, dx
  1454 00000651 EC                      	in	al, dx
  1455 00000652 EC                      	in	al, dx
  1456                                  
  1457 00000653 31C0                    	xor	ax, ax
  1458 00000655 EE                      	out	dx, al
  1459                                  
  1460 00000656 B96400                  	mov	cx, 100
  1461                                  WaitId:         
  1462 00000659 8B16[C614]              	mov	dx, [audio_io_base]
  1463 0000065D 80C20E                  	add	dl, 0Eh
  1464 00000660 EC                      	in	al, dx
  1465 00000661 08C0                    	or	al, al
  1466                                  	;js	short sb_GetId
  1467                                  	; 26/11/2024
  1468 00000663 790C                    	jns	short sb_next
  1469                                  	;loop	WaitId
  1470                                  	;jmp	sb_Exit
  1471                                  
  1472                                  sb_GetId:
  1473 00000665 8B16[C614]              	mov	dx, [audio_io_base]
  1474                                  	;add	dx, 0Ah
  1475 00000669 80C20A                  	add	dl, 0Ah
  1476 0000066C EC                      	in	al, dx
  1477 0000066D 3CAA                    	cmp	al, 0AAh
  1478 0000066F 7404                    	je	short SbOk
  1479                                  sb_next:
  1480 00000671 E2E6                    	loop	WaitId
  1481 00000673 F9                      	stc
  1482 00000674 C3                      	retn
  1483                                  SbOk:
  1484 00000675 8B16[C614]              	mov	dx, [audio_io_base]
  1485                                  	;add	dx, 0Ch
  1486 00000679 80C20C                  	add	dl, 0Ch
  1487                                  	SbOut	0D1h	; Turn on speaker
    46                              <1> %%wait:
    47 0000067C EC                  <1>  in al, dx
    48 0000067D 08C0                <1>  or al, al
    49 0000067F 78FB                <1>  js short %%wait
    50 00000681 B0D1                <1>  mov al, %1
    51 00000683 EE                  <1>  out dx, al
  1488                                  	SbOut	41h	; 8 bit or 16 bit transfer
    46                              <1> %%wait:
    47 00000684 EC                  <1>  in al, dx
    48 00000685 08C0                <1>  or al, al
    49 00000687 78FB                <1>  js short %%wait
    50 00000689 B041                <1>  mov al, %1
    51 0000068B EE                  <1>  out dx, al
  1489 0000068C 8B1E[5814]              	mov	bx, [WAVE_SampleRate] ; sampling rate (Hz)
  1490                                  	SbOut	bh	; sampling rate high byte
    46                              <1> %%wait:
    47 00000690 EC                  <1>  in al, dx
    48 00000691 08C0                <1>  or al, al
    49 00000693 78FB                <1>  js short %%wait
    50 00000695 88F8                <1>  mov al, %1
    51 00000697 EE                  <1>  out dx, al
  1491                                  	SbOut	bl	; sampling rate low byte
    46                              <1> %%wait:
    47 00000698 EC                  <1>  in al, dx
    48 00000699 08C0                <1>  or al, al
    49 0000069B 78FB                <1>  js short %%wait
    50 0000069D 88D8                <1>  mov al, %1
    51 0000069F EE                  <1>  out dx, al
  1492                                  
  1493                                  	; 25/11/2024
  1494                                  
  1495                                  StartDMA: 
  1496                                  	; autoinitialized mode
  1497 000006A0 803E[6214]10            	cmp	byte [WAVE_BitsPerSample], 16 ; 16 bit samples
  1498 000006A5 740E                    	je	short sb_play_1
  1499                                  	; 8 bit samples
  1500 000006A7 BBC600                  	mov	bx, 0C6h ; 8 bit output (0C6h)
  1501 000006AA 803E[5614]02            	cmp	byte [WAVE_NumChannels], 2 ; 1 = mono, 2 = stereo
  1502 000006AF 7211                    	jb	short sb_play_2
  1503 000006B1 B720                    	mov	bh, 20h	; 8 bit stereo (20h)
  1504 000006B3 EB0D                    	jmp	short sb_play_2
  1505                                  sb_play_1:
  1506                                  	; 16 bit samples
  1507 000006B5 BBB610                  	mov	bx, 10B6h ; 16 bit output (0B6h)
  1508 000006B8 803E[5614]02            	cmp	byte [WAVE_NumChannels], 2 ; 1 = mono, 2 = stereo
  1509 000006BD 7203                    	jb	short sb_play_2
  1510 000006BF 80C720                  	add	bh, 20h	; 16 bit stereo (30h)
  1511                                  sb_play_2:     
  1512                                  	; PCM output (8/16 bit mono autoinitialized transfer)
  1513                                  	SbOut   bl	; bCommand
    46                              <1> %%wait:
    47 000006C2 EC                  <1>  in al, dx
    48 000006C3 08C0                <1>  or al, al
    49 000006C5 78FB                <1>  js short %%wait
    50 000006C7 88D8                <1>  mov al, %1
    51 000006C9 EE                  <1>  out dx, al
  1514                                  	SbOut	bh	; bMode
    46                              <1> %%wait:
    47 000006CA EC                  <1>  in al, dx
    48 000006CB 08C0                <1>  or al, al
    49 000006CD 78FB                <1>  js short %%wait
    50 000006CF 88F8                <1>  mov al, %1
    51 000006D1 EE                  <1>  out dx, al
  1515                                  	; 25/11/2024
  1516 000006D2 BB2256                  	mov	bx, dma_buffer_size/2
  1517                                  			; half buffer size
  1518 000006D5 803E[6214]10            	cmp	byte [WAVE_BitsPerSample], 16 ; 16 bit DMA
  1519 000006DA 7502                    	jne	short sb_play_3
  1520 000006DC D1EB                    	shr	bx, 1	; byte count to word count (samples)
  1521                                  sb_play_3: 
  1522 000006DE 4B                      	dec	bx ; wBlkSize is one less than the actual size
  1523                                  	SbOut   bl
    46                              <1> %%wait:
    47 000006DF EC                  <1>  in al, dx
    48 000006E0 08C0                <1>  or al, al
    49 000006E2 78FB                <1>  js short %%wait
    50 000006E4 88D8                <1>  mov al, %1
    51 000006E6 EE                  <1>  out dx, al
  1524                                  	SbOut   bh
    46                              <1> %%wait:
    47 000006E7 EC                  <1>  in al, dx
    48 000006E8 08C0                <1>  or al, al
    49 000006EA 78FB                <1>  js short %%wait
    50 000006EC 88F8                <1>  mov al, %1
    51 000006EE EE                  <1>  out dx, al
  1525                                  
  1526                                  	; 24/11/2024
  1527                                  	;mov	byte [stopped], 0 ; playing !
  1528                                  sb_Exit:
  1529 000006EF C3                      	retn
  1530                                  
  1531                                  ; --------------------------------------------------------
  1532                                  ; 14/11/2024 - Erdogan Tan
  1533                                  ; --------------------------------------------------------
  1534                                  
  1535                                  	; 02/01/2025 (cgaplay2.asm, SB16)
  1536                                  	; 01/01/2025 (cgaplay.asm, 16bit registers)
  1537                                  	; 07/12/2024
  1538                                  	; 01/12/2024 (32bit registers)
  1539                                  	; 29/11/2024
  1540                                  checkUpdateEvents:
  1541 000006F0 E8ED02                  	call	check4keyboardstop
  1542 000006F3 724B                    	jc	short c4ue_ok
  1543                                  
  1544                                  	; 01/01/2025
  1545                                  	; 18/11/2024
  1546 000006F5 50                      	push	ax ; *
  1547 000006F6 09C0                    	or	ax, ax
  1548 000006F8 0F849800                	jz	c4ue_cpt
  1549                                  
  1550                                  	; 18/11/2024
  1551 000006FC 3C20                    	cmp	al, 20h ; SPACE (spacebar) ; pause/play
  1552 000006FE 752B                    	jne	short c4ue_chk_s
  1553 00000700 803E[3514]00            	cmp	byte [stopped], 0
  1554 00000705 7706                    	ja	short c4ue_chk_ps
  1555                                  	; pause
  1556                                  	;call	ac97_pause
  1557                                  	; 02/01/2025
  1558 00000707 E883FD                  	call	sb16_pause	; 24/11/2024
  1559                                  	; 02/01/2025
  1560                                  	; 21/11/2024
  1561                                  	;mov	al, [tLO]
  1562                                  	;mov	byte [tLP], al
  1563 0000070A E98700                  	jmp	c4ue_cpt
  1564                                  c4ue_chk_ps:
  1565 0000070D 803E[3514]01            	cmp	byte [stopped], 1
  1566 00000712 7705                    	ja	short c4ue_replay
  1567                                  	; continue to play (after a pause)
  1568                                  	;call	ac97_play
  1569                                  	; 02/01/2025
  1570 00000714 E898FD                  	call	sb16_play	; 24/11/2024
  1571 00000717 EB7B                    	jmp	c4ue_cpt
  1572                                  c4ue_replay:
  1573                                  	; 19/11/2024
  1574 00000719 58                      	pop	ax ; *
  1575 0000071A 58                      	pop	ax ; return address
  1576                                  	; 07/02/2024
  1577                                  	;mov	al, [volume]
  1578                                  	;call	SetmasterVolume
  1579 0000071B C606[3514]00            	mov	byte [stopped], 0
  1580                                  	; 02/01/2024
  1581                                  	; 24/11/2024
  1582 00000720 C606[A411]01            	mov	byte [half_buffer], 1
  1583 00000725 E8C104                  	call	move_to_beginning
  1584                                  	; 02/01/2025 (cgaplay2.asm, SB16)
  1585 00000728 E9FCFA                  	jmp	PlayWav
  1586                                  	; 07/12/2024 (cgaplay.asm, AC97)
  1587                                  	;jmp	RePlayWav
  1588                                  
  1589                                  c4ue_chk_s:
  1590 0000072B 3C53                    	cmp	al, 'S'	; stop
  1591 0000072D 7512                    	jne	short c4ue_chk_fb
  1592 0000072F 803E[3514]00            	cmp	byte [stopped], 0
  1593 00000734 775E                    	ja	c4ue_cpt ; Already stopped/paused
  1594                                  	;call	ac97_stop
  1595                                  	; 02/01/2025
  1596 00000736 E810FD                  	call	sb16_stop	; 24/11/2024
  1597                                  	; 19/11/2024
  1598 00000739 C606[3614]00            	mov	byte [tLO], 0
  1599                                  	; 02/01/2025
  1600                                  	; 21/11/2024
  1601                                  	;mov	byte [tLP], '0'
  1602 0000073E EB54                    	jmp	c4ue_cpt
  1603                                  
  1604                                  	; 01/12/2024
  1605                                  	; 18/11/2024
  1606                                  c4ue_ok:
  1607 00000740 C3                      	retn
  1608                                  
  1609                                  c4ue_chk_fb:
  1610                                  	; 17/11/2024
  1611 00000741 3C46                    	cmp	al, 'F'
  1612 00000743 7505                    	jne	short c4ue_chk_b
  1613 00000745 E87D04                  	call 	Player_ProcessKey_Forwards
  1614 00000748 EB4A                    	jmp	c4ue_cpt
  1615                                  
  1616                                  c4ue_chk_b:
  1617 0000074A 3C42                    	cmp	al, 'B'
  1618                                  	;;jne	short c4ue_cpt
  1619                                  	; 19/11/2024
  1620                                  	;jne	short c4ue_chk_h
  1621                                  	; 25/12/2024
  1622                                  	; 29/11/2024
  1623 0000074C 7505                    	jne	short c4ue_chk_n
  1624 0000074E E87004                  	call 	Player_ProcessKey_Backwards
  1625 00000751 EB41                    	jmp	short c4ue_cpt
  1626                                  
  1627                                  	;;;
  1628                                  	; 25/12/2024
  1629                                  	; 29/11/2024
  1630                                  c4ue_chk_n:
  1631 00000753 3C4E                    	cmp	al, 'N'
  1632 00000755 7404                    	je	short c4ue_nps
  1633                                  c4ue_chk_p:
  1634 00000757 3C50                    	cmp	al, 'P'
  1635 00000759 7507                    	jne	short c4ue_chk_h
  1636                                  c4ue_nps:
  1637 0000075B C606[3514]03            	mov	byte [stopped], 3
  1638 00000760 EB32                    	jmp	short c4ue_cpt
  1639                                  	;;;
  1640                                  
  1641                                  c4ue_chk_h:
  1642                                  	; 19/11/2024
  1643 00000762 3C48                    	cmp	al, 'H'
  1644 00000764 750A                    	jne	short c4ue_chk_cr
  1645 00000766 C606[3714]00            	mov	byte [wpoints], 0
  1646                                  	;call 	write_ac97_pci_dev_info
  1647                                  	; 02/01/2025
  1648 0000076B E81FFE                  	call 	write_sb16_dev_info
  1649                                  	; 30/12/2024
  1650 0000076E EB24                    	jmp	short c4ue_cpt
  1651                                  c4ue_chk_cr:
  1652                                  	;;;
  1653                                  	; 24/12/2024 (wave lighting points option)
  1654                                  	;mov	ah, [wpoints]
  1655                                  	; 01/01/2025
  1656 00000770 31DB                    	xor	bx, bx
  1657 00000772 8A1E[3714]              	mov	bl, [wpoints]
  1658 00000776 3C47                    	cmp	al, 'G'
  1659 00000778 7406                    	je	short c4ue_g
  1660                                  	; 19/11/2024
  1661 0000077A 3C0D                    	cmp	al, 0Dh ; ENTER/CR key
  1662 0000077C 7516                    	jne	short c4ue_cpt
  1663                                  	; 23/11/2024
  1664                                  	;xor	bx, bx
  1665                                  	; 30/12/2024
  1666                                  	;mov	bl, ah ; 24/12/2024
  1667 0000077E FEC3                    	inc	bl
  1668                                  c4ue_g:	; 30/12/2024
  1669 00000780 80E307                  	and	bl, 07h
  1670 00000783 7501                    	jnz	short c4ue_sc
  1671                                  	; 01/01/2025
  1672 00000785 43                      	inc	bx
  1673                                  c4ue_sc:
  1674 00000786 881E[3714]              	mov	[wpoints], bl
  1675                                  	; 01/01/2025
  1676 0000078A 8A87[9B11]              	mov	al, [bx+colors-1] ; 1 to 7
  1677                                  	; 24/12/2024
  1678 0000078E A2[A311]                	mov	[ccolor], al
  1679                                  	; 30/12/2024
  1680 00000791 E89104                  	call	clear_window
  1681                                  	;;;
  1682                                  c4ue_cpt:
  1683 00000794 1E                      	push	ds
  1684 00000795 BB4000                  	mov	bx, 40h
  1685 00000798 8EDB                    	mov	ds, bx
  1686 0000079A BB6C00                  	mov	bx, 6Ch  ; counter (INT 08h, 18.2 ticks per sec)
  1687                                  	;cli
  1688 0000079D 8B07                    	mov	ax, [bx]
  1689 0000079F 8B5702                  	mov	dx, [bx+2]
  1690                                  	;sti
  1691 000007A2 1F                      	pop	ds
  1692                                  	; 18/11/2024
  1693 000007A3 59                      	pop	cx ; *
  1694 000007A4 3B16[D614]              	cmp	dx, [timerticks+2]
  1695 000007A8 7506                    	jne	short c4ue_utt
  1696 000007AA 3B06[D414]              	cmp	ax, [timerticks]
  1697                                  	;je	short c4ue_ok
  1698                                  	; 18/11/2024
  1699 000007AE 740A                    	je	short c4ue_skip_utt
  1700                                  c4ue_utt:
  1701                                  	; 01/01/2025
  1702 000007B0 A3[D414]                	mov	[timerticks], ax
  1703 000007B3 8916[D614]              	mov	[timerticks+2], dx
  1704 000007B7 EB05                    	jmp	short c4ue_cpt_@
  1705                                  
  1706                                  	; 30/12/2024
  1707                                  c4ue_vb_ok:
  1708 000007B9 C3                      	retn
  1709                                  
  1710                                  c4ue_skip_utt:
  1711                                  	; 01/01/2025
  1712                                  	; 18/11/2024
  1713 000007BA 21C9                    	and	cx, cx
  1714 000007BC 74FB                    	jz	short c4ue_vb_ok
  1715                                  c4ue_cpt_@:
  1716                                  	; 18/11/2024
  1717 000007BE 803E[3514]00            	cmp	byte [stopped], 0
  1718 000007C3 77F4                    	ja	short c4ue_vb_ok
  1719                                  	
  1720 000007C5 E8FC02                  	call	CalcProgressTime
  1721                                  
  1722 000007C8 3B06[CC14]              	cmp	ax, [ProgressTime]
  1723                                  	;je	short c4ue_vb_ok
  1724                                  			; same second, no need to update
  1725                                  	; 23/11/2024
  1726 000007CC 7403                    	je	short c4ue_uvb
  1727                                  
  1728                                  	;call	UpdateProgressTime
  1729                                  	;call	UpdateProgressBar@
  1730 000007CE E89203                  	call	UpdateProgressBar
  1731                                  
  1732                                  	; 23/11/2024
  1733                                  c4ue_uvb:
  1734 000007D1 803E[3714]00            	cmp	byte [wpoints], 0
  1735 000007D6 76E1                    	jna	short c4ue_vb_ok
  1736                                  
  1737                                  	; 30/12/2024
  1738                                  	;call	UpdateWavePoints
  1739                                  	;retn
  1740                                  
  1741                                  	; 02/01/2025 (cgaplay2.asm, SB16)
  1742 000007D8 FF16[C814]              	call	word [UpdateWavePoints]
  1743 000007DC C3                      	retn
  1744                                  
  1745                                  ; --------------------------------------------------------
  1746                                  ; 27/12/2024 - Erdogan Tan
  1747                                  ; --------------------------------------------------------
  1748                                  
  1749                                  	; 23/01/2025
  1750                                  	; 02/01/2025 (cgaplay2.asm, SB16)
  1751                                  	; 01/01/2025 (cgaplay.asm, 16bit registers)
  1752                                  	; 30/12/2024 (cgaplay.s)
  1753                                  	;  * 320*200 pixels, 256 colors
  1754                                  	;  * 64 volume levels
  1755                                  	; 29/12/2024
  1756                                  	; 27/12/2024 (DMA Buffer Tracking)
  1757                                  	; 26/12/2024
  1758                                  	; 24/12/2024
  1759                                  ;UpdateWavePoints:
  1760                                  	; 02/01/2025
  1761                                  UpdateWavePoints_16s:
  1762                                  	; 01/01/2025
  1763 000007DD 06                      	push	es ; **
  1764 000007DE BB00A0                  	mov	bx, 0A000h
  1765 000007E1 8EC3                    	mov	es, bx
  1766                                  	;
  1767 000007E3 BE[AA11]                	mov	si, prev_points
  1768 000007E6 833C00                  	cmp	word [si], 0
  1769 000007E9 740C                    	jz	short lights_off_ok
  1770                                  
  1771                                  	;mov	cx, 640
  1772                                  	; 30/12/2024
  1773 000007EB B94001                  	mov	cx, 320
  1774                                  light_off:
  1775 000007EE AD                      	lodsw
  1776                                  	; ax = wave point (lighting point) address
  1777                                  	;mov	byte [ax], 0 ; black point (light off)
  1778                                  	; 01/01/2025 (16bit mode modification)
  1779 000007EF 89C3                    	mov	bx, ax
  1780 000007F1 26C60700                	mov	byte [es:bx], 0
  1781 000007F5 E2F7                    	loop	light_off
  1782                                  
  1783                                  lights_off_ok:
  1784                                  	; 29/12/2024
  1785 000007F7 803E[3614]32            	cmp	byte [tLO],'2'
  1786 000007FC 7505                    	jne	short lights_on_buff_1
  1787                                  lights_on_buff_2:
  1788                                  	; 01/01/2025
  1789                                  	;mov	dx, [WAV_BUFFER2]
  1790                                  	; 02/01/2025
  1791 000007FE BA[026B]                	mov	dx, wav_buffer2
  1792 00000801 EB03                    	jmp	short lights_on
  1793                                  lights_on_buff_1:
  1794                                  	; 01/01/2025
  1795                                  	;mov	dx, [WAV_BUFFER1]
  1796                                  	; 02/01/2025
  1797 00000803 BA[E014]                	mov	dx, wav_buffer1
  1798                                  lights_on:
  1799 00000806 3916[3A14]              	cmp	[pbuf_s], dx
  1800 0000080A 7519                    	jne	short lights_on_2
  1801 0000080C 8B1E[A611]              	mov	bx, [wpoints_dif]
  1802 00000810 8B36[3814]              	mov	si, [pbuf_o]
  1803                                  	;mov	cx, [buffersize] ; samples
  1804                                  	;; 01/01/2025
  1805                                  	;shl	cx, 1  ; bytes
  1806                                  	; 02/01/2025
  1807 00000814 B92256                  	mov	cx, LOADSIZE
  1808 00000817 29D9                    	sub	cx, bx ; sub cx, [wpoints_dif]
  1809 00000819 01DE                    	add	si, bx
  1810 0000081B 7204                    	jc	short lights_on_1
  1811 0000081D 39CE                    	cmp	si, cx
  1812 0000081F 760A                    	jna	short lights_on_3
  1813                                  lights_on_1:
  1814 00000821 89CE                    	mov	si, cx
  1815 00000823 EB06                    	jmp	short lights_on_3
  1816                                  
  1817                                  lights_on_2:
  1818                                  	; 29/12/2024
  1819 00000825 8916[3A14]              	mov	[pbuf_s], dx
  1820 00000829 31F6                    	xor	si, si ; 0
  1821                                  lights_on_3:
  1822 0000082B 8936[3814]              	mov	[pbuf_o], si
  1823                                  	; 02/01/2025
  1824                                  	; 01/01/2025
  1825                                  	;push	ds ; **
  1826                                  	;
  1827                                  	;mov	cx, 640
  1828                                  	; 30/12/2024
  1829 0000082F B94001                  	mov	cx, 320
  1830 00000832 89CD                    	mov	bp, cx
  1831                                  	; 26/12/2024
  1832 00000834 BF[AA11]                	mov	di, prev_points
  1833                                  	;mov	bx, [graphstart] ; start (top) line
  1834                                  	; 01/01/2025
  1835                                  	;mov	ds, dx
  1836                                  	; 02/01/2025
  1837 00000837 01D6                    	add	si, dx
  1838 00000839 BB0073                  	mov	bx, (11*8*320)+(4*320)
  1839                                  lights_on_4:
  1840                                  	; 23/01/2025
  1841                                  	;; 01/01/2025
  1842                                  	;xor	eax, eax ; 0
  1843                                  	;lodsw	; left
  1844                                  	;add	ah, 80h
  1845                                  	;mov	edx, eax
  1846                                  	;lodsw	; right
  1847                                  	;;add	ax, dx
  1848                                  	;add	ah, 80h
  1849                                  	;;;shr	eax, 9	; 128 volume levels
  1850                                  	;add	eax, edx
  1851                                  	;;;shr	eax, 10	; (L+R/2) & 128 volume levels
  1852                                  	;;shr	eax, 9	; (L+R/2) & 256 volume levels
  1853                                  	;; 30/12/2024
  1854                                  	;shr	eax, 11	; (L+R/2) & 64 volume levels
  1855                                  	; 23/01/2025
  1856 0000083C AD                      	lodsw	; left
  1857 0000083D 80C480                  	add	ah, 80h
  1858 00000840 89C2                    	mov	dx, ax	
  1859 00000842 AD                      	lodsw	; right
  1860 00000843 80C480                  	add	ah, 80h
  1861 00000846 01D0                    	add	ax, dx	; (L+R)	
  1862 00000848 D1D8                    	rcr	ax, 1	; (L+R)/2
  1863 0000084A C1E80A                  	shr	ax, 10	; 64 volume levels
  1864                                  
  1865                                  	; * 320 row  ; 30/12/2024
  1866 0000084D F7E5                    	mul	bp	; * 640 (row) 
  1867 0000084F 01D8                    	add	ax, bx ; + column
  1868                                  	; 02/01/2025
  1869 00000851 8A16[A311]              	mov	dl, [ccolor]
  1870                                  	; 01/01/2025
  1871                                  	;mov	dl, [cs:ccolor]
  1872 00000855 93                      	xchg	ax, bx
  1873 00000856 268817                  	mov	[es:bx], dl ; pixel (light on) color
  1874 00000859 93                      	xchg	ax, bx
  1875                                  	;mov	[cs:di], ax ; save light on addr in prev_points
  1876                                  	; 02/01/2025
  1877 0000085A 8905                    	mov	[di], ax
  1878 0000085C 47                      	inc	di
  1879 0000085D 47                      	inc	di
  1880 0000085E 43                      	inc	bx
  1881 0000085F E2DB                    	loop	lights_on_4
  1882                                  	; 02/01/2025
  1883                                  	;pop	ds ; **
  1884 00000861 07                      	pop	es ; *
  1885 00000862 C3                      	retn
  1886                                  
  1887                                  ; -------------------------
  1888                                  
  1889                                  	; 02/01/2025 (cgaplay2.asm, SB16, RetroDOS)
  1890                                  	; 01/01/2025 (cgaplay.asm, AC97, RetroDOS)
  1891                                  	; 30/12/2024 (cgaplay.s, AC97, TRDOS386)
  1892                                  	;  * 320*200 pixels, 256 colors
  1893                                  	;  * 64 volume levels
  1894                                  UpdateWavePoints_16m:
  1895                                  	; 01/01/2025
  1896 00000863 06                      	push	es ; **
  1897 00000864 BB00A0                  	mov	bx, 0A000h
  1898 00000867 8EC3                    	mov	es, bx
  1899                                  	;
  1900 00000869 BE[AA11]                	mov	si, prev_points
  1901 0000086C 833C00                  	cmp	word [si], 0
  1902 0000086F 740C                    	jz	short lights_off_16m_ok
  1903                                  
  1904                                  	;mov	cx, 640
  1905                                  	; 30/12/2024
  1906 00000871 B94001                  	mov	cx, 320
  1907                                  light_16m_off:
  1908 00000874 AD                      	lodsw
  1909                                  	; ax = wave point (lighting point) address
  1910                                  	;mov	byte [ax], 0 ; black point (light off)
  1911                                  	; 01/01/2025 (16bit mode modification)
  1912 00000875 89C3                    	mov	bx, ax
  1913 00000877 26C60700                	mov	byte [es:bx], 0
  1914 0000087B E2F7                    	loop	light_16m_off
  1915                                  
  1916                                  lights_off_16m_ok:
  1917                                  	; 29/12/2024
  1918 0000087D 803E[3614]32            	cmp	byte [tLO],'2'
  1919 00000882 7505                    	jne	short lights_16m_on_buff_1
  1920                                  lights_16m_on_buff_2:
  1921                                  	; 01/01/2025
  1922                                  	;mov	dx, [WAV_BUFFER2]
  1923                                  	; 02/01/2025
  1924 00000884 BA[026B]                	mov	dx, wav_buffer2
  1925 00000887 EB03                    	jmp	short lights_16m_on
  1926                                  lights_16m_on_buff_1:
  1927                                  	; 01/01/2025
  1928                                  	;mov	dx, [WAV_BUFFER1]
  1929                                  	; 02/01/2025
  1930 00000889 BA[E014]                	mov	dx, wav_buffer1
  1931                                  lights_16m_on:
  1932 0000088C 3916[3A14]              	cmp	[pbuf_s], dx
  1933 00000890 7519                    	jne	short lights_16m_on_2
  1934 00000892 8B1E[A611]              	mov	bx, [wpoints_dif]
  1935 00000896 8B36[3814]              	mov	si, [pbuf_o]
  1936                                  	;mov	cx, [buffersize] ; samples
  1937                                  	;; 01/01/2025
  1938                                  	;shl	cx, 1  ; bytes
  1939                                  	; 02/01/2025
  1940 0000089A B92256                  	mov	cx, LOADSIZE
  1941 0000089D 29D9                    	sub	cx, bx ; sub cx, [wpoints_dif]
  1942 0000089F 01DE                    	add	si, bx
  1943 000008A1 7204                    	jc	short lights_16m_on_1
  1944 000008A3 39CE                    	cmp	si, cx
  1945 000008A5 760A                    	jna	short lights_16m_on_3
  1946                                  lights_16m_on_1:
  1947 000008A7 89CE                    	mov	si, cx
  1948 000008A9 EB06                    	jmp	short lights_16m_on_3
  1949                                  
  1950                                  lights_16m_on_2:
  1951                                  	; 29/12/2024
  1952 000008AB 8916[3A14]              	mov	[pbuf_s], dx
  1953 000008AF 31F6                    	xor	si, si ; 0
  1954                                  lights_16m_on_3:
  1955 000008B1 8936[3814]              	mov	[pbuf_o], si
  1956                                  	; 02/01/2025
  1957                                  	; 01/01/2025
  1958                                  	;push	ds ; **
  1959                                  	;
  1960                                  	;mov	cx, 640
  1961                                  	; 30/12/2024
  1962 000008B5 B94001                  	mov	cx, 320
  1963 000008B8 89CD                    	mov	bp, cx
  1964                                  	; 26/12/2024
  1965 000008BA BF[AA11]                	mov	di, prev_points
  1966                                  	;mov	bx, [graphstart] ; start (top) line
  1967                                  	; 01/01/2025
  1968                                  	;mov	ds, dx
  1969                                  	; 02/01/2025
  1970 000008BD 01D6                    	add	si, dx
  1971 000008BF BB0073                  	mov	bx, (11*8*320)+(4*320)
  1972                                  lights_16m_on_4:
  1973                                  	; 02/01/2025 (16bit mono play modifications)
  1974                                  	; 23/01/2025
  1975                                  	;xor	ax, ax ; 0
  1976 000008C2 AD                      	lodsw	; left
  1977 000008C3 80C480                  	add	ah, 80h
  1978 000008C6 C1E80A                  	shr	ax, 10	; 64 volume levels
  1979                                  	; 30/12/2024
  1980                                  	; * 320 row
  1981 000008C9 F7E5                    	mul	bp ; * 640 (row)
  1982 000008CB 01D8                    	add	ax, bx ; + column
  1983                                  	; 02/01/2025
  1984 000008CD 8A16[A311]              	mov	dl, [ccolor]
  1985                                  	; 01/01/2025
  1986                                  	;mov	dl, [cs:ccolor]
  1987 000008D1 93                      	xchg	ax, bx
  1988 000008D2 268817                  	mov	[es:bx], dl ; pixel (light on) color
  1989 000008D5 93                      	xchg	ax, bx
  1990                                  	;mov	[cs:di], ax ; save light on addr in prev_points
  1991                                  	; 02/01/2025
  1992 000008D6 8905                    	mov	[di], ax
  1993 000008D8 47                      	inc	di
  1994 000008D9 47                      	inc	di
  1995 000008DA 43                      	inc	bx
  1996 000008DB E2E5                    	loop	lights_16m_on_4
  1997                                  	; 02/01/2025
  1998                                  	;pop	ds ; **
  1999 000008DD 07                      	pop	es ; *
  2000 000008DE C3                      	retn
  2001                                  
  2002                                  ; -------------------------
  2003                                  
  2004                                  	; 02/01/2025
  2005                                  UpdateWavePoints_8s:
  2006                                  	; 01/01/2025
  2007 000008DF 06                      	push	es ; **
  2008 000008E0 BB00A0                  	mov	bx, 0A000h
  2009 000008E3 8EC3                    	mov	es, bx
  2010                                  	;
  2011 000008E5 BE[AA11]                	mov	si, prev_points
  2012 000008E8 833C00                  	cmp	word [si], 0
  2013 000008EB 740C                    	jz	short lights_off_8s_ok
  2014                                  
  2015                                  	;mov	cx, 640
  2016                                  	; 30/12/2024
  2017 000008ED B94001                  	mov	cx, 320
  2018                                  light_8s_off:
  2019 000008F0 AD                      	lodsw
  2020                                  	; ax = wave point (lighting point) address
  2021                                  	;mov	byte [ax], 0 ; black point (light off)
  2022                                  	; 01/01/2025 (16bit mode modification)
  2023 000008F1 89C3                    	mov	bx, ax
  2024 000008F3 26C60700                	mov	byte [es:bx], 0
  2025 000008F7 E2F7                    	loop	light_8s_off
  2026                                  
  2027                                  lights_off_8s_ok:
  2028                                  	; 29/12/2024
  2029 000008F9 803E[3614]32            	cmp	byte [tLO],'2'
  2030 000008FE 7505                    	jne	short lights_8s_on_buff_1
  2031                                  lights_8s_on_buff_2:
  2032                                  	; 01/01/2025
  2033                                  	;mov	dx, [WAV_BUFFER2]
  2034                                  	; 02/01/2025
  2035 00000900 BA[026B]                	mov	dx, wav_buffer2
  2036 00000903 EB03                    	jmp	short lights_8s_on
  2037                                  lights_8s_on_buff_1:
  2038                                  	; 01/01/2025
  2039                                  	;mov	dx, [WAV_BUFFER1]
  2040                                  	; 02/01/2025
  2041 00000905 BA[E014]                	mov	dx, wav_buffer1
  2042                                  lights_8s_on:
  2043 00000908 3916[3A14]              	cmp	[pbuf_s], dx
  2044 0000090C 7519                    	jne	short lights_8s_on_2
  2045 0000090E 8B1E[A611]              	mov	bx, [wpoints_dif]
  2046 00000912 8B36[3814]              	mov	si, [pbuf_o]
  2047                                  	;mov	cx, [buffersize] ; samples
  2048                                  	;; 01/01/2025
  2049                                  	;shl	cx, 1  ; bytes
  2050                                  	; 02/01/2025
  2051 00000916 B92256                  	mov	cx, LOADSIZE
  2052 00000919 29D9                    	sub	cx, bx ; sub cx, [wpoints_dif]
  2053 0000091B 01DE                    	add	si, bx
  2054 0000091D 7204                    	jc	short lights_8s_on_1
  2055 0000091F 39CE                    	cmp	si, cx
  2056 00000921 760A                    	jna	short lights_8s_on_3
  2057                                  lights_8s_on_1:
  2058 00000923 89CE                    	mov	si, cx
  2059 00000925 EB06                    	jmp	short lights_8s_on_3
  2060                                  
  2061                                  lights_8s_on_2:
  2062                                  	; 29/12/2024
  2063 00000927 8916[3A14]              	mov	[pbuf_s], dx
  2064 0000092B 31F6                    	xor	si, si ; 0
  2065                                  lights_8s_on_3:
  2066 0000092D 8936[3814]              	mov	[pbuf_o], si
  2067                                  	; 02/01/2025
  2068                                  	; 01/01/2025
  2069                                  	;push	ds ; **
  2070                                  	;
  2071                                  	;mov	cx, 640
  2072                                  	; 30/12/2024
  2073 00000931 B94001                  	mov	cx, 320
  2074 00000934 89CD                    	mov	bp, cx
  2075                                  	; 26/12/2024
  2076 00000936 BF[AA11]                	mov	di, prev_points
  2077                                  	;mov	bx, [graphstart] ; start (top) line
  2078                                  	; 01/01/2025
  2079                                  	;mov	ds, dx
  2080                                  	; 02/01/2025
  2081 00000939 01D6                    	add	si, dx
  2082 0000093B BB0073                  	mov	bx, (11*8*320)+(4*320)
  2083                                  lights_8s_on_4:
  2084                                  	; 02/01/2025 (8bit stereo play modifications)
  2085 0000093E 31C0                    	xor	ax, ax ; 0
  2086 00000940 AC                      	lodsb	; left
  2087 00000941 89C2                    	mov	dx, ax
  2088 00000943 AC                      	lodsb	; right
  2089 00000944 01D0                    	add	ax, dx
  2090 00000946 D1E8                    	shr	ax, 1 ; (L+R/2)
  2091 00000948 2CFF                    	sub	al, 255	; max. value will be shown on top
  2092 0000094A C1E802                  	shr	ax, 2 ; 64 volume levels
  2093                                  	; * 320 row  ; 30/12/2024
  2094 0000094D F7E5                    	mul	bp	; * 640 (row) 
  2095 0000094F 01D8                    	add	ax, bx ; + column
  2096                                  	; 02/01/2025
  2097 00000951 8A16[A311]              	mov	dl, [ccolor]
  2098                                  	; 01/01/2025
  2099                                  	;mov	dl, [cs:ccolor]
  2100 00000955 93                      	xchg	ax, bx
  2101 00000956 268817                  	mov	[es:bx], dl ; pixel (light on) color
  2102 00000959 93                      	xchg	ax, bx
  2103                                  	;mov	[cs:di], ax ; save light on addr in prev_points
  2104                                  	; 02/01/2025
  2105 0000095A 8905                    	mov	[di], ax
  2106 0000095C 47                      	inc	di
  2107 0000095D 47                      	inc	di
  2108 0000095E 43                      	inc	bx
  2109 0000095F E2DD                    	loop	lights_8s_on_4
  2110                                  	; 02/01/2025
  2111                                  	;pop	ds ; **
  2112 00000961 07                      	pop	es ; *
  2113 00000962 C3                      	retn
  2114                                  
  2115                                  ; -------------------------
  2116                                  
  2117                                  	; 02/01/2025
  2118                                  UpdateWavePoints_8m:
  2119                                  	; 01/01/2025
  2120 00000963 06                      	push	es ; **
  2121 00000964 BB00A0                  	mov	bx, 0A000h
  2122 00000967 8EC3                    	mov	es, bx
  2123                                  	;
  2124 00000969 BE[AA11]                	mov	si, prev_points
  2125 0000096C 833C00                  	cmp	word [si], 0
  2126 0000096F 740C                    	jz	short lights_off_8m_ok
  2127                                  
  2128                                  	;mov	cx, 640
  2129                                  	; 30/12/2024
  2130 00000971 B94001                  	mov	cx, 320
  2131                                  light_8m_off:
  2132 00000974 AD                      	lodsw
  2133                                  	; ax = wave point (lighting point) address
  2134                                  	;mov	byte [ax], 0 ; black point (light off)
  2135                                  	; 01/01/2025 (16bit mode modification)
  2136 00000975 89C3                    	mov	bx, ax
  2137 00000977 26C60700                	mov	byte [es:bx], 0
  2138 0000097B E2F7                    	loop	light_8m_off
  2139                                  
  2140                                  lights_off_8m_ok:
  2141                                  	; 29/12/2024
  2142 0000097D 803E[3614]32            	cmp	byte [tLO],'2'
  2143 00000982 7505                    	jne	short lights_8m_on_buff_1
  2144                                  lights_8m_on_buff_2:
  2145                                  	; 01/01/2025
  2146                                  	;mov	dx, [WAV_BUFFER2]
  2147                                  	; 02/01/2025
  2148 00000984 BA[026B]                	mov	dx, wav_buffer2
  2149 00000987 EB03                    	jmp	short lights_8m_on
  2150                                  lights_8m_on_buff_1:
  2151                                  	; 01/01/2025
  2152                                  	;mov	dx, [WAV_BUFFER1]
  2153                                  	; 02/01/2025
  2154 00000989 BA[E014]                	mov	dx, wav_buffer1
  2155                                  lights_8m_on:
  2156 0000098C 3916[3A14]              	cmp	[pbuf_s], dx
  2157 00000990 7519                    	jne	short lights_8m_on_2
  2158 00000992 8B1E[A611]              	mov	bx, [wpoints_dif]
  2159 00000996 8B36[3814]              	mov	si, [pbuf_o]
  2160                                  	;mov	cx, [buffersize] ; samples
  2161                                  	;; 01/01/2025
  2162                                  	;shl	cx, 1  ; bytes
  2163                                  	; 02/01/2025
  2164 0000099A B92256                  	mov	cx, LOADSIZE
  2165 0000099D 29D9                    	sub	cx, bx ; sub cx, [wpoints_dif]
  2166 0000099F 01DE                    	add	si, bx
  2167 000009A1 7204                    	jc	short lights_8m_on_1
  2168 000009A3 39CE                    	cmp	si, cx
  2169 000009A5 760A                    	jna	short lights_8m_on_3
  2170                                  lights_8m_on_1:
  2171 000009A7 89CE                    	mov	si, cx
  2172 000009A9 EB06                    	jmp	short lights_8m_on_3
  2173                                  
  2174                                  lights_8m_on_2:
  2175                                  	; 29/12/2024
  2176 000009AB 8916[3A14]              	mov	[pbuf_s], dx
  2177 000009AF 31F6                    	xor	si, si ; 0
  2178                                  lights_8m_on_3:
  2179 000009B1 8936[3814]              	mov	[pbuf_o], si
  2180                                  	; 02/01/2025
  2181                                  	; 01/01/2025
  2182                                  	;push	ds ; **
  2183                                  	;
  2184                                  	;mov	cx, 640
  2185                                  	; 30/12/2024
  2186 000009B5 B94001                  	mov	cx, 320
  2187 000009B8 89CD                    	mov	bp, cx
  2188                                  	; 26/12/2024
  2189 000009BA BF[AA11]                	mov	di, prev_points
  2190                                  	;mov	bx, [graphstart] ; start (top) line
  2191                                  	; 01/01/2025
  2192                                  	;mov	ds, dx
  2193                                  	; 02/01/2025
  2194 000009BD 01D6                    	add	si, dx
  2195 000009BF BB0073                  	mov	bx, (11*8*320)+(4*320)
  2196                                  lights_8m_on_4:
  2197                                  	; 02/01/2025 (8bit mono play modifications)
  2198 000009C2 31C0                    	xor	ax, ax ; 0
  2199 000009C4 AC                      	lodsb
  2200 000009C5 2CFF                    	sub	al, 255	; max. value will be shown on top
  2201 000009C7 C1E802                  	shr	ax, 2  ; 64 volume levels
  2202                                  	; 30/12/2024
  2203                                  	; * 320 row
  2204 000009CA F7E5                    	mul	bp ; * 640 (row)
  2205 000009CC 01D8                    	add	ax, bx ; + column
  2206                                  	; 02/01/2025
  2207 000009CE 8A16[A311]              	mov	dl, [ccolor]
  2208                                  	; 01/01/2025
  2209                                  	;mov	dl, [cs:ccolor]
  2210 000009D2 93                      	xchg	ax, bx
  2211 000009D3 268817                  	mov	[es:bx], dl ; pixel (light on) color
  2212 000009D6 93                      	xchg	ax, bx
  2213                                  	;mov	[cs:di], ax ; save light on addr in prev_points
  2214                                  	; 02/01/2025
  2215 000009D7 8905                    	mov	[di], ax
  2216 000009D9 47                      	inc	di
  2217 000009DA 47                      	inc	di
  2218 000009DB 43                      	inc	bx
  2219 000009DC E2E4                    	loop	lights_8m_on_4
  2220                                  	; 02/01/2025
  2221                                  	;pop	ds ; **
  2222 000009DE 07                      	pop	es ; *
  2223 000009DF C3                      	retn
  2224                                  
  2225                                  ; --------------------------------------------------------
  2226                                  ; 19/05/2024 - (playwav4.asm) ich_wav4.asm
  2227                                  ; --------------------------------------------------------
  2228                                  
  2229                                  	; 02/01/2025 (cgaplay2.asm)
  2230                                  	; 29/11/2024
  2231                                  check4keyboardstop:
  2232                                  	; 19/05/2024
  2233                                  	; 08/11/2023
  2234                                  	; 04/11/2023
  2235 000009E0 B401                    	mov	ah, 1
  2236 000009E2 CD16                    	int	16h
  2237                                  	;clc
  2238 000009E4 7429                    	jz	short _cksr
  2239                                  
  2240 000009E6 30E4                    	xor	ah, ah
  2241 000009E8 CD16                    	int	16h
  2242                                  
  2243                                  	; 29/11/2024
  2244 000009EA A2[3C14]                	mov	[command], al
  2245                                  
  2246                                  	;;;
  2247                                  	; 19/05/2024 (change PCM out volume)
  2248 000009ED 3C2B                    	cmp	al, '+'
  2249 000009EF 750B                    	jne	short p_1
  2250                                  	
  2251 000009F1 A0[350A]                	mov	al, [volume]
  2252                                  	;cmp	al, 0
  2253                                  	;jna	short p_3
  2254                                  	;dec	al
  2255                                  	;jmp	short p_2
  2256                                  	; 02/01/2025
  2257 000009F4 3C0F                    	cmp	al, 15
  2258 000009F6 7319                    	jnb	short p_3
  2259 000009F8 FEC0                    	inc	al
  2260 000009FA EB0D                    	jmp	short p_2
  2261                                  p_1:
  2262 000009FC 3C2D                    	cmp	al, '-'
  2263 000009FE 7512                    	jne	short p_4
  2264                                  
  2265 00000A00 A0[350A]                	mov	al, [volume]
  2266                                  	;cmp	al, 31
  2267                                  	;jnb	short p_3
  2268                                  	;inc	al
  2269                                  	; 02/01/2025
  2270 00000A03 3C00                    	cmp	al, 0
  2271 00000A05 760A                    	jna	short p_3
  2272 00000A07 FEC8                    	dec	al
  2273                                  p_2:
  2274                                  	; 02/01/2025
  2275                                  	;mov	[volume], al
  2276                                  	; 14/11/2024
  2277                                  	;call	SetPCMOutVolume
  2278                                  	; 02/01/2025
  2279                                  	; 15/11/2024 (QEMU)
  2280 00000A09 E8E0F8                  	call	SetMasterVolume
  2281                                  	;call	UpdateVolume
  2282                                  	;;clc
  2283                                  	;retn
  2284 00000A0C E93101                  	jmp	UpdateVolume
  2285                                  
  2286                                  _cksr:		; 19/05/2024
  2287                                  	; 18/11/2024
  2288 00000A0F 31C0                    	xor	ax, ax
  2289                                  	;clc
  2290                                  p_3:
  2291 00000A11 C3                      	retn
  2292                                  p_4:
  2293                                  	; 17/11/2024
  2294 00000A12 80FC01                  	cmp	ah, 01h  ; ESC
  2295 00000A15 7417                        	je	short p_q
  2296 00000A17 3C03                    	cmp	al, 03h  ; CTRL+C
  2297 00000A19 7413                    	je	short p_q
  2298                                  
  2299                                  	; 18/11/2024
  2300 00000A1B 3C20                    	cmp	al, 20h
  2301 00000A1D 7415                    	je	short p_r
  2302                                  
  2303                                  	; 19/11/2024
  2304 00000A1F 3C0D                    	cmp	al, 0Dh ; CR/ENTER
  2305 00000A21 7411                    	je	short p_r
  2306                                  
  2307 00000A23 24DF                    	and	al, 0DFh
  2308                                  
  2309                                  	; 29/11/2024
  2310 00000A25 A2[3C14]                	mov	[command], al
  2311                                  
  2312                                  	;cmp	al, 'B'
  2313                                  	;je	short p_r
  2314                                  	;cmp	al, 'F'
  2315                                  	;je	short p_r
  2316                                  
  2317                                  	; 29/11/2024
  2318                                  	;cmp	al, 'N'
  2319                                  	;je	short p_r
  2320                                  	;cmp	al, 'P'
  2321                                  	;je	short p_r
  2322                                  
  2323 00000A28 3C51                    	cmp	al, 'Q'
  2324                                  	;je	short p_q
  2325 00000A2A 7407                    	je	short p_quit ; 29/11/2024
  2326                                  
  2327 00000A2C F8                      	clc
  2328 00000A2D C3                      	retn
  2329                                  
  2330                                  	;;;
  2331                                  ;_cskr:	
  2332                                  p_q:
  2333                                  	; 29/11/2024
  2334 00000A2E C606[3C14]51            	mov	byte [command], 'Q'
  2335                                  p_quit:
  2336 00000A33 F9                      	stc
  2337                                  p_r:
  2338 00000A34 C3                      	retn
  2339                                  
  2340                                  ; 29/05/2024
  2341                                  ; 19/05/2024
  2342                                  volume: 
  2343                                  	;db	02h
  2344                                  ; 26/12/2024
  2345                                  	;db	03h
  2346                                  ; 02/01/2025 (SB16)
  2347 00000A35 0A                      	db	10 ; max = 15, min = 0
  2348                                  
  2349                                  ; --------------------------------------------------------
  2350                                  
  2351                                  	; 01/01/2025 /cgaplay.asm)
  2352                                  setCursorPosition:
  2353                                  	; dh = Row
  2354                                  	; dl = Column
  2355                                  
  2356                                  	; 31/12/2024
  2357 00000A36 B700                    	mov	bh, 0
  2358 00000A38 B402                    	mov	ah, 02h
  2359 00000A3A CD10                    	int	10h
  2360 00000A3C C3                      	retn
  2361                                  	
  2362                                  ; --------------------------------------------------------
  2363                                  ; 14/11/2024
  2364                                  ; (Ref: player.asm, out_cs.asm, Matan Alfasi, 2017)
  2365                                  
  2366                                  ;; NAME:	SetTotalTime
  2367                                  ;; DESCRIPTION: Calculates the total time in seconds in file
  2368                                  ;; INPUT:	DATA_SubchunkSize, WAVE_SampleRate, WAVE_BlockAlign
  2369                                  ;; OUTPUT:	CurrentTotalTime=Total time in seconds in file,
  2370                                  ;; 		Output on the screen of the total time in seconds
  2371                                  
  2372                                  	; 01/01/2025
  2373                                  SetTotalTime:
  2374                                  	;; Calculate total seconds in file
  2375 00000A3D A1[6814]                	mov	ax, [DATA_SubchunkSize]
  2376 00000A40 8B16[6A14]              	mov	dx, [DATA_SubchunkSize+2]
  2377 00000A44 8B1E[5814]              	mov	bx, [WAVE_SampleRate]
  2378 00000A48 F7F3                    	div	bx
  2379 00000A4A 31D2                    	xor	dx, dx
  2380                                  
  2381 00000A4C 8B1E[6014]              	mov	bx, [WAVE_BlockAlign]
  2382                                  
  2383 00000A50 F7F3                    	div	bx
  2384                                  
  2385 00000A52 A3[CA14]                	mov	[TotalTime], ax
  2386                                  
  2387 00000A55 B33C                    	mov	bl, 60
  2388 00000A57 F6F3                    	div	bl
  2389                                  
  2390                                  	;; al = minutes, ah = seconds
  2391 00000A59 50                      	push	ax ; **
  2392 00000A5A 50                      	push	ax ; *
  2393                                  
  2394                                  	;mov	dh, 24
  2395                                  	;mov	dl, 42
  2396                                  	; 01/01/2025 (cgaplay.asm, video mode 13h)
  2397 00000A5B B617                    	mov	dh, 23
  2398 00000A5D B216                    	mov	dl, 22
  2399 00000A5F E8D4FF                  	call	setCursorPosition
  2400                                  
  2401 00000A62 58                      	pop	ax ; *
  2402 00000A63 30E4                    	xor	ah, ah
  2403 00000A65 BD0200                  	mov	bp, 2
  2404 00000A68 E80F00                  	call	PrintNumber
  2405                                  	
  2406                                  	;mov	dh, 24
  2407                                  	;mov	dl, 45
  2408                                  	; 01/01/2025 (cgaplay.asm, video mode 13h)
  2409 00000A6B B617                    	mov	dh, 23
  2410 00000A6D B219                    	mov	dl, 25
  2411 00000A6F E8C4FF                  	call	setCursorPosition
  2412                                  
  2413 00000A72 58                      	pop	ax ; **
  2414 00000A73 88E0                    	mov	al, ah
  2415 00000A75 30E4                    	xor	ah, ah
  2416 00000A77 BD0200                  	mov	bp, 2
  2417                                  	;jmp	short PrintNumber
  2418                                  
  2419                                  ; --------------------------------------------------------
  2420                                  
  2421                                  	; 01/01/2025 (cgaplay.asm)
  2422                                  PrintNumber:
  2423                                  	; bp = digits
  2424                                  	; ax = binary number
  2425 00000A7A BB0A00                  	mov	bx, 10
  2426 00000A7D 31C9                    	xor	cx, cx
  2427                                  printNumber_CutNumber:
  2428 00000A7F 41                      	inc	cx
  2429 00000A80 31D2                    	xor	dx, dx
  2430 00000A82 F7F3                    	div	bx
  2431 00000A84 52                      	push	dx
  2432 00000A85 39E9                    	cmp	cx, bp
  2433 00000A87 7402                    	je	short printNumber_printloop
  2434 00000A89 EBF4                    	jmp	printNumber_CutNumber
  2435                                  
  2436                                  printNumber_printloop:
  2437 00000A8B 58                      	pop	ax
  2438                                  	; bp = count of digits
  2439                                  	; ax <= 9
  2440                                  
  2441 00000A8C 0430                    	add	al, '0'
  2442                                  	
  2443                                  	; al = character
  2444 00000A8E E8C900                  	call	write_character_white
  2445                                  
  2446 00000A91 4D                      	dec	bp
  2447 00000A92 7402                     	jz	short printNumber_ok
  2448 00000A94 EBF5                    	jmp	short printNumber_printloop
  2449                                  printNumber_ok:
  2450 00000A96 C3                      	retn
  2451                                  
  2452                                  ; --------------------------------------------------------
  2453                                  
  2454                                  	; 01/01/2025
  2455                                  	; 14/11/2024 - Erdogan Tan
  2456                                  SetProgressTime:
  2457                                  	;; Calculate playing/progress seconds in file
  2458 00000A97 E82A00                  	call	CalcProgressTime
  2459                                  
  2460                                  UpdateProgressTime:
  2461                                  	; ax = (new) progress time 
  2462                                  
  2463 00000A9A A3[CC14]                	mov	[ProgressTime], ax
  2464                                  
  2465 00000A9D B33C                    	mov	bl, 60
  2466 00000A9F F6F3                    	div	bl
  2467                                  
  2468                                  	;; al = minutes, ah = seconds
  2469 00000AA1 50                      	push	ax ; **
  2470 00000AA2 50                      	push	ax ; *
  2471                                  
  2472                                  	;mov	dh, 24
  2473                                  	;mov	dl, 33
  2474                                  	; 01/01/2025 (cgaplay.asm, video mode 13h)
  2475 00000AA3 B617                    	mov	dh, 23
  2476 00000AA5 B20D                    	mov	dl, 13
  2477 00000AA7 E88CFF                  	call	setCursorPosition
  2478                                  
  2479 00000AAA 58                      	pop	ax ; *
  2480 00000AAB 30E4                    	xor	ah, ah
  2481 00000AAD BD0200                  	mov	bp, 2
  2482 00000AB0 E8C7FF                  	call	PrintNumber
  2483                                  	
  2484                                  	;mov	dh, 24
  2485                                  	;mov	dl, 36
  2486                                  	; 01/01/2025 (cgaplay.asm, video mode 13h)
  2487 00000AB3 B617                    	mov	dh, 23
  2488 00000AB5 B210                    	mov	dl, 16
  2489 00000AB7 E87CFF                  	call	setCursorPosition
  2490                                  
  2491 00000ABA 58                      	pop	ax ; **
  2492 00000ABB 88E0                    	mov	al, ah
  2493 00000ABD 30E4                    	xor	ah, ah
  2494                                  	; 21/12/2024
  2495 00000ABF BD0200                  	mov	bp, 2
  2496 00000AC2 EBB6                    	jmp	short PrintNumber
  2497                                  
  2498                                  ; --------------------------------------------------------
  2499                                  
  2500                                  	; 17/11/2024
  2501                                  	; 14/11/2024
  2502                                  CalcProgressTime:
  2503 00000AC4 A1[D014]                	mov	ax, [LoadedDataBytes]
  2504 00000AC7 8B16[D214]              	mov	dx, [LoadedDataBytes+2]
  2505 00000ACB 89C3                    	mov	bx, ax
  2506 00000ACD 09D3                    	or	bx, dx
  2507 00000ACF 740E                    	jz	short cpt_ok
  2508                                  
  2509 00000AD1 8B1E[5814]              	mov	bx, [WAVE_SampleRate]
  2510 00000AD5 F7F3                    	div	bx
  2511 00000AD7 31D2                    	xor	dx, dx
  2512 00000AD9 8B1E[6014]              	mov	bx, [WAVE_BlockAlign]
  2513 00000ADD F7F3                    	div	bx
  2514                                  cpt_ok:
  2515                                  	; ax = (new) progress time
  2516 00000ADF C3                      	retn
  2517                                  
  2518                                  ; --------------------------------------------------------
  2519                                  ; 14/11/2024
  2520                                  ; (Ref: player.asm, out_cs.asm, Matan Alfasi, 2017)
  2521                                  
  2522                                  ;; DESCRIPTION: Update file information on template
  2523                                  ;; PARAMS:	WAVE parameters and other variables
  2524                                  ;; REGS:	AX(RW)
  2525                                  ;; VARS:	CurrentFileName, WAVE_SampleRate, 
  2526                                  ;; RETURNS:	On-screen file info is updated.
  2527                                  
  2528                                  	; 01/01/2025 (cgaplay.asm)
  2529                                  UpdateFileInfo:
  2530                                  	;; Print File Name
  2531                                  	;mov	dh, 9
  2532                                  	;mov	dl, 23
  2533                                  	; 01/01/2025 (cgaplay.asm, video mode 13h)
  2534 00000AE0 B607                    	mov	dh, 7
  2535 00000AE2 B208                    	mov	dl, 8
  2536 00000AE4 E84FFF                  	call	setCursorPosition
  2537                                  	
  2538 00000AE7 BE[7214]                	mov	si, wav_file_name
  2539                                  	
  2540                                  	;;;
  2541                                  	; 14/11/2024
  2542                                  	; skip directory separators
  2543                                  	; (note: asciiz string, max. 79 bytes except zero tail)
  2544 00000AEA 89F3                    	mov	bx, si
  2545                                  chk4_nxt_sep:
  2546 00000AEC AC                      	lodsb
  2547 00000AED 3C5C                    	cmp	al, '\'
  2548 00000AEF 7406                    	je	short chg_fpos
  2549 00000AF1 20C0                    	and	al, al
  2550 00000AF3 7406                    	jz	short chg_fpos_ok
  2551 00000AF5 EBF5                    	jmp	short chk4_nxt_sep
  2552                                  chg_fpos:
  2553 00000AF7 89F3                    	mov	bx, si
  2554 00000AF9 EBF1                    	jmp	short chk4_nxt_sep
  2555                                  chg_fpos_ok:
  2556 00000AFB 89DE                    	mov	si, bx	; file name (without its path/directory)
  2557                                  	;;;
  2558                                  _fnl_chk:
  2559                                  	; 01/01/2025 (cplay.asm)
  2560                                  	; 30/12/2024 (cgaplay.s)
  2561                                  	; ????????.wav
  2562                                  	; 26/12/2024 (file name length limit -display-)
  2563 00000AFD BB0C00                  	mov	bx, 12
  2564                                  	;mov	bx, 17	; ????????.wav?????
  2565 00000B00 56                      	push	si
  2566                                  _fnl_chk_loop:
  2567 00000B01 AC                      	lodsb
  2568 00000B02 20C0                    	and	al, al
  2569 00000B04 7406                    	jz	short _fnl_ok
  2570 00000B06 4B                       	dec	bx
  2571 00000B07 75F8                    	jnz	short _fnl_chk_loop
  2572 00000B09 C60400                  	mov	byte [si], 0
  2573                                  _fnl_ok:
  2574 00000B0C 5E                      	pop	si
  2575                                  	;;;
  2576                                  
  2577 00000B0D E8CFF6                  	call	PrintString
  2578                                  	
  2579                                  	;; Print Frequency
  2580                                  	;mov	dh, 10
  2581                                  	;mov	dl, 23
  2582                                  	; 01/01/2025 (cgaplay.asm, video mode 13h)
  2583 00000B10 B608                    	mov	dh, 8
  2584 00000B12 B208                    	mov	dl, 8
  2585 00000B14 E81FFF                  	call	setCursorPosition
  2586                                  	 
  2587 00000B17 A1[5814]                	mov	ax, [WAVE_SampleRate]
  2588 00000B1A BD0500                  	mov	bp, 5
  2589 00000B1D E85AFF                  	call	PrintNumber
  2590                                  
  2591                                  	;; Print BitRate
  2592                                  	;mov	dh, 9
  2593                                  	;mov	dl, 57
  2594                                  	; 01/01/2025 (cgaplay.asm, video mode 13h)
  2595 00000B20 B607                    	mov	dh, 7
  2596 00000B22 B21F                    	mov	dl, 31
  2597 00000B24 E80FFF                  	call	setCursorPosition
  2598                                  
  2599 00000B27 A1[6214]                	mov	ax, [WAVE_BitsPerSample]
  2600 00000B2A BD0200                  	mov	bp, 2
  2601 00000B2D E84AFF                  	call	PrintNumber
  2602                                  
  2603                                  	;; Print Channel Number
  2604                                  	;mov	dh, 10
  2605                                  	;mov	dl, 57
  2606                                  	; 01/01/2025 (cgaplay.asm, video mode 13h)
  2607 00000B30 B608                    	mov	dh, 8
  2608 00000B32 B21F                    	mov	dl, 31
  2609 00000B34 E8FFFE                  	call	setCursorPosition
  2610                                  
  2611 00000B37 A1[5614]                	mov	ax, [WAVE_NumChannels]
  2612 00000B3A BD0100                  	mov	bp, 1
  2613 00000B3D E83AFF                  	call	PrintNumber
  2614                                  
  2615                                  	;call	UpdateVolume
  2616                                  	;retn
  2617                                  
  2618                                  ; --------------------------------------------------------
  2619                                  
  2620                                  	; 02/02/2025 (cgaplay2.asm) -SB16-
  2621                                  	; 01/01/2025 (cgaplay.asm) -AC97-
  2622                                  	; 14/11/2024
  2623                                  UpdateVolume:
  2624                                  	;; Print Volume
  2625                                  	;mov	dh, 24
  2626                                  	;mov	dl, 75
  2627                                  	; 01/01/2025 (cgaplay.asm, video mode 13h)
  2628 00000B40 B617                    	mov	dh, 23
  2629 00000B42 B223                    	mov	dl, 35
  2630 00000B44 E8EFFE                  	call	setCursorPosition
  2631                                  	
  2632 00000B47 A0[350A]                	mov	al, [volume]
  2633                                  
  2634 00000B4A B364                    	mov	bl, 100
  2635 00000B4C F6E3                    	mul	bl
  2636                                  
  2637                                  	;mov	bl, 31
  2638                                  	;div	bl
  2639                                  	; 02/01/2025 (SB16)
  2640 00000B4E B30F                    	mov	bl, 15
  2641 00000B50 F6F3                    	div	bl
  2642                                  
  2643                                  	;neg	ax
  2644                                  	;add	ax, 100
  2645                                  
  2646 00000B52 30E4                    	xor	ah, ah
  2647 00000B54 BD0300                  	mov	bp, 3
  2648                                  	;call	PrintNumber
  2649                                  	;retn
  2650 00000B57 E920FF                  	jmp	PrintNumber	
  2651                                  
  2652                                  ; --------------------------------------------------------
  2653                                  
  2654                                  	; 01/01/2025 (cgaplay.asm)
  2655                                  write_character_white:
  2656                                  	;mov	cx, 0Fh
  2657 00000B5A B30F                    	mov	bl, 0Fh
  2658                                  write_character:
  2659                                  	; 01/12/2024
  2660 00000B5C 30FF                    	xor	bh, bh
  2661                                  	; bl = foreground color
  2662                                  	; al = character (ASCII code)
  2663 00000B5E B40E                    	mov	ah, 0Eh
  2664 00000B60 CD10                    	int	10h
  2665 00000B62 C3                      	retn
  2666                                  
  2667                                  ; --------------------------------------------------------
  2668                                  
  2669                                  	; 01/01/2025 (cgaplay.asm)
  2670                                  	; 30/12/2024
  2671                                  	; write characters in video mode 13h
  2672                                  	; (320*200 pixels, 256 colors)
  2673                                  	; 22/12/2024
  2674                                  	; 21/12/2024
  2675                                  	; (write chars in VESA VBE graphics mode)
  2676                                  	; 14/11/2024
  2677                                  	; (Ref: player.asm, Matan Alfasi, 2017)
  2678                                  	; (Modification: Erdogan Tan, 14/11/2024)
  2679                                  
  2680                                  	;PROGRESSBAR_ROW equ 23
  2681                                  	; 21/12/2024 (640*480)
  2682                                  	;PROGRESSBAR_ROW equ 31
  2683                                  	; 30/12/2024 (320*200)
  2684                                  	PROGRESSBAR_ROW equ 22
  2685                                  
  2686                                  UpdateProgressBar:
  2687 00000B63 E831FF                  	call	SetProgressTime	; 14/11/2024
  2688                                  
  2689                                  	; 01/01/2025
  2690 00000B66 A1[CC14]                	mov	ax, [ProgressTime]
  2691                                  UpdateProgressBar@:
  2692                                  	;mov	dx, 80
  2693                                  	; 30/12/2024
  2694 00000B69 BA2800                  	mov	dx, 40 ; 320*200 pixels, 40 columns 
  2695 00000B6C F7E2                    	mul	dx
  2696 00000B6E 8B1E[CA14]              	mov	bx, [TotalTime]
  2697 00000B72 F7F3                    	div	bx
  2698                                  
  2699                                  	; 22/12/2024
  2700                                  	; check progress bar indicator position if it is same 
  2701 00000B74 3A06[A911]              	cmp	al, [pbprev]
  2702 00000B78 741E                    	je	short UpdateProgressBar_ok
  2703 00000B7A A2[A911]                	mov	[pbprev], al
  2704                                  
  2705                                  	; 01/01/2025
  2706                                  UpdateProgressBar@@:
  2707                                  	;; Push for the 'Clean' part
  2708 00000B7D 50                      	push	ax ; **
  2709 00000B7E 50                      	push	ax ; *
  2710                                  
  2711                                  	;; Set cursor position
  2712 00000B7F B616                    	mov	dh, PROGRESSBAR_ROW
  2713 00000B81 B200                    	mov	dl, 0
  2714 00000B83 E8B0FE                  	call	setCursorPosition
  2715                                  
  2716 00000B86 58                      	pop	ax ; *
  2717 00000B87 09C0                    	or	ax, ax
  2718 00000B89 741D                    	jz	short UpdateProgressBar_Clean
  2719                                  
  2720                                  	; 01/01/2025
  2721                                  UpdateProgressBar_DrawProgress:
  2722                                  	; 31/12/2024 (int 31h)
  2723                                  	; 22/12/2024
  2724                                  	; 21/12/2024
  2725                                  	; (write progress bar chars in graphics mode)
  2726                                  	;;;;
  2727 00000B8B 89C5                    	mov	bp, ax
  2728 00000B8D 50                      	push	ax ; ***
  2729                                  UpdateProgressBar_DrawProgress_@:
  2730                                  	; 01/01/2025
  2731 00000B8E B0DF                    	mov	al, 223
  2732                                  
  2733                                  	; al = character
  2734                                  	;call	write_character
  2735                                  	; 22/12/2024
  2736 00000B90 E8C7FF                  	call	write_character_white
  2737                                  
  2738 00000B93 4D                      	dec	bp
  2739 00000B94 7403                    	jz	short UpdateProgressBar_DrawCursor
  2740 00000B96 EBF6                    	jmp	short UpdateProgressBar_DrawProgress_@
  2741                                  
  2742                                  UpdateProgressBar_ok:
  2743 00000B98 C3                      	retn
  2744                                  
  2745                                  	; 01/01/2025
  2746                                  UpdateProgressBar_DrawCursor:
  2747                                  	; 22/12/2024
  2748 00000B99 5A                      	pop	dx ; ***
  2749 00000B9A B616                    	mov	dh, PROGRESSBAR_ROW
  2750                                  	; 31/12/2024
  2751 00000B9C FECA                    	dec	dl ; last written position again
  2752 00000B9E E895FE                  	call	setCursorPosition
  2753                                  
  2754                                  	; 01/01/2025	
  2755 00000BA1 B0DF                    	mov	al, 223
  2756                                  	;mov	cl, 0Ch ; red
  2757                                  	; 01/01/2025
  2758 00000BA3 B30C                    	mov	bl, 0Ch
  2759 00000BA5 E8B4FF                  	call	write_character
  2760                                  
  2761                                  	; 01/01/2025
  2762                                  UpdateProgressBar_Clean:
  2763                                  	;pop	ax  ; **
  2764                                  	; 22/12/2024
  2765 00000BA8 5A                      	pop	dx  ; **
  2766                                  	; 30/12/2024
  2767                                  	; 21/12/2024
  2768                                  	;mov	bp, 80
  2769                                  	; 30/12/2024
  2770 00000BA9 BD2800                  	mov	bp, 40 ; 40 columns (320*200 pixels)
  2771                                  	;sub	bp, ax
  2772 00000BAC 29D5                    	sub	bp, dx ; 22/12/2024
  2773                                  	;jz	short UpdateProgressBar_ok
  2774                                  	; 31/12/2024
  2775 00000BAE 76E8                    	jna	short UpdateProgressBar_ok
  2776                                  
  2777 00000BB0 B616                    	mov	dh, PROGRESSBAR_ROW
  2778                                  	;mov	dl, al ; 22/12/2024
  2779 00000BB2 E881FE                  	call	setCursorPosition
  2780                                  
  2781                                  	; 21/12/2024
  2782                                  	; (write progress bar chars in graphics mode)
  2783                                  UpdateProgressBar_Clean_@:
  2784                                  	; 01/01/2025	
  2785 00000BB5 B0DF                    	mov	al, 223
  2786                                  	;mov	cl, 08h ; gray (dark)
  2787 00000BB7 B308                    	mov	bl, 08h
  2788 00000BB9 E8A0FF                  	call	write_character
  2789                                  	
  2790 00000BBC 4D                      	dec	bp
  2791 00000BBD 74D9                    	jz	short UpdateProgressBar_ok
  2792 00000BBF EBF4                    	jmp	short UpdateProgressBar_Clean_@
  2793                                  
  2794                                  ; --------------------------------------------------------
  2795                                  ; 17/11/2024
  2796                                  
  2797                                  Player_ProcessKey_Backwards:
  2798                                  	;; In order to go backwards 5 seconds:
  2799                                  	;; Update file pointer to the beginning, skip headers
  2800 00000BC1 B142                    	mov	cl, 'B'
  2801 00000BC3 EB02                    	jmp	short Player_ProcessKey_B_or_F
  2802                                  
  2803                                  Player_ProcessKey_Forwards:
  2804                                  	;; In order to fast-forward 5 seconds, set the file pointer
  2805                                  	;; to CUR_SEEK + 5 * Freq
  2806                                  
  2807 00000BC5 B146                    	mov	cl, 'F'
  2808                                  	;jmp	short Player_ProcessKey_B_or_F
  2809                                  
  2810                                  	; 01/01/2025 (cgaplay.asm, 16bit registers)
  2811                                  	; 01/12/2024 (32bit registers)
  2812                                  Player_ProcessKey_B_or_F:
  2813                                  	; 17/11/2024
  2814                                  	; 04/11/2024
  2815                                  	; (Ref: player.asm, Matan Alfasi, 2017)
  2816                                    
  2817                                  	; 04/11/2024
  2818 00000BC7 B80500                  	mov	ax, 5
  2819 00000BCA 8B1E[6014]              	mov	bx, [WAVE_BlockAlign]
  2820 00000BCE F7E3                    	mul	bx
  2821 00000BD0 8B1E[5814]              	mov	bx, [WAVE_SampleRate]
  2822 00000BD4 F7E3                    	mul	bx
  2823                                  	; dx:ax = transfer byte count for 5 seconds
  2824                                  	
  2825                                  	; 17/11/2024
  2826 00000BD6 80F942                  	cmp	cl, 'B'
  2827 00000BD9 8B1E[D014]              	mov	bx, [LoadedDataBytes]
  2828 00000BDD 8B0E[D214]              	mov	cx, [LoadedDataBytes+2]
  2829 00000BE1 750C                    	jne	short move_forward ; cl = 'F'
  2830                                  move_backward:
  2831 00000BE3 29C3                    	sub	bx, ax
  2832 00000BE5 19D1                    	sbb	cx, dx
  2833 00000BE7 7322                    	jnc	short move_file_pointer
  2834                                  move_to_beginning:
  2835 00000BE9 31C9                    	xor	cx, cx ; 0
  2836 00000BEB 31DB                    	xor	bx, bx ; 0
  2837 00000BED EB1C                    	jmp	short move_file_pointer
  2838                                  move_forward: 
  2839 00000BEF 01C3                    	add	bx, ax
  2840 00000BF1 11D1                    	adc	cx, dx
  2841 00000BF3 720E                    	jc	short move_to_end
  2842 00000BF5 3B0E[6A14]              	cmp	cx, [DATA_SubchunkSize+2]
  2843 00000BF9 7708                    	ja	short move_to_end
  2844 00000BFB 720E                    	jb	short move_file_pointer
  2845 00000BFD 3B1E[6814]              	cmp	bx, [DATA_SubchunkSize]
  2846 00000C01 7608                    	jna	short move_file_pointer
  2847                                  move_to_end:
  2848 00000C03 8B1E[6814]              	mov	bx, [DATA_SubchunkSize]
  2849 00000C07 8B0E[6A14]              	mov	cx, [DATA_SubchunkSize+2]
  2850                                  move_file_pointer:
  2851 00000C0B 89DA                    	mov	dx, bx    
  2852 00000C0D 8916[D014]              	mov	[LoadedDataBytes], dx
  2853 00000C11 890E[D214]              	mov	[LoadedDataBytes+2], cx
  2854 00000C15 83C22C                  	add	dx, 44 ; + header
  2855 00000C18 83D100                  	adc	cx, 0
  2856                                  
  2857                                  	; seek
  2858 00000C1B 8B1E[6E14]              	mov	bx, [filehandle]
  2859 00000C1F B80042                  	mov	ax, 4200h
  2860 00000C22 CD21                    	int	21h
  2861                                  	
  2862 00000C24 C3                      	retn
  2863                                  
  2864                                  ; --------------------------------------------------------
  2865                                  
  2866                                  	; 01/01/2025 (cgaplay.asm)
  2867                                  	; (video mode 13h, 320*200, 256 colors)
  2868                                  clear_window:
  2869 00000C25 06                      	push	es
  2870 00000C26 BF00A0                  	mov	di, 0A000h
  2871 00000C29 8EC7                    	mov	es, di
  2872 00000C2B BF8070                  	mov	di, (11*8*320)+(2*320) ; AC97 info start 
  2873 00000C2E 29C0                    	sub	ax, ax
  2874 00000C30 B90032                  	mov	cx, (10*8*320)/2
  2875 00000C33 F3AB                    	rep	stosw
  2876 00000C35 A3[AA11]                	mov	[prev_points], ax ; 0
  2877 00000C38 07                      	pop	es
  2878 00000C39 C3                      	retn
  2879                                  
  2880                                  ; -------------------------------------------------------------
  2881                                  ; DATA (INFO)
  2882                                  ; -------------------------------------------------------------
  2883                                  
  2884                                  ; 02/01/2025
  2885                                  
  2886                                  Credits:
  2887 00000C3A 564741205741562050-     	db 'VGA WAV Player for Retro DOS by Erdogan Tan. '
  2887 00000C43 6C6179657220666F72-
  2887 00000C4C 20526574726F20444F-
  2887 00000C55 53206279204572646F-
  2887 00000C5E 67616E2054616E2E20 
  2888                                  	;db 'January 2025.',10,13,0
  2889 00000C67 466562727561727920-     	db 'February 2025.',10,13,0
  2889 00000C70 323032352E0A0D00   
  2890 00000C78 30322F30312F323032-     	db '02/01/2025', 10,13,0
  2890 00000C81 350A0D00           
  2891 00000C85 32332F30312F323032-     	db '23/01/2025', 10,13,0
  2891 00000C8E 350A0D00           
  2892 00000C92 30372F30322F323032-     	db '07/02/2025', 10,13,0
  2892 00000C9B 350A0D00           
  2893                                  
  2894                                  msgAudioCardInfo:
  2895 00000C9F 666F7220536F756E64-     	db  'for Sound Blaster 16 audio device.', 10,13,0
  2895 00000CA8 20426C617374657220-
  2895 00000CB1 313620617564696F20-
  2895 00000CBA 6465766963652E0A0D-
  2895 00000CC3 00                 
  2896                                  
  2897                                  	; 02/01/2025
  2898                                  msg_usage:
  2899 00000CC4 75736167653A204347-     	db 'usage: CGAPLAY2 <FileName1> <FileName2> <...>',10,13,0
  2899 00000CCD 41504C415932203C46-
  2899 00000CD6 696C654E616D65313E-
  2899 00000CDF 203C46696C654E616D-
  2899 00000CE8 65323E203C2E2E2E3E-
  2899 00000CF1 0A0D00             
  2900                                  
  2901                                  	; 24/11/2024
  2902                                  noDevMsg:
  2903 00000CF4 4572726F723A20556E-     	db 'Error: Unable to find Sound Blaster 16 audio device!'
  2903 00000CFD 61626C6520746F2066-
  2903 00000D06 696E6420536F756E64-
  2903 00000D0F 20426C617374657220-
  2903 00000D18 313620617564696F20-
  2903 00000D21 64657669636521     
  2904 00000D28 0A0D00                  	db 10,13,0
  2905                                  
  2906                                  noFileErrMsg:
  2907 00000D2B 4572726F723A206669-     	db 'Error: file not found.',10,13,0
  2907 00000D34 6C65206E6F7420666F-
  2907 00000D3D 756E642E0A0D00     
  2908                                  
  2909                                  msg_error: ; 30/05/2024
  2910                                  
  2911                                  ; 24/11/2024
  2912                                  msg_init_err:
  2913 00000D44 0D0A                    	db 0Dh, 0Ah
  2914 00000D46 536F756E6420426C61-     	db "Sound Blaster 16 hardware initialization error !"
  2914 00000D4F 737465722031362068-
  2914 00000D58 617264776172652069-
  2914 00000D61 6E697469616C697A61-
  2914 00000D6A 74696F6E206572726F-
  2914 00000D73 722021             
  2915 00000D76 0D0A00                  	db 0Dh, 0Ah, 0
  2916                                  
  2917                                  ; 19/11/2024
  2918                                  ; 03/06/2017
  2919                                  hex_chars:
  2920 00000D79 303132333435363738-     	db "0123456789ABCDEF", 0
  2920 00000D82 3941424344454600   
  2921                                  
  2922                                  ; 24/11/2024
  2923                                  msgSB16Info:
  2924 00000D8A 0D0A                    	db 0Dh, 0Ah
  2925 00000D8C 20417564696F204861-     	db " Audio Hardware: Sound Blaster 16", 0Dh, 0Ah 
  2925 00000D95 7264776172653A2053-
  2925 00000D9E 6F756E6420426C6173-
  2925 00000DA7 7465722031360D0A   
  2926 00000DAF 202020202020426173-     	db "      Base Port: "
  2926 00000DB8 6520506F72743A20   
  2927                                  msgBasePort:
  2928 00000DC0 303030680D0A            	db "000h", 0Dh, 0Ah 
  2929 00000DC6 202020202020202020-     	db "            IRQ: "
  2929 00000DCF 2020204952513A20   
  2930                                  msgIRQ:
  2931 00000DD7 30                      	db 30h
  2932 00000DD8 0D0A00                  	db 0Dh, 0Ah, 0
  2933                                  
  2934 00000DDB 90                      align 4
  2935                                  
  2936                                  ; -------------------------------------------------------------
  2937                                  
  2938                                  	; 30/12/2024
  2939                                  PlayingScreen:
  2940 00000DDC DBDBDBDBDBDBDBDBDB-     	db  14 dup(219), " DOS Player ", 14 dup(219)
  2940 00000DE5 DBDBDBDBDB20444F53-
  2940 00000DEE 20506C6179657220DB-
  2940 00000DF7 DBDBDBDBDBDBDBDBDB-
  2940 00000E00 DBDBDBDB           
  2941 00000E04 C9CDCDCDCDCDCDCDCD-     	db  201, 38 dup(205), 187
  2941 00000E0D CDCDCDCDCDCDCDCDCD-
  2941 00000E16 CDCDCDCDCDCDCDCDCD-
  2941 00000E1F CDCDCDCDCDCDCDCDCD-
  2941 00000E28 CDCDCDBB           
  2942 00000E2C BA203C53706163653E-     	db  186, " <Space> Play/Pause <N>/<P> Next/Prev ", 186
  2942 00000E35 20506C61792F506175-
  2942 00000E3E 7365203C4E3E2F3C50-
  2942 00000E47 3E204E6578742F5072-
  2942 00000E50 657620BA           
  2943 00000E54 BA203C533E20202020-     	db  186, " <S>     Stop       <Enter> Color     ", 186
  2943 00000E5D 2053746F7020202020-
  2943 00000E66 2020203C456E746572-
  2943 00000E6F 3E20436F6C6F722020-
  2943 00000E78 202020BA           
  2944 00000E7C BA203C463E20202020-     	db  186, " <F>     Forwards   <+>/<-> Volume    ", 186
  2944 00000E85 20466F727761726473-
  2944 00000E8E 2020203C2B3E2F3C2D-
  2944 00000E97 3E20566F6C756D6520-
  2944 00000EA0 202020BA           
  2945 00000EA4 BA203C423E20202020-     	db  186, " <B>     Backwards  <Q>     Quit Prg  ", 186
  2945 00000EAD 204261636B77617264-
  2945 00000EB6 7320203C513E202020-
  2945 00000EBF 202051756974205072-
  2945 00000EC8 672020BA           
  2946 00000ECC CCCDCDCDCDCDCDCDCD-     	db  204, 38 dup(205), 185
  2946 00000ED5 CDCDCDCDCDCDCDCDCD-
  2946 00000EDE CDCDCDCDCDCDCDCDCD-
  2946 00000EE7 CDCDCDCDCDCDCDCDCD-
  2946 00000EF0 CDCDCDB9           
  2947 00000EF4 BA2046696C653A2020-     	db  186, " File:              Bits:     0       ", 186
  2947 00000EFD 202020202020202020-
  2947 00000F06 202020426974733A20-
  2947 00000F0F 202020203020202020-
  2947 00000F18 202020BA           
  2948 00000F1C BA20467265713A2030-     	db  186, " Freq: 0     Hz     Channels: 0       ", 186
  2948 00000F25 2020202020487A2020-
  2948 00000F2E 2020204368616E6E65-
  2948 00000F37 6C733A203020202020-
  2948 00000F40 202020BA           
  2949 00000F44 C8CDCDCDCDCDCDCDCD-     	db  200, 38 dup(205), 188
  2949 00000F4D CDCDCDCDCDCDCDCDCD-
  2949 00000F56 CDCDCDCDCDCDCDCDCD-
  2949 00000F5F CDCDCDCDCDCDCDCDCD-
  2949 00000F68 CDCDCDBC           
  2950 00000F6C 202020202020202020-     	db  40 dup(32)
  2950 00000F75 202020202020202020-
  2950 00000F7E 202020202020202020-
  2950 00000F87 202020202020202020-
  2950 00000F90 20202020           
  2951                                  improper_samplerate_txt:
  2952                                  read_error_txt:
  2953 00000F94 202020202020202020-     	db  40 dup(32)
  2953 00000F9D 202020202020202020-
  2953 00000FA6 202020202020202020-
  2953 00000FAF 202020202020202020-
  2953 00000FB8 20202020           
  2954 00000FBC 202020202020202020-     	db  40 dup(32)
  2954 00000FC5 202020202020202020-
  2954 00000FCE 202020202020202020-
  2954 00000FD7 202020202020202020-
  2954 00000FE0 20202020           
  2955 00000FE4 202020202020202020-     	db  40 dup(32)
  2955 00000FED 202020202020202020-
  2955 00000FF6 202020202020202020-
  2955 00000FFF 202020202020202020-
  2955 00001008 20202020           
  2956 0000100C 202020202020202020-     	db  40 dup(32)
  2956 00001015 202020202020202020-
  2956 0000101E 202020202020202020-
  2956 00001027 202020202020202020-
  2956 00001030 20202020           
  2957 00001034 202020202020202020-     	db  40 dup(32)
  2957 0000103D 202020202020202020-
  2957 00001046 202020202020202020-
  2957 0000104F 202020202020202020-
  2957 00001058 20202020           
  2958 0000105C 202020202020202020-     	db  40 dup(32)
  2958 00001065 202020202020202020-
  2958 0000106E 202020202020202020-
  2958 00001077 202020202020202020-
  2958 00001080 20202020           
  2959 00001084 202020202020202020-     	db  40 dup(32)
  2959 0000108D 202020202020202020-
  2959 00001096 202020202020202020-
  2959 0000109F 202020202020202020-
  2959 000010A8 20202020           
  2960 000010AC 202020202020202020-     	db  40 dup(32)
  2960 000010B5 202020202020202020-
  2960 000010BE 202020202020202020-
  2960 000010C7 202020202020202020-
  2960 000010D0 20202020           
  2961 000010D4 202020202020202020-     	db  40 dup(32)
  2961 000010DD 202020202020202020-
  2961 000010E6 202020202020202020-
  2961 000010EF 202020202020202020-
  2961 000010F8 20202020           
  2962 000010FC 202020202020202020-     	db  40 dup(32)
  2962 00001105 202020202020202020-
  2962 0000110E 202020202020202020-
  2962 00001117 202020202020202020-
  2962 00001120 20202020           
  2963 00001124 CDCDCDCDCDCDCDCDCD-     	db  40 dup(205)
  2963 0000112D CDCDCDCDCDCDCDCDCD-
  2963 00001136 CDCDCDCDCDCDCDCDCD-
  2963 0000113F CDCDCDCDCDCDCDCDCD-
  2963 00001148 CDCDCDCD           
  2964 0000114C 202020202020202020-     	db  40 dup(32)
  2964 00001155 202020202020202020-
  2964 0000115E 202020202020202020-
  2964 00001167 202020202020202020-
  2964 00001170 20202020           
  2965 00001174 202020202020202020-     	db  13 dup(32), "00:00 ", 174, 175, " 00:00", 4 dup(32), "VOL 000%"
  2965 0000117D 2020202030303A3030-
  2965 00001186 20AEAF2030303A3030-
  2965 0000118F 20202020564F4C2030-
  2965 00001198 303025             
  2966                                  	;db  40 dup(32) ; not necessary
  2967 0000119B 00                      	db 0
  2968                                  
  2969                                  ; -------------------------------------------------------------
  2970                                  
  2971                                  ; 31/12/2024
  2972                                  	; 30/12/2024
  2973                                  ;fillblock:
  2974                                  ;	times 8 db 0FFh
  2975                                  ;	dw 0
  2976                                  
  2977                                  ; -------------------------------------------------------------
  2978                                  
  2979                                  ; 30/12/2024
  2980                                  ; 23/11/2024
  2981                                  colors:
  2982 0000119C 0F0B0A0C0E090D          	db 0Fh, 0Bh, 0Ah, 0Ch, 0Eh, 09h, 0Dh
  2983                                  	; white, cyan, green, red, yellow, blue, magenta
  2984 000011A3 0B                      ccolor:	db 0Bh	; cyan
  2985                                  
  2986                                  ; -------------------------------------------------------------
  2987                                  
  2988                                  ; 02/05/2024
  2989                                  ; 24/11/2024
  2990                                  half_buffer:
  2991 000011A4 01                      	db 1	; dma half buffer 1 or 2 (0 or 1)
  2992                                  		; (initial value = 1 -> after xor in TuneLoop -> 0)
  2993                                  EOF: 
  2994                                  
  2995                                  ; -------------------------------------------------------------
  2996                                  
  2997                                  bss:
  2998                                  
  2999                                  ABSOLUTE bss
  3000                                  
  3001                                  ; 02/01/2025 (SB16 modifications) -cgaplay2.asm-
  3002                                  ; 01/01/2025 (16bit modifications) -AC97, cgaplay.asm-
  3003                                  
  3004 000011A5 ??                      alignb 2
  3005                                  
  3006                                  ; 24/12/2024
  3007                                  wpoints_dif:	; wave lighting points factor (differential) 
  3008 000011A6 ????                    	resw 1	; required bytes for 1/18 second wave lighting
  3009                                  ; 01/01/2025
  3010                                  ;graphstart:
  3011                                  ;	resw 1	; start (top) line/row for wave lighting points 	 
  3012                                  
  3013                                  columns:
  3014 000011A8 ??                      	resb 1
  3015 000011A9 ??                      pbprev:	resb 1 ; previous progress bar indicator position
  3016                                  
  3017                                  ;alignb 2
  3018                                  
  3019                                  bss_start:
  3020                                  
  3021                                  ; 30/12/2024
  3022                                  prev_points:
  3023 000011AA <res 280h>              	resw 320 ; previous wave points (which are lighting)
  3024                                  
  3025                                  ; 02/01/2025
  3026                                  ; 24/11/2024
  3027                                  old_irq5v_o:
  3028 0000142A ????                    	resw 1
  3029                                  old_irq5v_s:
  3030 0000142C ????                    	resw 1
  3031                                  old_irq7v_o:
  3032 0000142E ????                    	resw 1
  3033                                  old_irq7v_s:
  3034 00001430 ????                    	resw 1
  3035                                  ;
  3036 00001432 ??                      IRQnum:	resb 1
  3037                                  ; 27/11/2024
  3038                                  audio_intr:
  3039 00001433 ??                      	resb 1
  3040                                  ; 25/11/2024
  3041                                  IRQstatus:
  3042 00001434 ??                      	resb 1	
  3043                                  
  3044                                  ; 18/11/2024
  3045                                  stopped:
  3046 00001435 ??                      	resb 1
  3047 00001436 ??                      tLO:	resb 1
  3048                                  ; 21/11/2024
  3049                                  ;tLP:	resb 1
  3050                                  ; 30/12/2024
  3051                                  wpoints:
  3052 00001437 ??                      	resb 1
  3053 00001438 ????                    pbuf_o:	resw 1
  3054                                  ; 29/12/2024
  3055 0000143A ????                    pbuf_s:	resw 1
  3056                                  
  3057                                  ; 25/12/2024
  3058                                  ; 29/11/2024
  3059                                  command:
  3060 0000143C ??                      	resb 1
  3061                                  filecount:
  3062 0000143D ??                      	resb 1
  3063                                  
  3064                                  ; 30/11/2024
  3065 0000143E ????                    alignb 4
  3066                                  
  3067                                  ;;;;;;;;;;;;;;
  3068                                  ; 14/11/2024
  3069                                  ; (Ref: player.asm, Matan Alfasi, 2017)  
  3070                                  WAVFILEHEADERbuff:
  3071                                  RIFF_ChunkID:
  3072 00001440 ????????                	resd 1	; Must be equal to "RIFF" - big-endian
  3073                                  		; 0x52494646
  3074                                  RIFF_ChunkSize:
  3075 00001444 ????????                	resd 1	; Represents total file size, not 
  3076                                          	; including the first 2 fields 
  3077                                  		; (Total_File_Size - 8), little-endian
  3078                                  RIFF_Format:
  3079 00001448 ????????                	resd 1	; Must be equal to "WAVE" - big-endian
  3080                                  		; 0x57415645
  3081                                  
  3082                                  ;; WAVE header parameters ("Sub-chunk")
  3083                                  WAVE_SubchunkID:
  3084 0000144C ????????                	resd 1	; Must be equal to "fmt " - big-endian
  3085                                  		; 0x666d7420
  3086                                  WAVE_SubchunkSize:
  3087 00001450 ????????                	resd 1	; Represents total chunk size
  3088                                  WAVE_AudioFormat:
  3089 00001454 ????                    	resw 1	; PCM (Raw) - is 1, other - is a form 
  3090                                  		; of compression, not supported.
  3091                                  WAVE_NumChannels:
  3092 00001456 ????                    	resw 1	; Number of channels, Mono-1, Stereo-2
  3093                                  WAVE_SampleRate:
  3094 00001458 ????????                	resd 1	; Frequency rate, in Hz (8000, 44100 ...)
  3095                                  WAVE_ByteRate:
  3096 0000145C ????????                	resd 1	; SampleRate * NumChannels * BytesPerSample
  3097                                  WAVE_BlockAlign:
  3098 00001460 ????                    	resw 1	; NumChannels * BytesPerSample
  3099                                  		; Number of bytes for one sample.
  3100                                  WAVE_BitsPerSample:
  3101 00001462 ????                    	resw 1	; 8 = 8 bits, 16 = 16 bits, etc.
  3102                                  
  3103                                  ;; DATA header parameters
  3104                                  DATA_SubchunkID:
  3105 00001464 ????????                	resd 1	; Must be equal to "data" - big-endian
  3106                                          	; 0x64617461
  3107                                  DATA_SubchunkSize:
  3108 00001468 ????????                	resd 1	; NumSamples * NumChannels * BytesPerSample
  3109                                          	; Number of bytes in the data.
  3110                                  ;;;;;;;;;;;;;;
  3111                                  
  3112                                  ; 01/01/2025
  3113                                  
  3114 0000146C ??                      flags:	resb 1
  3115                                  ; 06/11/2023
  3116                                  ac97_int_ln_reg:
  3117 0000146D ??                      	resb 1
  3118                                  filehandle:
  3119 0000146E ????                    	resw 1
  3120                                  
  3121                                  ; 01/01/2025
  3122                                  ; 28/11/2024
  3123                                  PSP_CurrentOffset:
  3124 00001470 ????                    	resw 1
  3125                                  
  3126                                  ; 30/05/2024
  3127                                  wav_file_name:
  3128 00001472 <res 50h>               	resb 80	; wave file, path name (<= 80 bytes)
  3129 000014C2 ????                    	resw 1	; 30/11/2024
  3130                                  
  3131                                  ; 08/11/2023
  3132                                  ; 07/11/2023
  3133                                  fbs_shift:
  3134 000014C4 ??                      	resb 1
  3135                                  ; 07/12/2024
  3136 000014C5 ??                      SRB:	resb 1
  3137                                  
  3138                                  ; 02/01/2025
  3139                                  audio_io_base:
  3140 000014C6 ????                    	resw 1	; Sound Blaster 16 base port address (220h)
  3141                                  
  3142                                  ; 02/01/2025
  3143                                  UpdateWavePoints:
  3144 000014C8 ????                    	resw 1	; wave lighting procedure pointer (8m,16m,8s,16s)
  3145                                  		
  3146                                  ; 01/01/2025
  3147                                  ; 14/11/2024
  3148                                  TotalTime:
  3149 000014CA ????                    	resw 1	; Total (WAV File) Playing Time in seconds
  3150                                  ProgressTime:
  3151 000014CC ????                    	resw 1
  3152 000014CE ????                    count:	resw 1	; byte count of one (wav file) read
  3153                                  LoadedDataBytes:
  3154 000014D0 ????????                	resd 1	; total read/load count
  3155                                  
  3156                                  timerticks:
  3157 000014D4 ????????                	resd 1	; (to eliminate excessive lookup of events in tuneloop)
  3158                                  		; (in order to get the emulator/qemu to run correctly)
  3159 000014D8 ????????????????        alignb 16
  3160                                  
  3161                                  ; 02/01/2025
  3162                                  ; 24/11/2024
  3163                                  dma_buffer:	; 32768 bytes	
  3164                                  wav_buffer1:
  3165 000014E0 <res 5622h>             	resb dma_buffer_size/2 ; 16384
  3166                                  wav_buffer2:
  3167 00006B02 <res 5622h>             	resb dma_buffer_size/2 ; 16384
  3168                                  
  3169                                  ; 14/11/2024
  3170                                  bss_end:
