[f40a309] | 1 | /*
|
---|
| 2 | =============================================================================
|
---|
| 3 | dcopy.c -- copy MIDAS-VII to disk
|
---|
| 4 | Version 3 -- 1988-09-01 -- D.N. Lynx Crowe
|
---|
| 5 | =============================================================================
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[b28a12e] | 8 | #include "ram.h"
|
---|
[f40a309] | 9 |
|
---|
| 10 | #define PROGID "midas.abs" /* MIDAS-VII program file name */
|
---|
| 11 |
|
---|
[b28a12e] | 12 | /*
|
---|
[f40a309] | 13 | */
|
---|
| 14 |
|
---|
| 15 | /*
|
---|
| 16 | =============================================================================
|
---|
| 17 | dcopy() -- copy MIDAS-VII to disk
|
---|
| 18 | =============================================================================
|
---|
| 19 | */
|
---|
| 20 |
|
---|
[7258c6a] | 21 | int16_t dcopy(void)
|
---|
[f40a309] | 22 | {
|
---|
| 23 | register FILE *fp;
|
---|
[7258c6a] | 24 | register int8_t *from;
|
---|
| 25 | register int32_t wrtlen, loadlen, bsslen, txtlen;
|
---|
[f40a309] | 26 |
|
---|
| 27 | defect = 0; /* reset error word */
|
---|
| 28 |
|
---|
[7258c6a] | 29 | txtlen = (int32_t)&etext - (int32_t)&Lo_RAM; /* calculate text length */
|
---|
| 30 | bsslen = (int32_t)&end - (int32_t)&edata; /* calculate BSS length */
|
---|
[f40a309] | 31 |
|
---|
[7258c6a] | 32 | loadlen = (int32_t)&edata - (int32_t)&Lo_RAM; /* calculate write length */
|
---|
[f40a309] | 33 |
|
---|
| 34 | /* create the object file header */
|
---|
| 35 |
|
---|
| 36 | mphead.F_Magic = F_R_C; /* magic = contiguous file */
|
---|
| 37 | mphead.F_Text = txtlen; /* text length */
|
---|
| 38 | mphead.F_Data = p_dlen; /* data length */
|
---|
| 39 | mphead.F_BSS = bsslen; /* BSS length */
|
---|
| 40 | mphead.F_Symtab = 0L; /* symbol table length */
|
---|
| 41 | mphead.F_Res1 = 0L; /* reserved area #1 */
|
---|
[4422c8e] | 42 | mphead.F_Res2 = (int32_t)&Lo_RAM; /* text base */
|
---|
[f40a309] | 43 | mphead.F_Res3 = 0xFFFF; /* flag word */
|
---|
| 44 |
|
---|
| 45 | /* ***** initialize for a (possibly) new disk here ***** */
|
---|
| 46 |
|
---|
| 47 | /* open MIDAS-VII object file for writing */
|
---|
| 48 |
|
---|
| 49 | preio(); /* kill the LCD backlight */
|
---|
| 50 |
|
---|
| 51 | if ((FILE *)NULL EQ (fp = fopenb(PROGID, "w"))) {
|
---|
| 52 |
|
---|
| 53 | defect = 1; /* couldn't open file */
|
---|
| 54 | postio(); /* restore LCD backlight */
|
---|
| 55 | return(FAILURE);
|
---|
| 56 | }
|
---|
| 57 |
|
---|
[fa38804] | 58 |
|
---|
[f40a309] | 59 | /* write program header to disk */
|
---|
| 60 |
|
---|
| 61 | from = &mphead;
|
---|
| 62 |
|
---|
| 63 | for (wrtlen = sizeof mphead; wrtlen--; )
|
---|
| 64 | if (EOF EQ putc(*from++, fp)) {
|
---|
| 65 |
|
---|
| 66 | defect = 2; /* couldn't write program header */
|
---|
| 67 | fclose(fp);
|
---|
| 68 | postio(); /* restore LCD backlight */
|
---|
| 69 | return(FAILURE);
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | /* write MIDAS-VII to disk */
|
---|
| 73 |
|
---|
| 74 | from = &Lo_RAM;
|
---|
| 75 |
|
---|
| 76 | for (wrtlen = loadlen; wrtlen--; )
|
---|
| 77 | if (EOF EQ putc(*from++, fp)) {
|
---|
| 78 |
|
---|
| 79 | defect = 3; /* couldn't write program */
|
---|
| 80 | fclose(fp);
|
---|
| 81 | postio(); /* restore LCD backlight */
|
---|
| 82 | return(FAILURE);
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | /* flush and close file */
|
---|
| 86 |
|
---|
| 87 | fflush(fp);
|
---|
| 88 | fclose(fp);
|
---|
| 89 | postio(); /* restore LCD backlight */
|
---|
| 90 | return(SUCCESS);
|
---|
| 91 | }
|
---|
[6262b5c] | 92 |
|
---|