source: buchla-68k/orig/RAM/DCOPY.C@ 4f508e6

Last change on this file since 4f508e6 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Imported original source code.

  • Property mode set to 100755
File size: 2.6 KB
Line 
1/*
2 =============================================================================
3 dcopy.c -- copy MIDAS-VII to disk
4 Version 3 -- 1988-09-01 -- D.N. Lynx Crowe
5 =============================================================================
6*/
7
8#include "stddefs.h"
9#include "stdio.h"
10#include "objdefs.h"
11
12#define PROGID "midas.abs" /* MIDAS-VII program file name */
13
14extern short defect; /* error code */
15
16extern char end, edata, etext; /* loader symbols */
17
18extern long p_dlen; /* size of data (from basepage) */
19
20extern Lo_RAM(); /* lowest address loaded (lowram.s) */
21
22extern struct EXFILE mphead; /* MIDAS-VII program header */
23
24/*
25
26*/
27
28/*
29 =============================================================================
30 dcopy() -- copy MIDAS-VII to disk
31 =============================================================================
32*/
33
34short
35dcopy()
36{
37 register FILE *fp;
38 register char *from;
39 register long wrtlen, loadlen, bsslen, txtlen;
40
41 defect = 0; /* reset error word */
42
43 txtlen = (long)&etext - (long)&Lo_RAM; /* calculate text length */
44 bsslen = (long)&end - (long)&edata; /* calculate BSS length */
45
46 loadlen = (long)&edata - (long)&Lo_RAM; /* calculate write length */
47
48 /* create the object file header */
49
50 mphead.F_Magic = F_R_C; /* magic = contiguous file */
51 mphead.F_Text = txtlen; /* text length */
52 mphead.F_Data = p_dlen; /* data length */
53 mphead.F_BSS = bsslen; /* BSS length */
54 mphead.F_Symtab = 0L; /* symbol table length */
55 mphead.F_Res1 = 0L; /* reserved area #1 */
56 mphead.F_Res2 = &Lo_RAM; /* text base */
57 mphead.F_Res3 = 0xFFFF; /* flag word */
58
59 /* ***** initialize for a (possibly) new disk here ***** */
60
61 /* open MIDAS-VII object file for writing */
62
63 preio(); /* kill the LCD backlight */
64
65 if ((FILE *)NULL EQ (fp = fopenb(PROGID, "w"))) {
66
67 defect = 1; /* couldn't open file */
68 postio(); /* restore LCD backlight */
69 return(FAILURE);
70 }
71
72/*
73
74*/
75 /* write program header to disk */
76
77 from = &mphead;
78
79 for (wrtlen = sizeof mphead; wrtlen--; )
80 if (EOF EQ putc(*from++, fp)) {
81
82 defect = 2; /* couldn't write program header */
83 fclose(fp);
84 postio(); /* restore LCD backlight */
85 return(FAILURE);
86 }
87
88 /* write MIDAS-VII to disk */
89
90 from = &Lo_RAM;
91
92 for (wrtlen = loadlen; wrtlen--; )
93 if (EOF EQ putc(*from++, fp)) {
94
95 defect = 3; /* couldn't write program */
96 fclose(fp);
97 postio(); /* restore LCD backlight */
98 return(FAILURE);
99 }
100
101 /* flush and close file */
102
103 fflush(fp);
104 fclose(fp);
105 postio(); /* restore LCD backlight */
106 return(SUCCESS);
107}
Note: See TracBrowser for help on using the repository browser.