-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmpeg_2_bitstream.s
More file actions
123 lines (113 loc) · 2.11 KB
/
mpeg_2_bitstream.s
File metadata and controls
123 lines (113 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
;
; bitstream.s
;
; Copyright 2014 Fernando Rodriguez (support@fernansoft.com).
; All rights reserved
;
;typedef struct mp3_stream_t
;{;
; unsigned char const *ptr;
; unsigned int buffer;
; unsigned int bufflen;
;}
;mp3_stream_t;
;
; w0 = stream pointer
; w1 = bits to read
;
.global _mp3_stream_read
_mp3_stream_read:
;{
;
; if there's enough bits in the buffer
; return them
;
mov [w0 + (1 * 2)], w2 ; stream->buffer => w2
mov [w0 + (2 * 2)], w3 ; stream->bufflen => w3
cp w1, w3
bra gtu, _mp3_stream_read_reload
mov #1, w4
sl w4, w3, w4
dec w4, w4
sub w3, w1, w3
mov w3, [w0 + (2 * 2)]
and w2, w4, w0
lsr w0, w3, w0
return
_mp3_stream_read_reload:
;
; read whatever's left on the buffer
;
mov [w0], w5
mov #1, w4
sl w4, w3, w4
dec w4, w4
and w2, w4, w4
sub w1, w3, w1
clr w3
;
; if we still need more than 8 bits read a
; byte directly from the stream
;
cp w1, #8
bra ltu, _mp3_stream_read_no_bytes
sl w4, #8, w4
ior.b w4, [w5++], w4
sub w1, #8, w1
_mp3_stream_read_no_bytes:
;
; if we still need any bits reload the buffer
; with two bytes and read the bits
;
cp0 w1
bra z, _mp3_stream_read_no_bits
ze [w5++], w6
mov.b w6, [w0 + (1 * 2) + 1]
ze [w5++], w6
mov.b w6, [w0 + (1 * 2)]
mov [w0 + (1 * 2)], w2
sl w4, w1, w4
mov #16, w6
sub w6, w1, w3
lsr w2, w3, w6
ior w4, w6, w4
_mp3_stream_read_no_bits:
;
; update the stream object and return
; the bits read
;
mov w5, [w0]
mov w3, [w0 + (2 * 2)]
mov w4, w0
return
;}
.global _mp3_stream_read_bool
_mp3_stream_read_bool:
;{
;
; if there's at least one bit on the stram
; return it
;
mov [w0 + (1 * 2)], w1
mov [w0 + (2 * 2)], w2
cp0 w2
bra z, _mp3_stream_read_bool_reload
dec w2, w2
mov w2, [w0 + (2 * 2)]
mov #1, w0
sl w0, w2, w0
and w1, w0, w0
return
_mp3_stream_read_bool_reload:
mov [w0], w3
ze [w3++], w4
mov.b w4, [w0 + (1 * 2) + 1]
ze [w3++], w4
mov.b w4, [w0 + (1 * 2)]
mov w3, [w0]
mov [w0 + (1 * 2)], w1
mov #(16 - 1), w3
mov w3, [w0 + (2 * 2)]
lsr w1, #15, w0
return
;}