-
Notifications
You must be signed in to change notification settings - Fork 1
/
mos_api.inc
227 lines (216 loc) · 6.75 KB
/
mos_api.inc
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
;
; Title: AGON MOS - API for user projects
; Author: Dean Belfield
; Created: 03/08/2022
; Last Updated: 19/05/2023
;
; Modinfo:
; 05/08/2022: Added mos_feof
; 09/08/2022: Added system variables: cursorX, cursorY
; 18/08/2022: Added system variables: scrchar, scrpixel, audioChannel, audioSuccess, vpd_pflags
; 05/09/2022: Added mos_ren, vdp_pflag_mode
; 24/09/2022: Added mos_getError, mos_mkdir
; 13/10/2022: Added mos_oscli
; 23/02/2023: Added more sysvars, fixed typo in sysvar_audioSuccess, offsets for sysvar_scrCols, sysvar_scrRows
; 04/03/2023: Added sysvar_scrpixelIndex
; 08/03/2023: Renamed sysvar_keycode to sysvar_keyascii, added sysvar_vkeycode
; 15/03/2023: Added mos_copy, mos_getrtc, mos_setrtc, rtc, vdp_pflag_rtc
; 21/03/2023: Added mos_setintvector, sysvars for keyboard status, vdu codes for vdp
; 22/03/2023: The VDP commands are now indexed from 0x80
; 29/03/2023: Added mos_uopen, mos_uclose, mos_ugetc, mos_uputc
; 13/04/2023: Added FatFS file structures (FFOBJID, FIL, DIR, FILINFO)
; 15/04/2023: Added mos_getfil, mos_fread, mos_fwrite and mos_flseek
; 19/05/2023: Added sysvar_scrMode
; VDP control (VDU 23, 0, n)
;
vdp_gp: EQU 80h
vdp_keycode: EQU 81h
vdp_cursor: EQU 82h
vdp_scrchar: EQU 83h
vdp_scrpixel: EQU 84h
vdp_audio: EQU 85h
vdp_mode: EQU 86h
vdp_rtc: EQU 87h
vdp_keystate: EQU 88h
vdp_logicalcoords: EQU C0h
vdp_terminalmode: EQU FFh
; MOS high level functions
;
mos_getkey: EQU 00h
mos_load: EQU 01h
mos_save: EQU 02h
mos_cd: EQU 03h
mos_dir: EQU 04h
mos_del: EQU 05h
mos_ren: EQU 06h
mos_mkdir: EQU 07h
mos_sysvars: EQU 08h
mos_editline: EQU 09h
mos_fopen: EQU 0Ah
mos_fclose: EQU 0Bh
mos_fgetc: EQU 0Ch
mos_fputc: EQU 0Dh
mos_feof: EQU 0Eh
mos_getError: EQU 0Fh
mos_oscli: EQU 10h
mos_copy: EQU 11h
mos_getrtc: EQU 12h
mos_setrtc: EQU 13h
mos_setintvector: EQU 14h
mos_uopen: EQU 15h
mos_uclose: EQU 16h
mos_ugetc: EQU 17h
mos_uputc: EQU 18h
mos_getfil: EQU 19h
mos_fread: EQU 1Ah
mos_fwrite: EQU 1Bh
mos_flseek: EQU 1Ch
; FatFS file access functions
;
ffs_fopen: EQU 80h
ffs_fclose: EQU 81h
ffs_fread: EQU 82h
ffs_fwrite: EQU 83h
ffs_flseek: EQU 84h
ffs_ftruncate: EQU 85h
ffs_fsync: EQU 86h
ffs_fforward: EQU 87h
ffs_fexpand: EQU 88h
ffs_fgets: EQU 89h
ffs_fputc: EQU 8Ah
ffs_fputs: EQU 8Bh
ffs_fprintf: EQU 8Ch
ffs_ftell: EQU 8Dh
ffs_feof: EQU 8Eh
ffs_fsize: EQU 8Fh
ffs_ferror: EQU 90h
; FatFS directory access functions
;
ffs_dopen: EQU 91h
ffs_dclose: EQU 92h
ffs_dread: EQU 93h
ffs_dfindfirst: EQU 94h
ffs_dfindnext: EQU 95h
; FatFS file and directory management functions
;
ffs_stat: EQU 96h
ffs_unlink: EQU 97h
ffs_rename: EQU 98h
ffs_chmod: EQU 99h
ffs_utime: EQU 9Ah
ffs_mkdir: EQU 9Bh
ffs_chdir: EQU 9Ch
ffs_chdrive: EQU 9Dh
ffs_getcwd: EQU 9Eh
; FatFS volume management and system configuration functions
;
ffs_mount: EQU 9Fh
ffs_mkfs: EQU A0h
ffs_fdisk EQU A1h
ffs_getfree: EQU A2h
ffs_getlabel: EQU A3h
ffs_setlabel: EQU A4h
ffs_setcp: EQU A5h
; File access modes
;
fa_read: EQU 01h
fa_write: EQU 02h
fa_open_existing: EQU 00h
fa_create_new: EQU 04h
fa_create_always: EQU 08h
fa_open_always: EQU 10h
fa_open_append: EQU 30h
; System variable indexes for api_sysvars
; Index into _sysvars in globals.asm
;
sysvar_time: EQU 00h ; 4: Clock timer in centiseconds (incremented by 2 every VBLANK)
sysvar_vpd_pflags: EQU 04h ; 1: Flags to indicate completion of VDP commands
sysvar_keyascii: EQU 05h ; 1: ASCII keycode, or 0 if no key is pressed
sysvar_keymods: EQU 06h ; 1: Keycode modifiers
sysvar_cursorX: EQU 07h ; 1: Cursor X position
sysvar_cursorY: EQU 08h ; 1: Cursor Y position
sysvar_scrchar: EQU 09h ; 1: Character read from screen
sysvar_scrpixel: EQU 0Ah ; 3: Pixel data read from screen (R,B,G)
sysvar_audioChannel: EQU 0Dh ; 1: Audio channel
sysvar_audioSuccess: EQU 0Eh ; 1: Audio channel note queued (0 = no, 1 = yes)
sysvar_scrWidth: EQU 0Fh ; 2: Screen width in pixels
sysvar_scrHeight: EQU 11h ; 2: Screen height in pixels
sysvar_scrCols: EQU 13h ; 1: Screen columns in characters
sysvar_scrRows: EQU 14h ; 1: Screen rows in characters
sysvar_scrColours: EQU 15h ; 1: Number of colours displayed
sysvar_scrpixelIndex: EQU 16h ; 1: Index of pixel data read from screen
sysvar_vkeycode: EQU 17h ; 1: Virtual key code from FabGL
sysvar_vkeydown EQU 18h ; 1: Virtual key state from FabGL (0=up, 1=down)
sysvar_vkeycount: EQU 19h ; 1: Incremented every time a key packet is received
sysvar_rtc: EQU 1Ah ; 8: Real time clock data
sysvar_keydelay: EQU 22h ; 2: Keyboard repeat delay
sysvar_keyrate: EQU 24h ; 2: Keyboard repeat reat
sysvar_keyled: EQU 26h ; 1: Keyboard LED status
sysvar_scrMode: EQU 27h ; 1: Screen mode
; Flags for the VPD protocol
;
vdp_pflag_cursor: EQU 00000001b
vdp_pflag_scrchar: EQU 00000010b
vdp_pflag_point: EQU 00000100b
vdp_pflag_audio: EQU 00001000b
vdp_pflag_mode: EQU 00010000b
vdp_pflag_rtc: EQU 00100000b
;
; FatFS structures
; These mirror the structures contained in src_fatfs/ff.h in the MOS project
;
; Object ID and allocation information (FFOBJID)
;
FFOBJID .STRUCT
fs: DS 3 ; Pointer to the hosting volume of this object
id: DS 2 ; Hosting volume mount ID
attr: DS 1 ; Object attribute
stat: DS 1 ; Object chain status (b1-0: =0:not contiguous, =2:contiguous, =3:fragmented in this session, b2:sub-directory stretched)
sclust: DS 4 ; Object data start cluster (0:no cluster or root directory)
objsize: DS 4 ; Object size (valid when sclust != 0)
FFOBJID_SIZE .ENDSTRUCT FFOBJID
;
; File object structure (FIL)
;
FIL .STRUCT
obj: .TAG FFOBJID ; Object identifier
flag: DS 1 ; File status flags
err: DS 1 ; Abort flag (error code)
fptr: DS 4 ; File read/write pointer (Zeroed on file open)
clust: DS 4 ; Current cluster of fpter (invalid when fptr is 0)
sect: DS 4 ; Sector number appearing in buf[] (0:invalid)
dir_sect: DS 4 ; Sector number containing the directory entry
dir_ptr: DS 3 ; Pointer to the directory entry in the win[]
FIL_SIZE .ENDSTRUCT FIL
;
; Directory object structure (DIR)
;
DIR .STRUCT
obj: .TAG FFOBJID ; Object identifier
dptr: DS 4 ; Current read/write offset
clust: DS 4 ; Current cluster
sect: DS 4 ; Current sector (0:Read operation has terminated)
dir: DS 3 ; Pointer to the directory item in the win[]
fn: DS 12 ; SFN (in/out) {body[8],ext[3],status[1]}
blk_ofs: DS 4 ; Offset of current entry block being processed (0xFFFFFFFF:Invalid)
DIR_SIZE .ENDSTRUCT DIR
;
; File information structure (FILINFO)
;
FILINFO .STRUCT
fsize: DS 4 ; File size
fdate: DS 2 ; Modified date
ftime: DS 2 ; Modified time
fattrib: DS 1 ; File attribute
altname: DS 13 ; Alternative file name
fname: DS 256 ; Primary file name
FILINFO_SIZE .ENDSTRUCT FILINFO
;
; Macro for calling the API
; Parameters:
; - function: One of the function numbers listed above
;
MOSCALL: MACRO function
LD A, function
RST.LIS 08h
ENDMACRO