-
Notifications
You must be signed in to change notification settings - Fork 3
/
disk.asm
171 lines (138 loc) · 3.02 KB
/
disk.asm
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
; disk routines
const TEMP_SECTOR_BUF: 0x01FFF808
const RAMDISK_START: 0x03800000
; read a sector into the specified memory buffer
; inputs:
; r0: sector number
; r1: disk ID
; r2: sector buffer (512 bytes)
; outputs:
; none
read_sector:
cmp.8 r1, 4
ifz jmp read_romdisk_sector
cmp.8 r1, 5
ifz jmp read_ramdisk_sector
push r3
push r4
mov r3, 0x80002000 ; command to set the location of the buffer
mov r4, 0x80003000 ; command to read a sector from a disk into the buffer
or.8 r4, r1 ; set the disk ID
out r3, r2 ; set the memory buffer location
out r4, r0 ; read the sector into memory
pop r4
pop r3
ret
; read a sector from the romdisk into the specified memory buffer
; inputs:
; r0: sector number
; r2: sector buffer (512 bytes)
; outputs:
; none
read_romdisk_sector:
push r0
push r1
push r2
; source pointer
mul r0, 512
add r0, romdisk_image
; destination pointer
mov r1, r2
; copy 512 bytes
mov r2, 512
call copy_memory_bytes
pop r2
pop r1
pop r0
ret
; read a sector from the ramdisk into the specified memory buffer
; inputs:
; r0: sector number
; r2: sector buffer (512 bytes)
; outputs:
; none
read_ramdisk_sector:
push r0
push r1
push r2
; source pointer
mul r0, 512
add r0, RAMDISK_START
; destination pointer
mov r1, r2
; copy 512 bytes
mov r2, 512
call copy_memory_bytes
pop r2
pop r1
pop r0
ret
; check if a RYFS image is included as a romdisk
; inputs:
; none
; outputs:
; Z flag: set if available, reset if not
is_romdisk_available:
push r0
mov r0, romdisk_image
add r0, 514
cmp.16 [r0], 0x5952
pop r0
ret
; check if a RYFS filesystem is initialized on the ramdisk
; inputs:
; none
; outputs:
; Z flag: set if available, reset if not
is_ramdisk_formatted:
push r0
mov r0, RAMDISK_START
add r0, 514
cmp.16 [r0], 0x5952
pop r0
ret
; write a sector from the specified memory buffer
; inputs:
; r0: sector number
; r1: disk ID
; r2: sector buffer (512 bytes)
; outputs:
; none
write_sector:
cmp.8 r1, 4
ifz ret
cmp.8 r1, 5
ifz jmp write_ramdisk_sector
push r3
push r4
mov r3, 0x80002000 ; command to set the location of the buffer
mov r4, 0x80004000 ; command to write a sector to a disk from the buffer
or.8 r4, r1 ; set the disk ID
out r3, r2 ; set the memory buffer location
out r4, r0 ; write the sector from memory
pop r4
pop r3
ret
; write a sector to ramdisk from the specified memory buffer
; inputs:
; r0: sector number
; r2: sector buffer (512 bytes)
; outputs:
; none
write_ramdisk_sector:
push r0
push r1
push r2
; destination pointer
mov r1, r0
mul r1, 512
add r1, RAMDISK_START
; source pointer
mov r0, r2
; copy 512 bytes
mov r2, 512
call copy_memory_bytes
pop r2
pop r1
pop r0
ret