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

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

Added missing includes and declarations.

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