-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsd_asm.S
116 lines (96 loc) · 2.81 KB
/
sd_asm.S
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
.code16
.text
.macro toggle_clk
or $0x2, %al
out %ax,%dx // write P1LTCH clk high
and $0xfd, %al
out %ax,%dx // write P1LTCH clk low
.endm
.macro test_bit_and_shift bit
test $\bit,%cl // is bit set?
jz 3f // nope? jump to b80_ns
or $0x1,%al // yes, so turn on bit 0 of P1LTCH
jmp 2f // toggle clk
3:
and $0xfe,%al // turn off bit 0 of P1LTCH
2:
out %ax,%dx // write P1LTCH clk low
toggle_clk
.endm
.macro sample_input_bit_and_shift_data
sal $1,%bl // bl << 1
mov $0xff5a,%dx // fetch current DIN
in %dx,%ax //
test $0x40,%al // if(DIN)
jz 2f //
or $1, %bl // bl++
2:
mov $0xff56,%dx // fetch current P1LTCH value
in %dx,%ax //
or $0x1,%al // DI high
toggle_clk
.endm
.global xmit_mmc
/*-----------------------------------------------------------------------*/
/* Transmit a BYTE to the MMC (bitbanging) */
/*-----------------------------------------------------------------------*/
//void xmit_mmc (
// uint8_t d /* Data to be sent */
//);
xmit_mmc:
mov %sp,%bx
mov 2(%bx),%cx
mov $0xff56,%dx
in %dx,%ax // fetch current P1LTCH value
test_bit_and_shift 0x80
test_bit_and_shift 0x40
test_bit_and_shift 0x20
test_bit_and_shift 0x10
test_bit_and_shift 0x08
test_bit_and_shift 0x04
test_bit_and_shift 0x02
test_bit_and_shift 0x01
ret
.global rcvr_mmc
/*-----------------------------------------------------------------------*/
/* Receive a BYTE from the MMC (bitbanging) */
/*-----------------------------------------------------------------------*/
//uint8_t rcvr_mmc (void)
rcvr_mmc:
xor %bx,%bx
sample_input_bit_and_shift_data
sample_input_bit_and_shift_data
sample_input_bit_and_shift_data
sample_input_bit_and_shift_data
sample_input_bit_and_shift_data
sample_input_bit_and_shift_data
sample_input_bit_and_shift_data
sample_input_bit_and_shift_data
mov %bx, %ax
ret
.global skip_mmc
/*-----------------------------------------------------------------------*/
/* Skip BYTEs on the MMC (bitbanging) */
/*-----------------------------------------------------------------------*/
//void skip_mmc (
// uint16_t n /* Number of BYTEs to skip */
//);
skip_mmc:
mov %sp,%bx
mov 2(%bx),%cx
mov $0xff56,%dx // fetch current P1LTCH value
in %dx,%ax //
or $0x1,%al // DI high
out %ax,%dx // write P1LTCH DI high
loop:
toggle_clk
toggle_clk
toggle_clk
toggle_clk
toggle_clk
toggle_clk
toggle_clk
toggle_clk
dec %cx
jnz loop
ret