-
Notifications
You must be signed in to change notification settings - Fork 50
/
appendix-hypervisor-calls.tex
1955 lines (1719 loc) · 68.3 KB
/
appendix-hypervisor-calls.tex
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
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\newenvironment{hyppotrap}[3]
{
\newcommand{\availablefrom}[1]{Available since Hyppo ##1}
\newcommand{\deprecatedfrom}[1]{
\textcolor{Orange}{
\textbf{DEPRECATED} since Hyppo ##1.
This service may be removed in a future version. New programs should
not use this service.
}
}
\newcommand{\errordesc}[3]{
\index{Hyppo Error Codes!\$##1}
\textbf{\$##1 ##2} ##3\par
}
\newcommand{\hypporef}[1]{
\StrDel{hyppo:##1}{\_}[\reflbl]
\nameref{\reflbl}
}
\newcommand{\notimplemented}{\item[Remarks:]\textbf{NOT IMPLEMENTED}\par}
\newcommand{\register}[2]{\textbf{##1} ##2\par}
\newcommand{\TODO}{\textbf{\color{red}TODO}}
\titleformat*{\subsection}{\normalfont\huge\bfseries\color{blue}}
\subsection{hyppo\_#1}
{ \StrDel{hyppo:#1}{\_}[\reflbl] \label{\reflbl} }
\index{Hyppo Services!\$#2 \$#3}
\begin{description}[leftmargin=2.7cm,style=nextline]
\item [Trap:] LDA \#\$#3 : STA \$#2 : CLV
}
{
\end{description}
}
\DeclareTCBInputListing{\acmelisting}{ m }{
bottom=0mm,
breakable,
colback=black,
coltext=lightgray,
enhanced,
frame empty,
fontupper=\codefont,
listing engine=listings,
listing file={#1},
listing only,
listing options={
basewidth=0.3em,
breakatwhitespace,
breakindent=0pt,
breaklines,
columns=fullflexible,
commentstyle=\sffamily\footnotesize\color{Dandelion},
includerangemarker=false,
inputpath="examples/appendix-hypervisor-calls",
keywordstyle={*\color{white}},
keywordstyle={[2]\color{GreenYellow}},
language={[acme]Assembler},
linerange=EXAMPLE\ BEGINS-EXAMPLE\ ENDS,
postbreak={;\space},
rangeprefix=;\ >>>\ ,
showstringspaces=false,
},
top=0mm,
underlay first and middle={
\node at ([yshift=-3mm]frame.south)
{\ldots{} continues on the next page \ldots} ;
}
}
\addtocontents{toc}{\protect\setcounter{tocdepth}{1}}
\chapter{MEGA65 Hyppo Services}
\index{Hyppo Services}
\index{Registers!\$D640}
\index{Registers!\$D641}
\index{Registers!\$D642}
\index{Registers!\$D643}
\index{Registers!\$D644}
\index{Registers!\$D645}
\index{Registers!\$D646}
\index{Registers!\$D647}
\index{Registers!\$D648}
\index{Registers!\$D649}
\index{Registers!\$D64A}
\index{Registers!\$D64B}
\index{Registers!\$D64C}
\index{Registers!\$D64D}
\index{Registers!\$D64E}
\index{Registers!\$D64F}
\index{Registers!\$D650}
\index{Registers!\$D651}
\index{Registers!\$D652}
\index{Registers!\$D653}
\index{Registers!\$D654}
\index{Registers!\$D655}
\index{Registers!\$D656}
\index{Registers!\$D657}
\index{Registers!\$D658}
\index{Registers!\$D659}
\index{Registers!\$D65A}
\index{Registers!\$D65B}
\index{Registers!\$D65C}
\index{Registers!\$D65D}
\index{Registers!\$D65E}
\index{Registers!\$D65F}
\index{Registers!\$D660}
\index{Registers!\$D661}
\index{Registers!\$D662}
\index{Registers!\$D663}
\index{Registers!\$D664}
\index{Registers!\$D665}
\index{Registers!\$D666}
\index{Registers!\$D667}
\index{Registers!\$D668}
\index{Registers!\$D669}
\index{Registers!\$D66A}
\index{Registers!\$D66B}
\index{Registers!\$D66C}
\index{Registers!\$D66D}
\index{Registers!\$D66E}
\index{Registers!\$D66F}
\index{Registers!\$D670}
\index{Registers!\$D671}
\index{Registers!\$D672}
\index{Registers!\$D673}
\index{Registers!\$D674}
\index{Registers!\$D675}
\index{Registers!\$D676}
\index{Registers!\$D677}
\index{Registers!\$D678}
\index{Registers!\$D679}
\index{Registers!\$D67A}
\index{Registers!\$D67B}
\index{Registers!\$D67C}
\index{Registers!\$D67D}
\index{Registers!\$D67E}
\index{Registers!\$D67F}
\section{Introduction}
A part of the MEGA65 is the system program called Hyppo that:
\begin{itemize}
\item Boots the MEGA65.
\item Loads the ROMs and other files from the SD card.
\item Makes memory banks 2 and 3 ROM-like by protecting them from being
written to.
\item Virtualises the floppy disk controller so you can use disk images.
\item Launches various utilities like the freezer and the Matrix Mode
Debugger.
\item Provides services specific to the MEGA65 that you can use in your
programs.
\end{itemize}
If you know about hypervisors and virtual machines, Hyppo is a very limited
hypervisor. Don't expect to be able to run multiple virtual machines
concurrently with full isolation. Hyppo runs things that are more akin to the
task and processes of a modern operating system than the virtual machines of a
hypervisor as you might know it.
Hyppo provides 3 operating modes.
\begin{itemize}
\item \textbf{The C64-like operating mode} runs C64 programs and MEGA65
programs that run in the MEGA65's C64 mode. When you boot with
\megasymbolkey pressed or use the \textbf{GO64} command, Hyppo
starts a process in the C64-like operating mode to run BASIC 2 or the
MEGA65 program.
\item \textbf{The C65-like operating mode} is the MEGA65's normal operating
mode. This is where regular MEGA65 program run, including BASIC 65
programs.
\item \textbf{The MEGA65 operating mode} runs the MEGA65's system programs
like the freezer, the configuration utility and the Matrix Mode
Debugger. Maybe surprisingly, normal MEGA65 programs do not run in the
MEGA65 operating mode. They run in the C65-like operating mode. The
MEGA65 operating mode is designed solely for the MEGA65 and does not
attempt to be compatible with or even be similar to previous systems.
\end{itemize}
Unlike on the C128, it is possible for a program to effectively change the
operating mode while it's is running, by simply enabling or disabling the
various hardware features.
\filbreak
Hyppo provides very limited virtualisation of the MEGA65's hardware. It can
virtualise the floppy controller. There are plans to virtualise the serial bus
so the MEGA65 can use disk images for units like the 1541.
There are some parts of the hardware that only Hyppo can access. It is the only
component that can directly access the internal and external SD cards. You need
to use Hyppo's services if you want to access the files and directories on the
SD cards from within your programs.
\subsection{Terminology}
When you start to learn about Hyppo, there can be some terminology that might be
confusing if you already know about other parts of the MEGA65.
On the SD card there is likely to be a file called HICKUP.M65. This file updates
Hyppo to new versions without having to install an upgraded core. You might find
occasions where Hyppo might be called Hickup because of this strong association.
There are 3 distinct disk operating systems in the MEGA65.
\begin{itemize}
\item Inside Hyppo is Hyppo DOS, or HDOS for short. HDOS is for accessing
the FAT32 file system on the SD cards. HDOS does not know anything
about Commodore file systems. It can attach an image of a Commodore
file system, but it does not understand what is inside the image.
\item Inside the KERNAL is CBDOS. CBDOS is for accessing 1581-like file
systems. CBDOS uses the 45IO27 multi-function I/O controller to access
the sectors of a physical disk. CBDOS does not know anything about SD
cards and the FAT32 file system on them. Hyppo virtualises part of the
45IO27 so CBDOS can access disk images like they're physical disks.
\item The external disk units attached to the serial bus each have their own
DOS. They are used for accessing the file systems on their respective
physical disks.
\end{itemize}
The word drive means different things for each of these DOS's.
\begin{itemize}
\item The drives in Hyppo are the partitions of the internal and external SD
cards. When the MEGA65 boots, Hyppo assigns numbers to the partitions
it can read.
\item The drives in CBDOS are the physical disk drives attached to the 45IO27
multi-function I/O controller --- such as the internal disk drive ---
or the disk images attached to the virtualised 45IO27. The CBDOS drives
are normally seen as units 8 and 9.
\item The drives in an external unit attached to the serial bus are the
disk drives inside that unit.
\end{itemize}
\filbreak
\subsection{Versions}
This chapter describes the services available in Hyppo 1.2.
New Hyppo services may become available and existing Hyppo services may change
or be deprecated. A robust program will use the \nameref{hyppo:getversion}
service to check whether it is compatible with the Hyppo in the MEGA65 it's
running on.
% Jimbo - Do we commit to semantic versioning? Do we have a deprecation policy?
\subsection{Using}
When you want to use a Hyppo service, you don't use JSR. This is because
Hyppo exists in a space that's separate from regular code. In order to
access it, the CPU needs to switch into its hypervisor mode.
At addresses \$D640 -- \$D67F are a set of hypervisor traps. Writing to these
addresses are not like writing to other addresses. Instead of writing to memory
or I/O, the CPU switches into the hypervisor mode and starts a Hyppo service.
How the CPU does this is described in \bookvref{cha:cpu}.
Which Hyppo service starts depends on what value from the A register you
write and which trap you write to. Each of the services described in this
chapter tells you what value to write and which trap to use. You have to use the
A register when triggering a trap. Writing the same value from another register
won't work.
When the Hyppo service finishes, the CPU will switch back to your program.
Except for the registers a service uses to return values, the registers are
otherwise preserved.
\textbf{Important} The CPU may or may not execute the next byte in your
program after the Hyppo service finishes. Put a CLV instruction after the STA.
The CPU executing the CLV or not shouldn't matter to your program. If your
program does rely on the V flag, you can use the NOP instruction instead. When
you use NOP you must be mindful of when the CPU interprets the NOP as a prefix
for the following instruction. For this reason, you should prefer using CLV
over NOP.
\subsection{Errors}
\index{Hyppo Error Codes}
If the service was successful, it will set the C flag.
If the service was unsuccessful, it will clear the C flag and put an error code
in the A register. There is a table of error codes in the description for
\nameref{hyppo:geterrorcode}.
\subsection{Examples}
The examples use the ACME assembler. The ACME assembler is not required. The
Hyppo services can be used with any assembler.
The examples are often not complete. They assume an error handler called error
is defined somewhere. They also assume a transfer area has been defined
somewhere. \nameref{hyppo:setuptransferarea} and \nameref{hyppo:setname}
show how to define a transfer area.
% ==============================================================================
% General Services
% ==============================================================================
\newpage
\section{General Services}
% ******************************************************************************
% geterrorcode
% ******************************************************************************
\begin{hyppotrap}{geterrorcode}{D640}{38}
\index{Hyppo Error Codes}
\item [Service:]
Returns the current error code from Hyppo.
\item [Precondition:]
The previous service used cleared the C flag.
\item [Outputs:]
\register{A}{The error code of the previously failed service.}
\item [History:]
\availablefrom{1.2}
\item [Remarks:]
The error code is only valid if the previous Hyppo service cleared the C flag.
If the C flag was set there was no error and the Hyppo error code is
undefined.
The meanings here are generic. See the sections for the services for more
specific meanings.
\item [Error codes:] This is possibly not an exhaustive list.
{
\setlength{\def\arraystretch{1.5}\tabcolsep}{3pt}
\begin{longtable}{|c|r|l|p{8cm}|}
\hline
\textbf{Hex} & \textbf{Dec} & \textbf{Name} & \textbf{General meaning}\\
\hline
\endhead
\index{Hyppo Error Codes!\$01}
\$01 & 1 & \makecell[tl]{partition not \\ interesting} &
The partition is not of a supported type.
\\\hline
\index{Hyppo Error Codes!\$02}
\$02 & 2 & bad signature &
The signature bytes at the end of a partition table or of the first sector
of a partition were missing or incorrect.
\\\hline
\index{Hyppo Error Codes!\$03}
\$03 & 3 & is small FAT &
This is partition is FAT12 or FAT16 partition. Only FAT32 is supported.
\\\hline
\index{Hyppo Error Codes!\$04}
\$04 & 4 & \makecell[tl]{too many reserved\\clusters} &
The partition has more than 65,535 reserved sectors.
\\\hline
\index{Hyppo Error Codes!\$05}
\$05 & 5 & not two FATs &
The partition does not have exactly two copies of the FAT structure.
\\\hline
\index{Hyppo Error Codes!\$06}
\$06 & 6 & too few clusters &
The partition contains too few clusters.
% Jimbo - What is the minimum?
\\\hline
\index{Hyppo Error Codes!\$07}
\$07 & 7 & read timeout &
It took to long to read from the SD card.
% Jimbo - Is there a write timeout error code?
\\\hline
\index{Hyppo Error Codes!\$08}
\$08 & 8 & partition error &
An unspecified error occurred while handling a partition.
\\\hline
\index{Hyppo Error Codes!\$10}
\$10 & 16 & invalid address &
An invalid address was supplied in an argument.
\\\hline
\index{Hyppo Error Codes!\$11}
\$11 & 17 & illegal value &
An illegal value was supplied in an argument.
\\\hline
\index{Hyppo Error Codes!\$20}
\$20 & 32 & read error &
An unspecified error occurred while reading.
\\\hline
\index{Hyppo Error Codes!\$21}
\$21 & 33 & write error &
An unspecified error occurred while writing.
\\\hline
\index{Hyppo Error Codes!\$80}
\$80 & 128 & no such drive &
The supplied Hyppo drive number does not exist.
\\\hline
\index{Hyppo Error Codes!\$81}
\$81 & 129 & {name too long} &
The supplied filename was too long.
\\\hline
\index{Hyppo Error Codes!\$82}
\$82 & 130 & not implemented &
The Hyppo service is not implemented.
\\\hline
\index{Hyppo Error Codes!\$83}
\$83 & 131 & file too long &
The file is larger than 16MB.
\\\hline
\index{Hyppo Error Codes!\$84}
\$84 & 132 & \makecell[tl]{too many\\open files} &
All of the file descriptors are in use.
\\\hline
\index{Hyppo Error Codes!\$85}
\$85 & 133 & invalid cluster &
The supplied cluster number is invalid.
\\\hline
\index{Hyppo Error Codes!\$86}
\$86 & 134 & is a directory &
An attempt was made to operate on a directory, where a normal file was
expected.
\\\hline
\index{Hyppo Error Codes!\$87}
\$87 & 135 & not a directory &
An attempt was made to operate on a normal file, where a directory was
expected.
\\\hline
\index{Hyppo Error Codes!\$88}
\$88 & 136 & file not found &
The file could not be located in the current directory of the current drive.
\\\hline
\index{Hyppo Error Codes!\$89}
\$89 & 137 & \makecell[tl]{invalid file\\descriptor} &
An invalid or closed file descriptor was supplied.
\\\hline
\index{Hyppo Error Codes!\$8A}
\$8A & 138 & \makecell[tl]{image wrong\\length} &
The disk image file has the wrong length.
\\\hline
\index{Hyppo Error Codes!\$8B}
\$8B & 139 & image fragmented &
The disk image is not stored contiguously on the SD card.
\\\hline
\index{Hyppo Error Codes!\$8C}
\$8C & 140 & no space &
The SD card has no free space for the requested operation.
\\\hline
\index{Hyppo Error Codes!\$8D}
\$8D & 141 & file exists &
A file already exists with the given name.
\\\hline
\index{Hyppo Error Codes!\$8E}
\$8E & 142 & directory full &
The directory cannot accommodate any more entries.
\\\hline
\index{Hyppo Error Codes!\$FF}
\$FF & 255 & eof &
The end of a file or directory was encountered.
\\\hline
\index{Hyppo Error Codes!\$FF}
\$FF & 255 & no such trap &
There is no Hyppo service available for the trap. The program may be
incompatible with this version of Hyppo.
\\\hline
\end{longtable}
}
\end{hyppotrap}
% ******************************************************************************
% getversion
% ******************************************************************************
\newpage
\begin{hyppotrap}{getversion}{D640}{00}
\item [Service:]
Returns the version of Hyppo \textbf{A.X} and HDOS \textbf{Y.Z}.
\item [Outputs:]
\register{A}{The major version number of Hyppo}
\register{X}{The minor version number of Hyppo}
\register{Y}{The major version number of HDOS}
\register{Z}{The minor version number of HDOS}
\item [History:]
\availablefrom{1.2}
\item [Remarks:]
The HDOS in Hyppo is not related to the CBDOS inside the KERNAL or the
DOS in the disk drive units attached to the serial port.
\item [Example:]
Tests if Hyppo's version is $\geq$ 1.2 and $<$ 2.0.
\acmelisting{getversion.asm}
\end{hyppotrap}
% ******************************************************************************
% setup_transfer_area
%
% Jimbo - What are the post-conditions for this? What services are affected by
% this?
% - Is this now redundant? So far everything I've used has the transfer
% area as a parameter.
% ******************************************************************************
\newpage
\begin{hyppotrap}{setup\_transfer\_area}{D640}{3A}
\item [Service:]
Sets up the area Hyppo uses to transfer data to and from your program.
\item [Inputs:]
\register{Y}{The MSB of the transfer area's address}
\item [Errors:]
\errordesc{10}{invalid address}{The transfer area address in Y $>$ \$7E}
\item [History:]
\availablefrom{1.2}
\item [Remarks:]
The transfer area must be between \$0000 and \$7E00. It must also begin on a
page boundary. The LSB of its address must be \$00.
The transfer area is 256 bytes long for most services.
The transfer area is indicated using the CPU's current memory mapping at
the time that a service is used. However, it is good practice to always
place it in the bottom 32KB of bank 0.
\item [Example:]
Reserves 256 bytes on a page boundary and sets it up as the transfer area.
\acmelisting{setup_transfer_area.asm}
\end{hyppotrap}
% ==============================================================================
% Disk/storage services
% ==============================================================================
\newpage
\section{Drive/Storage Services}
% Jimbo - These should be named as what they are, partitions.
% This would resolve potential confusion when we do start referring
% to the virtual F011's drive 0 and 1 around mounting disk images.
In Hyppo, drives are the partitions of the internal and external SD cards.
They are not the drive 0 and drive 1 of the F011 floppy controller. They
are also not the drive 0 and drive 1 of dual-drive units attached to the serial
bus.
% ******************************************************************************
% chdir
% ******************************************************************************
\begin{hyppotrap}{chdir}{D640}{0C}
\item [Service:]
Changes the current working directory.
\item [Preconditions:]
The FAT dir entry for the directory you want to change to has been
found. \hypporef{findfile} is typically used to find a FAT dir entry.
\hypporef{findfirst}, \hypporef{findnext} and \hypporef{readdir} can also be
used.
\item [Errors:]
\errordesc{87}{not a directory}{The FAT dir entry last found isn't for a
directory. Bit 4 of the FAT dir entry's attribute byte is set for
directories.}
\item [History:]
\availablefrom{1.2}
\item [Remarks:]
You can move up to the parent directory by finding the .. FAT dir entry.
You cannot move up or down more than one directory at a time.
Use \hypporef{cdrootdir} to directly change back to the root directory.
\item [Example:]
Changes to an arbitrary path on the current drive. Call with Y:X being the
address of the path. The last character of each component in the path needs
to have bit 7 set. The whole path is terminated with a \$00. For example,
to change into DIR1 and then DIR2 the path would be
{\codefont !text "DIR", '1'+\$80, "DIR" '2'+\$80, 0}.
If successful, returns with the C flag set. If some part of the path doesn't
exist, returns with the C flag cleared and the current working directory will
be whatever directory was last successfully navigated to.
\acmelisting{chdir.asm}
\end{hyppotrap}
% ******************************************************************************
% cdrootdir
% ******************************************************************************
\newpage
\begin{hyppotrap}{cdrootdir}{D640}{3C}
\index{Hyppo Move to Root Directory}
\index{Root directory}
\item [Service:]
Change drive by calling \hypporef{selectdrive} and set the current directory
to the root directory.
\item [Inputs:]
\register{X}{The drive number to become the new current drive}
\item [Precondition:]
None.
\item [Outputs:]
\register{A}{Any error code that can be returned by \hypporef{selectdrive}}
\item [History:]
\availablefrom{1.16}
\end{hyppotrap}
% ******************************************************************************
% closeall
% ******************************************************************************
\newpage
\begin{hyppotrap}{closeall}{D640}{22}
\item [Service:]
Closes all the file descriptors.
\item [Postconditions:]
Using any file descriptor with \hypporef{closedir} or \hypporef{closefile}
succeeds.
Using any file descriptor with \hypporef{readdir} or \hypporef{readfile}
fails.
\hypporef{opendir} and \hypporef{openfile} reuse the file descriptor.
\item [History:]
\availablefrom{1.2}
\item [Remarks:]
You can also close individual file descriptors using \hypporef{closedir} or
\hypporef{closefile}.
\end{hyppotrap}
% ******************************************************************************
% closedir
% ******************************************************************************
\newpage
\begin{hyppotrap}{closedir}{D640}{16}
\item [Service:]
Closes a file descriptor for a directory.
\item [Preconditions:]
The file descriptor given in the X register was opened using
\hypporef{opendir}.
\item [Inputs:]
\register{X}{The file descriptor for the directory}
\item [Postconditions:]
Using the file descriptor again with \hypporef{closedir} succeeds.
Using the file descriptor again with \hypporef{readdir} fails.
\hypporef{opendir} and \hypporef{openfile} reuse the file descriptor.
\item [History:]
\availablefrom{1.2}
\item [Remarks:]
You can also close all the open file descriptors using \hypporef{closeall}.
\item [Example:]
See the example in \hypporef{opendir}.
\end{hyppotrap}
% ******************************************************************************
% closefile
% ******************************************************************************
\newpage
\begin{hyppotrap}{closefile}{D640}{20}
\item [Service:]
Closes a file descriptor for a file.
\item [Preconditions:]
The file descriptor given in the X register was opened using
\hypporef{openfile}.
\item [Inputs:]
\register{X}{The file descriptor for the file}
\item [Postconditions:]
Using the file descriptor again with \hypporef{closefile} succeeds.
Using the file descriptor again with \hypporef{readfile} fails.
\hypporef{opendir} and \hypporef{openfile} reuse the file descriptor.
\item [History:]
\availablefrom{1.2}
\item [Remarks:]
You can also close all the open file descriptors using \hypporef{closeall}.
\end{hyppotrap}
% ******************************************************************************
% filedate
% ******************************************************************************
\newpage
\begin{hyppotrap}{filedate}{D640}{2C}
\item [Service:]
Sets time stamp of a file.
\notimplemented
\end{hyppotrap}
% ******************************************************************************
% findfile
%
% Jimbo - Does this service work for files that don't have an LFN?
% ******************************************************************************
\newpage
\begin{hyppotrap}{findfile}{D640}{34}
\item [Service:]
Finds the first file whose filename matches the current Hyppo filename.
\item [Preconditions:]
The current Hyppo filename has been set using \hypporef{setname}.
\item [Postconditions:]
No additional file descriptors are open.
\item [Errors:]
\errordesc{88}{file not found}{A matching file was not found in the current
directory of the current drive.}
\item [History:]
\availablefrom{1.2}
\item [Remarks:]
% Jimbo - Why does Hyppo do this and create this restriction?
Hyppo will only find files whose long filename is all in uppercase.
Hyppo converts the current filename to ASCII uppercase before trying
to match it. Bytes \$61 -- \$7B change to \$41 -- \$5A.
Hyppo does not yet support the wildcard characters * and ?. Support
for that is planned in a future version.
This only finds the first matching file. You can find multiple matches by
using \hypporef{findfirst} and \hypporef{findnext}.
\item [Example:]
See the example in \hypporef{openfile}.
\end{hyppotrap}
% ******************************************************************************
% findfirst
%
% Jimbo - Does this service work for files that don't have an LFN?
% ******************************************************************************
\newpage
\begin{hyppotrap}{findfirst}{D640}{30}
\item [Service:]
Finds the first file whose filename matches the current Hyppo filename.
\item [Preconditions:]
The current Hyppo filename has been set using \hypporef{setname}.
\item [Outputs:]
\register{A}{The file descriptor for reading the current working directory.
You might be responsible for closing this file descriptor using
\hypporef{closedir}. See the remarks.}
\item [Postconditions:]
\hypporef{findnext} find the next matching file or fails with a file not
found error.
\item [Side effects:]
Sets the current file descriptor.
\item [Errors:]
\errordesc{88}{file not found}{A matching file was not found in the current
directory of the current drive.}
\item [History:]
\availablefrom{1.2}
\item [Remarks:]
If Hyppo finds an initial matching file, it will set the C flag and
return a file descriptor in the A register. This is a file descriptor for
reading the current working directory. You are responsible for closing it
using \hypporef{closedir}. It's a standard directory file descriptor. You
can use \hypporef{readdir} to read the FAT dir entries after the file that
was found.
If Hyppo doesn't find any matching files, it will fail with a file
not found error. In this case Hyppo will have already closed the
file descriptor and you don't have to close it.
% Jimbo - Why does Hyppo do this and create this restriction?
Hyppo will only find files whose long filename is all in uppercase.
Hyppo converts the current filename to ASCII uppercase before trying
to match it. Bytes \$61 -- \$7B change to \$41 -- \$5A.
Hyppo does not yet support the wildcard characters * and ?. Support
for that is planned in a future version.
If you are only interested in the first match, you can use \hypporef{findfile}
instead. \hypporef{findfile} always closes the file descriptor for you. But
you can't use it to find multiple matching files.
\item [Example:]
See the example in \hypporef{findnext}.
\end{hyppotrap}
% ******************************************************************************
% findnext
%
% Jimbo - Does this service work for files that don't have an LFN?
% ******************************************************************************
\newpage
\begin{hyppotrap}{findnext}{D640}{32}
\item [Service:]
Finds a subsequent file whose filename matches the current Hyppo filename.
\item [Preconditions:]
The current Hyppo filename has been set using \hypporef{setname}.
The first matching file has already been found successfully using
\hypporef{findfirst}.
\item [Postconditions:]
Using \hypporef{findnext} again finds the next matching file or fails with a
file not found error.
\item [Errors:]
\errordesc{88}{file not found}{A subsequent matching file was not found in
the current directory of the current drive.}
\item [History:]
\availablefrom{1.2}
\item [Remarks:]
If Hyppo doesn't find a subsequent matching file, it will fail with a
file not found error. Hyppo will also close the file descriptor it
output in \hypporef{findfirst}.
If you don't exhaust the search by using \hypporef{findnext} until it fails
with a file not found error, you are required to close the file descriptor
yourself using \hypporef{closedir}.
\item [Example:]
Returns with X register containing the number of files matching the current
Hyppo filename in the current working directory of the current drive. While
a directory can in theory have multiple files with an identical name, this
example will be more useful once Hyppo supports * and ? wildcards.
\acmelisting{findnext.asm}
\end{hyppotrap}
% ******************************************************************************
% fstat
% ******************************************************************************
\newpage
\begin{hyppotrap}{fstat}{D640}{28}
\item [Service:]
Returns information about a file.
\notimplemented
\end{hyppotrap}
% ******************************************************************************
% getcurrentdrive
% ******************************************************************************
\newpage
\begin{hyppotrap}{getcurrentdrive}{D640}{04}
\item [Service:]
Returns the number of the currently selected drive (SD card partition).
\item [Outputs:]
\register{A}{The current drive number}
\item [History:]
\availablefrom{1.2}
\item [Remarks:]
\hypporef{selectdrive} changes the current drive number. \hypporef{cdrootdir}
can also change it.
\item [Example:]
Prints the number of the currently selected drive in the top-left of the
screen. This example assumes that there aren't more than 10 drives (drives
0 to 9). It also assumes the screen memory hasn't been moved from \$800.
\acmelisting{getcurrentdrive.asm}
\end{hyppotrap}
% ******************************************************************************
% getcwd
% ******************************************************************************
\newpage
\begin{hyppotrap}{getcwd}{D640}{0A}
\item [Service:]
Returns information on the currently selected directory or sub-directory.
\notimplemented
\end{hyppotrap}
% ******************************************************************************
% getdefaultdrive
% ******************************************************************************
\newpage
\begin{hyppotrap}{getdefaultdrive}{D640}{02}
\item [Service:]
Returns the drive number (SD card partition) Hyppo selected while
booting.
\item [Outputs:]
\register{A}{The default drive number}
\item [History:]
\availablefrom{1.2}
\item [Example:]
Selects the default drive.
\acmelisting{getdefaultdrive.asm}
\end{hyppotrap}
% ******************************************************************************
% getdrivesize
% ******************************************************************************
\newpage
\begin{hyppotrap}{getdrivesize}{D640}{08}
\item [Service:]
Returns information on the size of the currently selected drive (SD card
partition).
\notimplemented
\end{hyppotrap}
% ******************************************************************************
% loadfile
% ******************************************************************************
\newpage
\begin{hyppotrap}{loadfile}{D640}{36}
\item [Service:]
Loads a file into chip memory.
\item [Preconditions:]
The name of the file to load has been set using \hypporef{setname}.
\item [Inputs:]
\register{X}{The LSB of the address to start loading from}
\register{Y}{The middle byte of the address to start loading from}
\register{Z}{The MSB of the address to start loading from}
\item [Postconditions:]
No additional file descriptors are open.
\item [Errors:]
\errordesc{84}{too many open files}{\hypporef{loadfile} uses one file
descriptor internally, but all the file descriptors are in use. Close some or
all of the file descriptors using \hypporef{closedir}, \hypporef{closefile}
or \hypporef{closeall}.}
\errordesc{88}{file not found}{The file was not found in the current directory
of the current drive.}
\item [History:]
\availablefrom{1.2}
\item [Remarks:]
This service can load files up to 16MB in size into the first 16MB of chip
memory. Chip memory is the 384KB or more of memory inside the CPU module.
Loading will start at 28-bit address \$00ZZYYXX. If loading tries to go beyond
\$00FFFFFF, it wraps around and continue at \$00000000.
You can use \hypporef{loadfile\_attic} to load a file into hyper memory. The
hyper memory is the 8MB or more of memory in the external RAM chips.
\item [Example:]
Loads a file into memory starting at \$48000.
\acmelisting{loadfile.asm}
\end{hyppotrap}
% ******************************************************************************
% loadfile_attic
% ******************************************************************************
\newpage
\begin{hyppotrap}{loadfile\_attic}{D640}{3E}
\item [Service:]
Loads a file into hyper memory.
\item [Preconditions:]
The name of the file to load has been set using \hypporef{setname}.
\item [Inputs:]
\register{X}{The LSB of the address to start loading from}
\register{Y}{The middle byte of the address to start loading from}
\register{Z}{The MSB of the address to start loading from}
\item [Postconditions:]
No additional file descriptors are open.
\item [Errors:]
\errordesc{84}{too many open files}{hos\_loadfile\_attic uses one file
descriptor internally, but all the file descriptors are in use. Close some or
all of the file descriptors using \hypporef{closedir}, \hypporef{closefile}
or \hypporef{closeall}.}
\errordesc{88}{file not found}{The file was not found in the current directory
of the current drive.}
\item [History:]
\availablefrom{1.2}
\item [Remarks:]
This service can load files up to 16MB in size into the first 16MB of hyper
memory. Hyper memory is the 8MB or more of memory in the external RAM chips.
Loading will start at 28-bit address \$08ZZYYXX. If loading tries to go beyond
\$08FFFFFF, the loading will wrap around and continue at \$08000000.
You can use \hypporef{loadfile} to load a file into chip memory. The chip
memory is the 384KB or more of memory inside the CPU module.
\end{hyppotrap}
% ******************************************************************************
% mkdir
% ******************************************************************************
\newpage
\begin{hyppotrap}{mkdir}{D640}{0E}
\item [Service:]
Creates a sub-directory.
\item [Errors:]
\errordesc{8D}{file exists}{A sub-directory or file already exists with the
current Hyppo filename in the current working directory of the current
drive.}
\notimplemented
\end{hyppotrap}
% ******************************************************************************
% mkfile
% ******************************************************************************
\begin{hyppotrap}{mkfile}{D640}{1E}
\item [Service:]
Creates a file.
\item [Errors:]
\errordesc{8D}{file exists}{A sub-directory or file already exists with the
current Hyppo filename in the current working directory of the current
drive.}
\notimplemented
\end{hyppotrap}
% ******************************************************************************
% opendir
% ******************************************************************************
\newpage
\begin{hyppotrap}{opendir}{D640}{12}
\item [Service:]
Opens the current working directory for reading the file entries in it.
\item [Preconditions:]
The drive and directory you want to read have already been set up using
\hypporef{selectdrive} and \hypporef{chdir} if necessary.
\item [Outputs:]
\register{A}{The file descriptor for reading the directory. You are
responsible for closing this file descriptor using \hypporef{closedir}.}
\item [Postconditions:]
\hypporef{readdir} reads the first FAT dir entry in the directory.
\item [Errors:]
\errordesc{84}{too many open files}{All the file descriptors are in use.
\hypporef{opendir} and \hypporef{openfile} share the same very small pool of
file descriptors. Close some or all of the file descriptors using
\hypporef{closedir}, \hypporef{closefile} or \hypporef{closeall}.}
\errordesc{87}{not a directory}{The FAT dir entry last found is for a file.
Use \hypporef{openfile} for files.}
\item [History:]
\availablefrom{1.2}
\item [Example:]
Calls processdirentry for each FAT dir entry in the current working directory.
processdirentry is assumed to be defined elsewhere.
\acmelisting{opendir.asm}
\end{hyppotrap}