source: buchla-68k/ram/dcopy.c@ 0c834c5

Last change on this file since 0c834c5 was 0580615, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Point of no return.

  • Property mode set to 100644
File size: 2.5 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 void Lo_RAM(void);
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 dcopy(void)
35{
36 register FILE *fp;
37 register char *from;
38 register long wrtlen, loadlen, bsslen, txtlen;
39
40 defect = 0; /* reset error word */
41
42 txtlen = (long)&etext - (long)&Lo_RAM; /* calculate text length */
43 bsslen = (long)&end - (long)&edata; /* calculate BSS length */
44
45 loadlen = (long)&edata - (long)&Lo_RAM; /* calculate write length */
46
47 /* create the object file header */
48
49 mphead.F_Magic = F_R_C; /* magic = contiguous file */
50 mphead.F_Text = txtlen; /* text length */
51 mphead.F_Data = p_dlen; /* data length */
52 mphead.F_BSS = bsslen; /* BSS length */
53 mphead.F_Symtab = 0L; /* symbol table length */
54 mphead.F_Res1 = 0L; /* reserved area #1 */
55 mphead.F_Res2 = &Lo_RAM; /* text base */
56 mphead.F_Res3 = 0xFFFF; /* flag word */
57
58 /* ***** initialize for a (possibly) new disk here ***** */
59
60 /* open MIDAS-VII object file for writing */
61
62 preio(); /* kill the LCD backlight */
63
64 if ((FILE *)NULL EQ (fp = fopenb(PROGID, "w"))) {
65
66 defect = 1; /* couldn't open file */
67 postio(); /* restore LCD backlight */
68 return(FAILURE);
69 }
70
71/*
72
73*/
74 /* write program header to disk */
75
76 from = &mphead;
77
78 for (wrtlen = sizeof mphead; wrtlen--; )
79 if (EOF EQ putc(*from++, fp)) {
80
81 defect = 2; /* couldn't write program header */
82 fclose(fp);
83 postio(); /* restore LCD backlight */
84 return(FAILURE);
85 }
86
87 /* write MIDAS-VII to disk */
88
89 from = &Lo_RAM;
90
91 for (wrtlen = loadlen; wrtlen--; )
92 if (EOF EQ putc(*from++, fp)) {
93
94 defect = 3; /* couldn't write program */
95 fclose(fp);
96 postio(); /* restore LCD backlight */
97 return(FAILURE);
98 }
99
100 /* flush and close file */
101
102 fflush(fp);
103 fclose(fp);
104 postio(); /* restore LCD backlight */
105 return(SUCCESS);
106}
Note: See TracBrowser for help on using the repository browser.