libmenu: Fix cursor on exit from showmenus()
[syslinux.git] / sample / filetest.c
blob2ef772a18a279e67dbe660287c52b9191f497831
1 #include <com32.h>
2 #include <stdarg.h>
4 #define NULL ((void *)0)
5 int printf(const char *, ...);
6 int putchar(int);
8 static inline void memset(void *buf, int ch, unsigned int len)
10 asm volatile ("cld; rep; stosb":"+D" (buf), "+c"(len):"a"(ch):"memory");
13 static void strcpy(char *dst, const char *src)
15 while (*src)
16 *dst++ = *src++;
18 *dst = '\0';
21 static void printregs(const com32sys_t * r)
23 printf("eflags = %08x ds = %04x es = %04x fs = %04x gs = %04x\n"
24 "eax = %08x ebx = %08x ecx = %08x edx = %08x\n"
25 "ebp = %08x esi = %08x edi = %08x esp = %08x\n",
26 r->eflags.l, r->ds, r->es, r->fs, r->gs,
27 r->eax.l, r->ebx.l, r->ecx.l, r->edx.l,
28 r->ebp.l, r->esi.l, r->edi.l, r->_unused_esp.l);
31 int __start(void)
33 unsigned int ax, cx, si, t;
34 com32sys_t inreg, outreg;
35 char *p;
37 /* Test null system call */
38 inreg.eflags.l = 0xffffffff;
39 inreg.eax.l = 0x11110000;
40 inreg.ecx.l = 0x22222222;
41 inreg.edx.l = 0x33333333;
42 inreg.ebx.l = 0x44444444;
43 inreg.ebp.l = 0x55555555;
44 inreg.esi.l = 0x66666666;
45 inreg.edi.l = 0x77777777;
46 inreg.ds = 0xaaaa;
47 inreg.es = 0xbbbb;
48 inreg.fs = 0xcccc;
49 inreg.gs = 0xdddd;
50 printregs(&inreg);
51 __com32.cs_intcall(0x22, &inreg, &outreg);
52 printregs(&outreg);
53 printf("----\n");
55 memset(&inreg, 0, sizeof inreg);
56 memset(&outreg, 0, sizeof outreg);
57 strcpy(__com32.cs_bounce, "test.txt");
58 inreg.eax.w[0] = 0x0006; // Open file
59 inreg.esi.w[0] = OFFS(__com32.cs_bounce);
60 inreg.es = SEG(__com32.cs_bounce);
61 printregs(&inreg);
62 __com32.cs_intcall(0x22, &inreg, &outreg);
63 printregs(&outreg);
64 printf("----\n");
66 si = outreg.esi.w[0]; /* File handle */
67 cx = outreg.ecx.w[0]; /* Block size */
68 ax = outreg.eax.l; /* File length */
70 while (si) {
71 /* We can only read 64K per call */
72 t = (ax > 65536) ? 65536 / cx : (ax + cx - 1) / cx;
74 memset(&inreg, 0, sizeof inreg);
75 inreg.esi.w[0] = si;
76 inreg.ecx.w[0] = t; /* Block count */
77 inreg.eax.w[0] = 0x0007; // Read file
78 inreg.ebx.w[0] = OFFS(__com32.cs_bounce);
79 inreg.es = SEG(__com32.cs_bounce);
80 printregs(&inreg);
81 __com32.cs_intcall(0x22, &inreg, &outreg);
82 printregs(&outreg);
83 printf("----\n");
84 si = outreg.esi.w[0];
86 /* Print the buffer */
87 t = (ax < 65536) ? ax : 65536;
88 p = __com32.cs_bounce;
89 while (t) {
90 putchar(*p++);
91 t--;
92 ax--;
96 return 0;