| [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 */
|
|---|
| 42 | mphead.F_Res2 = &Lo_RAM; /* text base */
|
|---|
| 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 |
|
|---|
| 58 | /* |
|---|
| 59 |
|
|---|
| 60 | */
|
|---|
| 61 | /* write program header to disk */
|
|---|
| 62 |
|
|---|
| 63 | from = &mphead;
|
|---|
| 64 |
|
|---|
| 65 | for (wrtlen = sizeof mphead; wrtlen--; )
|
|---|
| 66 | if (EOF EQ putc(*from++, fp)) {
|
|---|
| 67 |
|
|---|
| 68 | defect = 2; /* couldn't write program header */
|
|---|
| 69 | fclose(fp);
|
|---|
| 70 | postio(); /* restore LCD backlight */
|
|---|
| 71 | return(FAILURE);
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | /* write MIDAS-VII to disk */
|
|---|
| 75 |
|
|---|
| 76 | from = &Lo_RAM;
|
|---|
| 77 |
|
|---|
| 78 | for (wrtlen = loadlen; wrtlen--; )
|
|---|
| 79 | if (EOF EQ putc(*from++, fp)) {
|
|---|
| 80 |
|
|---|
| 81 | defect = 3; /* couldn't write program */
|
|---|
| 82 | fclose(fp);
|
|---|
| 83 | postio(); /* restore LCD backlight */
|
|---|
| 84 | return(FAILURE);
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | /* flush and close file */
|
|---|
| 88 |
|
|---|
| 89 | fflush(fp);
|
|---|
| 90 | fclose(fp);
|
|---|
| 91 | postio(); /* restore LCD backlight */
|
|---|
| 92 | return(SUCCESS);
|
|---|
| [6262b5c] | 93 | }
|
|---|
| 94 |
|
|---|