Browse Source

Bugfix for SDL2 + clean

Yann Weber 5 years ago
parent
commit
7db3e44299
2 changed files with 90 additions and 25 deletions
  1. 5
    3
      sdl.asm
  2. 85
    22
      yaglitch.asm

+ 5
- 3
sdl.asm View File

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

+ 85
- 22
yaglitch.asm View File

92
 	%ifdef SDL1
92
 	%ifdef SDL1
93
 		event: resb 24
93
 		event: resb 24
94
 	%endif
94
 	%endif
95
-	%ifdef SDL 2
95
+	%ifdef SDL2
96
 		event: resb 56
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
 	%endif
102
 	%endif
98
 
103
 
99
 section .text
104
 section .text
358
 	;xor rcx, rcx
363
 	;xor rcx, rcx
359
 	;call SDL_SetVideoMode
364
 	;call SDL_SetVideoMode
360
 
365
 
361
-%ifdef SDL1
362
 	audio_start:
366
 	audio_start:
363
 		;start audio
367
 		;start audio
364
 		xor rdi, rdi
368
 		xor rdi, rdi
365
 		call SDL_PauseAudio
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
 %endif
379
 %endif
367
 
380
 
368
 loop_event:
381
 loop_event:
387
 %endif
400
 %endif
388
 %ifdef SDL2
401
 %ifdef SDL2
389
 		mov edi, [event]
402
 		mov edi, [event]
390
-		cmp edi, SDL_AUDIODEVICEADDED
391
-		je sdl2_audiostart
392
 		cmp edi, SDL_QUIT
403
 		cmp edi, SDL_QUIT
393
 		je exit
404
 		je exit
394
 %endif
405
 %endif
395
 
406
 
396
 	jmp loop_event
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
 sdl_error:
409
 sdl_error:
406
 	; display error & exit
410
 	; display error & exit
407
 	call SDL_GetError
411
 	call SDL_GetError
415
 	mov rdi, 0xF
419
 	mov rdi, 0xF
416
 	jmp exit.exit_err
420
 	jmp exit.exit_err
417
 
421
 
422
+exit_fatal:
423
+	mov rdi, 42
424
+	jmp exit.exit_err
425
+
418
 exit:
426
 exit:
419
 	call SDL_Quit
427
 	call SDL_Quit
420
 
428
 
604
 		add al, "A" - 10
612
 		add al, "A" - 10
605
 		ret
613
 		ret
606
 
614
 
615
+%ifndef MIX_AUDIO
616
+; simplest/shortes audio_callback : copy byte returned by run_glitch in *stream
607
 audio_cllbck:
617
 audio_cllbck:
608
 	; rdi -> *userdata
618
 	; rdi -> *userdata
609
 	; rsi -> *stream
619
 	; rsi -> *stream
610
 	; rdx -> stream_len
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
 		push rdi
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
 		pop rdi
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
 run_glitch:
688
 run_glitch:
626
 	; Run the glitch_pgm
689
 	; Run the glitch_pgm

Loading…
Cancel
Save