Browse code

Add source code of the ROM

Pawel Jablonski authored on 14/12/2022 19:10:08
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,189 @@
1
+; Author: Pawel Jablonski
2
+; E-mail: pj@xirx.net
3
+; WWW: xirx.net
4
+; GIT: git.xirx.net
5
+;
6
+; License: You can use this code however you like
7
+; but leave information about the original author.
8
+; Code is free for non-commercial and commercial use.
9
+
10
+; No arguments
11
+; No return
12
+global .xIOInit:
13
+	push A
14
+	push B
15
+	push X
16
+	; Set counter
17
+	mov 0, A
18
+	; Set last clock value
19
+	mov 0, B
20
+	; Wait until IO board is not started
21
+.xIOInit_wait:
22
+	in X
23
+	and 0x10, X
24
+	cmp B, X
25
+	je .xIOInit_wait
26
+	mov X, B
27
+	inc A
28
+	; Wait until 8 edges are detected
29
+	cmp 8, A
30
+	jne .xIOInit_wait
31
+	pop X
32
+	pop B
33
+	pop A
34
+	ret
35
+
36
+; Arguments:
37
+; 	A - register address
38
+; No return
39
+global .xIOSetRegister:
40
+	push X
41
+	push A
42
+	; Get bus status bit
43
+	in X
44
+	and 0x80, X
45
+	; Send register address
46
+	out 0x00
47
+	and 0x0f, A
48
+	or 0b11000000, A
49
+	out A
50
+	; Wait for status change
51
+.xIOSetRegister_wait:
52
+	in A
53
+	and 0x80, A
54
+	cmp A, X
55
+	je .xIOSetRegister_wait
56
+	pop A
57
+	pop X
58
+	ret
59
+
60
+; Arguments:
61
+; 	A - data to transmit
62
+; No return
63
+global .xIOWriteLowHalf:
64
+	push X
65
+	push A
66
+	; Get bus status bit
67
+	in X
68
+	and 0x80, X
69
+	; Send low half
70
+	out 0x00
71
+	and 0x0f, A
72
+	or 0b11100000, A
73
+	out A
74
+	; Wait for status change
75
+.xIOWriteLowHalf_wait:
76
+	in A
77
+	and 0x80, A
78
+	cmp A, X
79
+	je .xIOWriteLowHalf_wait
80
+	pop A
81
+	pop X
82
+	ret
83
+
84
+; Arguments:
85
+; 	A - data to transmit
86
+; No return
87
+global .xIOWriteHighHalf:
88
+	push X
89
+	push A
90
+	; Get bus status bit
91
+	in X
92
+	and 0x80, X
93
+	; Send high half
94
+	out 0x00
95
+	swap A
96
+	and 0x0f, A
97
+	or 0b11110000, A
98
+	out A
99
+	; Wait for status change
100
+.xIOWriteHighHalf_wait:
101
+	in A
102
+	and 0x80, A
103
+	cmp A, X
104
+	je .xIOWriteLowHalf_wait
105
+	pop A
106
+	pop X
107
+	ret
108
+
109
+; No arguments
110
+; No return
111
+global .xIOWrite:
112
+	call .xIOWriteLowHalf
113
+	call .xIOWriteHighHalf
114
+	ret
115
+
116
+; No arguments
117
+; Return:
118
+; 	A - received data
119
+global .xIOReadLowHalf:
120
+	; Push registers to stack
121
+	push X
122
+	push B
123
+	push A
124
+	in X
125
+	and 0x80, X
126
+	; Read low half
127
+	out 0x00
128
+	and 0x0f, A
129
+	or 0b10100000, A
130
+	out A
131
+	; Wait for status change
132
+.xIOReadLowHalf_wait:
133
+	; Get bus status bit
134
+	in A
135
+	mov A, B
136
+	and 0x80, A
137
+	; Wait until status bit is not toggled
138
+	cmp A, X
139
+	je .xIOReadLowHalf_wait
140
+	; Set low half to return
141
+	and 0x0f, B
142
+	pop A
143
+	and 0xf0, A
144
+	or B, A
145
+	pop B
146
+	pop X
147
+	ret
148
+
149
+; No arguments
150
+; Return:
151
+; 	A - received data
152
+global .xIOReadHighHalf:
153
+	push X
154
+	push B
155
+	push A
156
+	; Get bus status bit
157
+	in X
158
+	and 0x80, X
159
+	; Read high half
160
+	out 0x00
161
+	and 0x0f, A
162
+	or 0b10110000, A
163
+	out A
164
+	; Wait for status change
165
+.xIOReadHighHalf_wait:
166
+	; Get bus status bit
167
+	in A
168
+	mov A, B
169
+	and 0x80, A
170
+	; Wait until status bit is not toggled
171
+	cmp A, X
172
+	je .xIOReadHighHalf_wait
173
+	; Set high half to return
174
+	swap B
175
+	and 0xf0, B
176
+	pop A
177
+	and 0x0f, A
178
+	or B, A
179
+	pop B
180
+	pop X
181
+	ret
182
+	
183
+; No arguments
184
+; No return
185
+global .xIORead:
186
+	call .xIOReadLowHalf
187
+	call .xIOReadHighHalf
188
+	ret
189
+