Subversion Repositories SvarDOS

Rev

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

Rev 448 Rev 449
Line 31... Line 31...
31
#include "rmod.h"
31
#include "rmod.h"
32
 
32
 
33
#include "rmodinit.h"
33
#include "rmodinit.h"
34
 
34
 
35
 
35
 
36
/* returns segment where rmod is installed */
36
/* returns far pointer to rmod's settings block on success */
37
unsigned short rmod_install(unsigned short envsize) {
37
struct rmod_props far *rmod_install(unsigned short envsize) {
38
  char far *myptr, far *mcb;
38
  char far *myptr, far *mcb;
39
  unsigned short far *owner;
39
  unsigned short far *owner;
-
 
40
  const unsigned short sizeof_rmodandprops_paras = rmod_len + sizeof(struct rmod_props) + 15 / 16;
40
  unsigned int rmodseg = 0xffff;
41
  unsigned int rmodseg = 0xffff;
41
  unsigned int envseg = 0;
42
  unsigned int envseg = 0;
-
 
43
  struct rmod_props far *res = NULL;
42
 
44
 
43
  /* read my current env segment from PSP */
45
  /* read my current env segment from PSP */
44
  _asm {
46
  _asm {
45
    push ax
47
    push ax
46
    push bx
48
    push bx
Line 50... Line 52...
50
    pop bx
52
    pop bx
51
    pop ax
53
    pop ax
52
  }
54
  }
53
 
55
 
54
  /* printf("original (PSP) env buffer at %04X\r\n", envseg); */
56
  /* printf("original (PSP) env buffer at %04X\r\n", envseg); */
-
 
57
 
-
 
58
  /* if envseg is zero, then enforce our own one (MSDOS 5 does not provide a default env) */
-
 
59
  if ((envseg == 0) && (envsize == 0)) envsize = 256;
-
 
60
 
55
  /* if custom envsize requested, convert it to number of paragraphs */
61
  /* if custom envsize requested, convert it to number of paragraphs */
56
  if (envsize != 0) {
62
  if (envsize != 0) {
57
    envsize += 15;
63
    envsize += 15;
58
    envsize /= 16;
64
    envsize /= 16;
59
  }
65
  }
Line 77... Line 83...
77
    mov ax, 0x5801
83
    mov ax, 0x5801
78
    mov bx, 0x0082
84
    mov bx, 0x0082
79
    int 0x21
85
    int 0x21
80
    /* ask for a memory block and save the given segment to rmodseg */
86
    /* ask for a memory block and save the given segment to rmodseg */
81
    mov ah, 0x48
87
    mov ah, 0x48
82
    mov bx, (rmod_len + 15) / 16
88
    mov bx, sizeof_rmodandprops_paras
83
    int 0x21
89
    int 0x21
84
    jc ALLOC_FAIL
90
    jc ALLOC_FAIL
85
    mov rmodseg, ax
91
    mov rmodseg, ax
86
    /* ask for a memory block for the environment and save it to envseg (only if custom size requested) */
92
    /* ask for a memory block for the environment and save it to envseg (only if custom size requested) */
87
    mov bx, envsize
93
    mov bx, envsize
Line 103... Line 109...
103
    int 0x21
109
    int 0x21
104
  }
110
  }
105
 
111
 
106
  if (rmodseg == 0xffff) {
112
  if (rmodseg == 0xffff) {
107
    outputnl("malloc error");
113
    outputnl("malloc error");
108
    return(0xffff);
114
    return(NULL);
109
  }
115
  }
110
 
116
 
111
  /* copy rmod to its destination */
117
  /* copy rmod to its destination */
112
  myptr = MK_FP(rmodseg, 0);
118
  myptr = MK_FP(rmodseg, 0);
113
  _fmemcpy(myptr, rmod, rmod_len);
119
  _fmemcpy(myptr, rmod, rmod_len);
Line 122... Line 128...
122
  mcb = MK_FP(envseg - 1, 0);
128
  mcb = MK_FP(envseg - 1, 0);
123
  owner = (void far *)(mcb + 1);
129
  owner = (void far *)(mcb + 1);
124
  *owner = rmodseg;
130
  *owner = rmodseg;
125
  _fmemcpy(mcb + 8, "SVARENV", 8);
131
  _fmemcpy(mcb + 8, "SVARENV", 8);
126
 
132
 
-
 
133
  /* if env block is newly allocated, fill it with a few NULLs */
-
 
134
  if (envsize != 0) {
-
 
135
    owner = MK_FP(envseg, 0);
-
 
136
    owner[0] = 0;
-
 
137
    owner[1] = 0;
-
 
138
  }
-
 
139
 
-
 
140
  /* prepare result (rmod props) */
-
 
141
  res = MK_FP(rmodseg, rmod_len);
-
 
142
  _fmemset(res, 0, sizeof(*res));
-
 
143
  res->rmodseg = rmodseg;
-
 
144
 
127
  /* write env segment to rmod buffer */
145
  /* write env segment to rmod buffer */
128
  owner = MK_FP(rmodseg, RMOD_OFFSET_ENVSEG);
146
  owner = MK_FP(rmodseg, RMOD_OFFSET_ENVSEG);
129
  *owner = envseg;
147
  *owner = envseg;
130
 
148
 
131
  /* write boot drive to rmod bootdrive field */
149
  /* write boot drive to rmod bootdrive field */
Line 177... Line 195...
177
    pop si
195
    pop si
178
    pop bx
196
    pop bx
179
    pop ax
197
    pop ax
180
  }
198
  }
181
 
199
 
182
  return(rmodseg);
200
  return(res);
183
}
201
}
184
 
202
 
185
 
203
 
186
/* look up my parent: if it's rmod then return its segment,
204
/* look up my parent: if it's rmod then return a ptr to its props struct,
187
 * otherwise return 0xffff */
205
 * otherwise return NULL */
188
unsigned short rmod_find(void) {
206
struct rmod_props far *rmod_find(void) {
189
  unsigned short *parent = (void *)0x0C; /* parent's seg in PSP[Ch] ("prev. int22 handler") */
207
  unsigned short *parent = (void *)0x0C; /* parent's seg in PSP[Ch] ("prev. int22 handler") */
190
  unsigned short far *ptr;
208
  unsigned short far *ptr;
191
  const unsigned short sig[] = {0x1983, 0x1985, 0x2017, 0x2019};
209
  const unsigned short sig[] = {0x1983, 0x1985, 0x2017, 0x2019};
192
  unsigned char i;
210
  unsigned char i;
193
  /* is it rmod? */
211
  /* is it rmod? */
194
  ptr = MK_FP(*parent, 0);
212
  ptr = MK_FP(*parent, 0);
195
  for (i = 0; i < 4; i++) if (ptr[i] != sig[i]) return(0xffff);
213
  for (i = 0; i < 4; i++) if (ptr[i] != sig[i]) return(NULL);
196
  /* match successfull (rmod is my parent) */
214
  /* match successfull (rmod is my parent) */
197
  return(*parent);
215
  return(MK_FP(*parent, rmod_len));
198
}
216
}
199
 
217
 
200
 
218
 
201
/* update rmod's pointer to comspec */
219
/* update rmod's pointer to comspec */
202
void rmod_updatecomspecptr(unsigned short rmod_seg, unsigned short env_seg) {
220
void rmod_updatecomspecptr(unsigned short rmod_seg, unsigned short env_seg) {