2114 |
mateusz.vi |
1 |
/*
|
|
|
2 |
* measure the time it takes to load an LNG file
|
|
|
3 |
* Copyright (C) 2024 Mateusz Viste
|
|
|
4 |
*/
|
|
|
5 |
|
|
|
6 |
#include <stdio.h>
|
|
|
7 |
#include <stdlib.h>
|
|
|
8 |
#include <dos.h>
|
|
|
9 |
#include <conio.h> /* outp() */
|
|
|
10 |
|
|
|
11 |
#include "../svarlang.h"
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
static unsigned long nowtime = 0; /* current time counter */
|
|
|
15 |
static void interrupt (*oldfunc)(void); /* interrupt function pointer */
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
static void interrupt handle_clock(void) {
|
|
|
20 |
static int callmod = 0;
|
|
|
21 |
|
|
|
22 |
/* increment the time */
|
|
|
23 |
nowtime += 858; /* one cycle is 858.21us to be exact */
|
|
|
24 |
|
|
|
25 |
/* increment the callmod */
|
|
|
26 |
callmod++;
|
|
|
27 |
callmod &= 63; /* call the original clock INT every 64 calls */
|
|
|
28 |
|
|
|
29 |
/* if this is the 64th call, then call handler */
|
|
|
30 |
if (callmod == 0) {
|
|
|
31 |
nowtime += 13; /* compensate for integer division inaccuracy */
|
|
|
32 |
_chain_intr(oldfunc);
|
|
|
33 |
} else { /* otherwise, clear the interrupt controller */
|
|
|
34 |
outp(0x20, 0x20); /* end of interrupt */
|
|
|
35 |
}
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
|
|
|
39 |
/* This routine will stop the timer. It has void return value so that it
|
|
|
40 |
* can be an exit procedure. */
|
|
|
41 |
static void timer_stop(void) {
|
|
|
42 |
/* Disable interrupts */
|
|
|
43 |
_disable();
|
|
|
44 |
|
|
|
45 |
/* Reinstate the old interrupt handler */
|
|
|
46 |
_dos_setvect(0x08, oldfunc);
|
|
|
47 |
|
|
|
48 |
/* Reinstate the clock rate to standard 18.2 Hz */
|
|
|
49 |
outp(0x43, 0x36); /* Set up for count to be sent */
|
|
|
50 |
outp(0x40, 0x00); /* LSB = 00 \_together make 65536 (0) */
|
|
|
51 |
outp(0x40, 0x00); /* MSB = 00 / */
|
|
|
52 |
|
|
|
53 |
/* Enable interrupts */
|
|
|
54 |
_enable();
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
/* This routine will start the fast clock rate by installing the handle_clock
|
|
|
59 |
* routine as the interrupt service routine for the clock interrupt and then
|
|
|
60 |
* setting the interrupt rate up to its higher speed by programming the 8253
|
|
|
61 |
* timer chip. */
|
|
|
62 |
static void timer_init(void) {
|
|
|
63 |
/* Store the old interrupt handler */
|
|
|
64 |
oldfunc = _dos_getvect(0x08);
|
|
|
65 |
|
|
|
66 |
/* Set the nowtime to zero */
|
|
|
67 |
nowtime = 0;
|
|
|
68 |
|
|
|
69 |
/* Disable interrupts */
|
|
|
70 |
_disable();
|
|
|
71 |
|
|
|
72 |
/* Install the new interrupt handler */
|
|
|
73 |
_dos_setvect(0x08, handle_clock);
|
|
|
74 |
|
|
|
75 |
/* Increase the clock rate */
|
|
|
76 |
outp(0x43, 0x36); /* Set up for count to be sent */
|
|
|
77 |
outp(0x40, 0x00); /* LSB = 00 \_together make 2^10 = 1024 */
|
|
|
78 |
outp(0x40, 0x04); /* MSB = 04 / */
|
|
|
79 |
|
|
|
80 |
/* Enable interrupts */
|
|
|
81 |
_enable();
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
|
|
|
85 |
int main(int argc, char **argv) {
|
|
|
86 |
int r;
|
|
|
87 |
|
|
|
88 |
if (argc != 2) {
|
|
|
89 |
puts("loads lang from FDISK.LNG and measure how long it took");
|
|
|
90 |
puts("usage: tim lang (example: tim PL)");
|
|
|
91 |
return(1);
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
timer_init();
|
|
|
95 |
r = svarlang_load("FDISK.LNG", argv[1]);
|
|
|
96 |
timer_stop();
|
|
|
97 |
|
|
|
98 |
if (r != 0) {
|
|
|
99 |
printf("svarlang_load('FDISK.LNG', '%s') failed with err %d\n", argv[1], r);
|
|
|
100 |
return(1);
|
|
|
101 |
} else {
|
|
|
102 |
int i, count = 0;
|
|
|
103 |
printf("svarlang_load('FDISK.LNG', '%s') took %lu ms\nFirst 3 strings:\n", argv[1], nowtime / 1024);
|
|
|
104 |
for (i = 0; i < 0xffff; i++) {
|
|
|
105 |
const char *s = svarlang_strid(i);
|
|
|
106 |
if (*s == 0) continue;
|
|
|
107 |
puts(s);
|
|
|
108 |
count++;
|
|
|
109 |
if (count == 3) break;
|
|
|
110 |
}
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
|
|
|
114 |
return(0);
|
|
|
115 |
}
|