Difference between revisions of "Programming in MDOS"

From Ninerpedia
Jump to navigation Jump to search
m
 
(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== Extended Operations (XOPs) ==
* [[MDOS command line|Getting the arguments from the command line]]
* [[Device access in TIC]]
* [[MDOS XOP Definitions]]
* [[Geneve keyboard control]]
* [[Benchmarking]]
* [[Setting the Geneve clock|Setting the real-time clock]]


MDOS makes frequent use of XOPs and offers them for user programs. An XOP (extended operation) is a special command of the TMS processor family which causes a [[Terminology#C|context switch]], transferring control to a location that is specified in a table.
[[Category:MDOS]]
 
[[Category:Programming| ]]
Here are the details of the [[MDOS XOP Definitions]].
 
== Device access in TIC ==
 
=== Reading and writing disk sectors ===
 
The following code demonstrates how level-2 file access can be used in a TIC program. It copies a file, independent of the file format, by reading a sector and writing to a target file. Each sector is allocated when written.
 
This sample code is certainly not the best way to copy files (wasting a lot of time by repeatedly and writing single sectors); it is only intended to illustrate the level-2 access.
 
#include <stdio_h>
#include <stdlib_h>
main(argc, argv)
int argc; char *argv[];
{
    int  res, sect, i;
    char rbuf[256];
    int  *ibuf;
    if (argc<2)
    {
        printf("Syntax: filecopy <from_file> <to_file>\n");
        return;
    }
    /* First we get the metadata */
    res = bread(argv[1], 0, 0, rbuf);
    check(res);
    /* write the old metadata as new metadata */
    res = bwrite(argv[2], 0, 0, rbuf);
    check(res);
    /* copy the file sector by sector */
    ibuf = rbuf;
    sect = ibuf[2];
    for (i=0; i < sect; i++)
    {
        printf("Copying sector %d of %d\r", i+1, sect);
        res = bread(argv[1], i, 1, rbuf);
        check(res);
        res = bwrite(argv[2], i, 1, rbuf);
        check(res);
    }
}
void check(code)
int code;
{
    if (code != 0)
    {
        printf("Error, code = %d\n", code);
        exit(7);
    }
}

Latest revision as of 13:38, 28 May 2016