Przeglądaj źródła

Bugfix for SDL2 + clean

Yann Weber 5 lat temu
rodzic
commit
7db3e44299
2 zmienionych plików z 90 dodań i 25 usunięć
  1. 5
    3
      sdl.asm
  2. 85
    22
      yaglitch.asm

+ 5
- 3
sdl.asm Wyświetl plik

@@ -8,9 +8,6 @@ Extern SDL_PauseAudio
8 8
 Extern SDL_WaitEvent
9 9
 Extern SDL_GetError
10 10
 
11
-;Extern SDL_QUIT
12
-;Extern SDL_AUDIODEVICEADDED
13
-
14 11
 %ifdef SDL1
15 12
 	%define SDL_QUIT 0x0C
16 13
 %endif
@@ -18,9 +15,14 @@ Extern SDL_GetError
18 15
 	%define SDL_QUIT 0x100
19 16
 	%define SDL_AUDIODEVICEADDED 0x1100
20 17
 %endif
18
+%ifdef MIX_AUDIO
19
+	Extern SDL_MixAudio
20
+	%define SDL_MAX_VOLUME 128
21
+%endif
21 22
 
22 23
 %define SDL_SWSURFACE 0
23 24
 
25
+
24 26
 %define AUDIO_U8        0x0008  ; Unsigned 8-bit samples 
25 27
 %define AUDIO_S8        0x8008  ; Signed 8-bit samples 
26 28
 %define AUDIO_U16LSB    0x0010  ; Unsigned 16-bit samples 

+ 85
- 22
yaglitch.asm Wyświetl plik

@@ -92,8 +92,13 @@ section .bss
92 92
 	%ifdef SDL1
93 93
 		event: resb 24
94 94
 	%endif
95
-	%ifdef SDL 2
95
+	%ifdef SDL2
96 96
 		event: resb 56
97
+		evt_cnt: resb 1
98
+	%endif
99
+	%ifdef MIX_AUDIO
100
+		cllbck_heap: resq 1
101
+		cllbck_heapsz: resw 1
97 102
 	%endif
98 103
 
99 104
 section .text
@@ -358,11 +363,19 @@ dbginit:
358 363
 	;xor rcx, rcx
359 364
 	;call SDL_SetVideoMode
360 365
 
361
-%ifdef SDL1
362 366
 	audio_start:
363 367
 		;start audio
364 368
 		xor rdi, rdi
365 369
 		call SDL_PauseAudio
370
+%ifdef MIX_AUDIO
371
+	; init callback heap infos
372
+	mov rax, 0xc ; brk
373
+	xor rdi, rdi ; get heap start addr
374
+	mov [cllbck_heapsz], rdi
375
+	syscall
376
+	cmp rax, -1
377
+	je exit_fatal
378
+	mov [cllbck_heap], rax
366 379
 %endif
367 380
 
368 381
 loop_event:
@@ -387,21 +400,12 @@ loop_event:
387 400
 %endif
388 401
 %ifdef SDL2
389 402
 		mov edi, [event]
390
-		cmp edi, SDL_AUDIODEVICEADDED
391
-		je sdl2_audiostart
392 403
 		cmp edi, SDL_QUIT
393 404
 		je exit
394 405
 %endif
395 406
 
396 407
 	jmp loop_event
397 408
 
398
-%ifdef SDL2
399
-	sdl2_audiostart:
400
-		xor rdi, rdi
401
-		call SDL_PauseAudio
402
-		jmp loop_event
403
-%endif
404
-
405 409
 sdl_error:
406 410
 	; display error & exit
407 411
 	call SDL_GetError
@@ -415,6 +419,10 @@ sdl_error:
415 419
 	mov rdi, 0xF
416 420
 	jmp exit.exit_err
417 421
 
422
+exit_fatal:
423
+	mov rdi, 42
424
+	jmp exit.exit_err
425
+
418 426
 exit:
419 427
 	call SDL_Quit
420 428
 
@@ -604,23 +612,78 @@ print_hnum:
604 612
 		add al, "A" - 10
605 613
 		ret
606 614
 
615
+%ifndef MIX_AUDIO
616
+; simplest/shortes audio_callback : copy byte returned by run_glitch in *stream
607 617
 audio_cllbck:
608 618
 	; rdi -> *userdata
609 619
 	; rsi -> *stream
610 620
 	; rdx -> stream_len
611
-	mov rcx, rdx
612
-	mov rdi, rsi
613
-	.loop:
614
-		push rcx
621
+	%ifdef SDL2
622
+		push rbx ; strange, but nescessary...
623
+	%endif
624
+		mov rcx, rdx
625
+		mov rdi, rsi
626
+		.loop:
627
+			push rcx
628
+			push rdi
629
+			call run_glitch
630
+			pop rdi
631
+			stosb
632
+			pop rcx
633
+			inc dword [t]
634
+			loop .loop
635
+	%ifdef SDL2
636
+		pop rbx ; if rbx change SDL2 segfault :/
637
+	%endif
638
+		ret
639
+%endif
640
+%ifdef MIX_AUDIO
641
+; another version of the audio callback using heap to store the data
642
+; and SDL_MixAudio to copy data in *stream
643
+audio_cllbck:
644
+	; rdi -> *userdata
645
+	; rsi -> *stream
646
+	; rdx -> stream_len
647
+	push rbx
648
+	mov rcx, [cllbck_heapsz]
649
+	cmp rcx, rdx
650
+	jle .heap_brk
651
+	.continue:
652
+		mov rdi, [cllbck_heap]
653
+		push rdx ; len
615 654
 		push rdi
616
-		call run_glitch
655
+		push rsi ; *stream, dst
656
+		mov rcx, rdx
657
+		.pop_loop: ; populating heap with glitch datas
658
+			push rcx
659
+			push rdi
660
+			call run_glitch
661
+			pop rdi
662
+			stosb
663
+			pop rcx
664
+			inc dword [t]
665
+			loop .pop_loop
666
+		pop rdi ; *stream
667
+		pop rsi ; heap_start
668
+		pop rdx ; len
669
+		mov rcx, SDL_MAX_VOLUME
670
+		pop rbx
671
+		ret
672
+	.heap_brk: ; resize heap to handle 
673
+		push rdi
674
+		push rsi
675
+		push rdx
676
+		mov rdi, [cllbck_heap]
677
+		add rdi, rdx
678
+		sub rdi, rcx
679
+		mov rax, 0xc ; brk
680
+		syscall
681
+		mov [cllbck_heap], rax
682
+		pop rdx
683
+		pop rsi
617 684
 		pop rdi
618
-		stosb
619
-		pop rcx
620
-		inc dword [t]
621
-		loop .loop
622
-dbg0:
623
-	ret
685
+		jmp .continue
686
+%endif
624 687
 
625 688
 run_glitch:
626 689
 	; Run the glitch_pgm

Loading…
Anuluj
Zapisz