forked from 0x10cAtlas/AtlasOS
-
Notifications
You must be signed in to change notification settings - Fork 1
/
API.txt
793 lines (534 loc) · 12.6 KB
/
API.txt
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
__ _______ _ __ ______ __ _____ _
/ \ |___ ___| | | / \ | ____| / \ | __ \ | |
/ /\ \ | | | | / /\ \ | |____ ____ / /\ \ | |__| | | |
/ /__\ \ | | | | / /__\ \ |____ | |____| / /__\ \ | ___/ | |
/ ______ \ | | | |___ / ______ \ ____| | / ______ \ | | | |
/_/ \_\ |_| |_____| /_/ \_\ |______| /_/ \_\ |_| |_|
API documentation for AtlasOS
Function calls
==============
All functions with three (3) or less parameters use fastcall. This means the parameters
are not pushed on the stack. Instead they are kept in the A, B and C registers.
The result is stored in A if not defined in this document.
Functions with more then three parameters expect them to be pushed on the stack in a
reversed order.
Less then three params
C:
int add(int x, int y) {
return x+y;
}
ASM:
ADD A, B
SET PC, POP
More then three params
C:
int add(int a, int b, int c, int d) {
return a+b+c+d;
}
ASM:
SET PUSH, B
SET A, SP
SUB A, 2
SET B, [A] ; SET d
SUB A, 1
ADD B, [A] ; ADD c
SUB A, 1
ADD B, [A] ; ADD b
SUB A, 1
ADD B, [A] ; ADD a
SET A, B ; Return
SET B, POP
SET PC, POP
API calls
=========
You call an API function by JSR'ing.
JSR [0x1000] ; Calls the os_version function
API functions
=============
os_version [0x1000]
-------------------
Description:
Returns the main and sub version of AtlasOS.
Parameter:
none
Return:
A - main version
B - sub version
Side effects:
none
proc_id [0x1001]
----------------
Description:
Returns the ID of the current running process (the process calling this function).
Parameter:
none
Return:
A - process ID
Side effects:
none
proc_suspend [0x1002]
---------------------
Description:
Suspends the current process and starts the next one. Processes should call this
function regularly to keep multitasking working and to get keyboard keys.
Parameter:
none
Return:
none
Side effects:
Runs other processes before returning to this one.
proc_get_addr [0x1003]
----------------------
Description:
Returns the address of the processes initial mem page.
Parameter:
none
Return:
A - address of the memory page.
Side effects:
none
proc_get_flags [0x1004]
-----------------------
Description:
Returns the flags of the process
Parameters:
none
Return:
A - Flags of the process
Side effects:
none
proc_kill_me [0x1005]
---------------------
Description:
Terminates the current process. No further code of it will be executed.
Parameters:
none
Return:
none
Side effects:
The process will be removed from the process list and its initial mem page will be freed.
proc_kill [0x1006]
------------------
Description:
Kills a process by its ID.
Parameters:
A - process ID
Return:
none
Side effects:
The process is removed from the process list and int initial mem page will be freed.
If the process doesn't exists nothing happens.
proc_load [0x1007]
------------------
Description:
Loads a new process into memory and starts it.
Parameters:
A - start address of the process BLOB
B - length of the process BLOB
Return:
process ID of the newly started process
Side effects:
Some memory is reserved, a new process is started.
reserved [0x1008]
-----------------
Mind the gap!
proc_callback_list [0x1009]
---------------------------
Description:
Calls a given callback function for every entry in the process list.
Parameters:
A - address of the callback function
Return:
none
Side effects:
The callback function is called once for every entry in the process list.
For every call of the callback function A is set to process ID.
msg_queue_reg [0x100A]
----------------------
Description:
Registers a new OS message queue for receiving messages from the OS and other apps.
Parameters:
A - Address of the 16 words buffer for the queue
Return:
A - 1 succeeded, 0 failed
Side effects:
Registers a new queue in the kernels queue list.
msg_queue_rem [0x100B]
----------------------
Description:
Removes a OS message queue.
Parameters:
A - Address of the 16 words buffer for the queue
Return:
A - 1 succeeded, 0 failed
Side effects:
Deletes a queue in the kernels queue list.
msg_broadcast [0x100C]
----------------------
Description:
Broadcasts a message to all message queues
Parameters:
A - Source of the message
B - Content of the message
Return:
none
Side effects:
The message is inserted in ALL message queues,
even the queue(s) of the broadcasting process.
msg_send [0x100D] ! not implemented yet !
-----------------
Description:
Sends a message to a specific process
Parameters:
A - process ID
B - Source of the message
C - Content of the message
Return:
none
Side effects:
The message is inserted in the processes message queue(s).
msg_get_message [0x100E]
------------------------
Description:
Receives the next message from the process' message queue.
Parameters:
none
Return:
A - Source of the message
B - Content of the message
Side effects:
The oldest message queue entry is returnd and removed from the queue.
page_alloc [0x100F]
-------------------
Description:
Allocates a memory page (1024 words) and returns its address.
Parameters:
none
Return:
A - address of the newly allocated memory or 0 if no more memory is available.
Side effects:
Reserves the memory in the memory management table.
page_free [0x1010]
-----------------
Description:
Frees allocated memory.
Parameters:
A - address of or in the mem page to be freed
Return:
none
Side effects:
The memory page will be marked as free in the memory management table.
! This does not clear the memory !
page_check [0x1011]
-------------------
Description:
Returns the amount of reserved memory.
Parameters:
none
Return:
Amount of reserved memory in words.
Side effects:
none
page_check_of [0x1012]
----------------------
Description:
Returns the amount of reserved memory of a specific process.
Parameters:
A - process ID
Return:
Amount of reserved memory of the given process in words.
Side effects:
none
mem_copy [0x1013]
-----------------
Description:
Copys a given number of words from source to destination.
Parameters:
A - source address
B - destination address
C - number of words to copy
Return:
none
Side effects:
The destination memory is overwritten by the contents of source.
mem_clear [0x1014]
------------------
Description:
Sets all words in the specified memory to 0x0000.
Parameters:
A - start address of the memory to be cleared.
B - length of the memory to be cleared.
Return:
none
Side effects:
All words in the specified memory are set to 0x0000.
pusha [0x1015]
--------------
Description:
Pushes all registers to the stack.
Parameters:
none
Return:
none
Side effects:
All registers are pushed to the stack.
Same as:
SET PUSH, A
SET PUSH, B
SET PUSH, C
SET PUSH, X
SET PUSH, Y
SET PUSH, Z
SET PUSH, I
SET PUSH, J
popa [0x1016]
-------------
Description:
Pops all registers from the stack.
Parameters:
none
Return:
none
Side effects:
All registers are POPed from the stack.
Same as:
SET J, POP
SET I, POP
SET Z, POP
SET Y, POP
SET X, POP
SET C, POP
SET B, POP
SET A, POP
strcpy [0x1017]
---------------
Description:
Copies a string from a source address to a destination address
Parameters:
A - source address
B - destination address
Return:
none
Side effects:
Copies the string. The string must be 0-terminated.
strncpy [0x1018]
----------------
Description:
Same as strcpy but with length limitation. (Same as C function)
Parameters:
A - source address
B - destination address
C - max length for copy
Return:
none
Side effects:
Same as strcpy but when C was exceeded the destination string has no 0-termination.
strlen [0x1019]
---------------
Description:
Returns the length of a null-terminated string
Parameters:
A - Start address of the string
Return:
B - Length of the string
Side effects:
none
strcmp [0x101A]
---------------
Description:
Compares two null-terminated strings to see if they're equal.
Parameters:
A - address of the first string
B - address of the second string
Return:
C and O as follows
A = B -> C=0, O=0
A > B -> C>0, O=0
A < B -> C>0, O>0
Side effects:
none
itoa [0x101B]
----------------
Description:
Converts a word into the numeric representation based on the radix (2, 10, 16).
Parameters:
A - word to be converted
B - string buffer (size: 5 words)
C - radix
Return:
none
Side effects:
The value of the word will be converted into a string.
Deprecated [0x101C]
----------------
atoi [0x101D]
-------------
Description:
Converts a textual, decimal number into the actual integer value
Parameters:
A - address of the source string
Return:
C - integer representation of the string
Side effects:
none
text_out [0x101E]
-----------------
Description:
Prints the text on the screen. It takes 0x00A0 as line feed.
Parameters:
A - start address of the text
Return:
none
Side effects:
Prints the text on the screen. Sets the screen cursor to the next char of the screen.
If the text reaches the bottom of the screen the screen is automaticaly scrolled.
newline [0x101F]
----------------
Description:
Sets the screen cursor to the next line.
Parameters:
none
Return:
none
Side effects:
If the cursor reaches the bottom of the screen the screen is autimaticaly scrolled.
scroll [0x1020]
---------------
Description:
Scrolls the screen one line up.
Parameters:
none
Return:
none
Side effects:
Screen is scrolled up and the screen cursor is set one line up.
clear [0x1021]
--------------
Description:
Clears the screen.
Parameters:
none
Return:
none
Side effects:
Sets the entire screen buffer to 0x7000. Sets the screen cursor to the top left position.
char_put [0x1022]
-----------------
Description:
Puts the specified char to the specified position on the screen.
Parameters:
A - X coordinate
B - Y coordinate
C - char to put on the screen
Return:
none
Side effects:
Puts the char on the screen. Does not effect the screen cursor.
! Does not specify a color for the char !
read_line [0x1023]
------------------
Description:
Reads a line from the keyboard to the string buffer
Parameters:
A - Key buffer of the application
B - String buffer of the application
C - Length of the string buffer
Return:
none
Side effects:
Reads the values from the keyboard. Constantly calls proc_suspend to wait for the key buffer to be filled.
rand [0x1024]
-------------
Description:
Returns a pseudorandom number.
Parameters:
none
Return:
A - pseudorandom number
Side effects:
Changes the entropy value of the OS.
srand [0x1025]
--------------
Description:
Initializes the random number generator
Parameters:
A - seed for the random number generator
Return:
none
Side effects:
Sets the OS's entropy value.
keyboard_register [0x1026]
--------------------------
Description:
Registers a memory address as a keyboard buffer.
Parameters:
A - address of the new keyboard buffer
Return:
none
Side effects:
adds the memory address to the keyboard buffer list. If the list is full this
function silently fail.
keyboard_unregister [0x1027]
----------------------------
Description:
Removes a keyboard buffer from the list
Parameters:
A - address of the keyboard buffer
Return:
none
Side effects:
The specified buffer will no longer be filled by the keyboard driver
keyboard_is_exclusive_active [0x1028]
-------------
Description:
Returns whether there is an exclusive keyboard buffer active
Parameters:
none
Return:
A - 0 if no, 1 if yes
Side effects:
none
virtual_filesystem_getfile [0x1029]
-------------
Description:
Returns the start of the matched filesystem entry
Parameters:
Return:
C - Pointer to start of FAT entry if found, 0 otherwise
Side effects:
none
virtual_filesystem_getfile_table [0x102A]
-------------
Description:
Returns the start of the filesystem file table. May be deprecated later
Parameters:
Return:
Side effects:
none
virtual_filesystem_getfile_bystart [0x102B]
-------------
Description:
Returns the start of the matched filesystem entry
Parameters:
Return:
C - Pointer to start of FAT entry if found, 0 otherwise
Side effects:
none
char_get [0x102C]
-------------
Description:
Returns the value at the A, B location on the screen
Parameters:
A - This is the X coordinate
B - This is the Y coordinate
Return:
A - Value of the screen character
Side effects:
none
// Ignore me!
[0x10]
-------------
Description:
Parameters:
Return:
Side effects: