Subversion Repositories SvarDOS

Rev

Rev 1377 | Rev 1780 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1377 Rev 1779
Line 1... Line 1...
1
/* This file is part of the svarlang project and is published under the terms
1
/* This file is part of the svarlang project and is published under the terms
2
 * of the MIT license.
2
 * of the MIT license.
3
 *
3
 *
4
 * Copyright (C) 2021-2023 Mateusz Viste
4
 * Copyright (C) 2021-2024 Mateusz Viste
5
 *
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a
6
 * Permission is hereby granted, free of charge, to any person obtaining a
7
 * copy of this software and associated documentation files (the "Software"),
7
 * copy of this software and associated documentation files (the "Software"),
8
 * to deal in the Software without restriction, including without limitation
8
 * to deal in the Software without restriction, including without limitation
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
Line 74... Line 74...
74
}
74
}
75
 
75
 
76
 
76
 
77
/* routines below are simplified (dos-based) versions of the libc FILE-related
77
/* routines below are simplified (dos-based) versions of the libc FILE-related
78
 * functions. Using them avoids a dependency on FILE, hence makes the binary
78
 * functions. Using them avoids a dependency on FILE, hence makes the binary
79
 * smaller if the application does not need to pull fopen() and friends */
79
 * smaller if the application does not need to pull fopen() and friends
-
 
80
 * I use pragma aux directives for more compact size. open-watcom only. */
80
#ifndef WITHSTDIO
81
#ifndef WITHSTDIO
81
static unsigned short FOPEN(const char *s) {
-
 
82
  unsigned short fname_seg = FP_SEG(s);
-
 
83
  unsigned short fname_off = FP_OFF(s);
-
 
84
  unsigned short res = 0; /* fd 0 is already used by stdout so it's a good error value */
-
 
85
  _asm {
-
 
86
    push dx
-
 
87
    push ds
-
 
88
 
-
 
89
    mov ax, fname_seg
-
 
90
    mov dx, fname_off
-
 
91
    mov ds, ax
-
 
92
    mov ax, 0x3d00  /* open file, read-only (fname at DS:DX) */
-
 
93
    int 0x21
-
 
94
    pop ds
-
 
95
    jc ERR
-
 
96
    mov res, ax
-
 
97
 
82
 
98
    ERR:
-
 
99
    pop dx
83
static unsigned short FOPEN(const char *s);
100
  }
-
 
101
 
84
 
-
 
85
#pragma aux FOPEN = \
-
 
86
"push ds" \
-
 
87
"mov ds, ax" \
-
 
88
"mov ax, 0x3D00" /* open file, read-only (fname at DS:DX) */ \
102
  return(res);
89
"int 0x21" \
-
 
90
"jnc DONE" \
-
 
91
"xor ax, ax" \
103
}
92
"DONE:" \
-
 
93
"pop ds" \
-
 
94
parm [ax dx] \
-
 
95
value [ax];
104
 
96
 
105
 
97
 
106
static void FCLOSE(unsigned short handle) {
98
static void FCLOSE(unsigned short handle) {
107
  _asm {
99
  _asm {
108
    mov ah, 0x3e
100
    mov ah, 0x3e