* © 2017 Aaron Taylor <ataylor at subgeniuskitty dot com>
* See LICENSE.txt file for copyright and license details.
void print_usage( char ** argv
) {
printf( "PDP-11 Serial Loader %d.%d (www.subgeniuskitty.com)\n"
"Usage: %s [option] ...\n"
" -h Help (prints this message)\n"
" -i <string> Path to input file (raw binary image)\n"
" -o <string> Path to serial port (/dev/cuau0 for first port on FreeBSD)\n"
, VER_MAJOR
, VER_MINOR
, argv
[0]
int main( int argc
, char ** argv
) {
char * device
, * binary_file
;
* Process command line arguments
while((c
= getopt(argc
,argv
,"hi:o:")) != -1) {
* Process the binary image file
if((binary_fd
= fopen(binary_file
,"r")) < 0) {
fprintf(stderr
, "Failed to open %s\n", binary_file
);
fseek(binary_fd
, 0L, SEEK_END
);
bytes
= (uint16_t) ftell(binary_fd
);
uint16_t * buffer
= malloc(bytes
);
fread(buffer
, 1, bytes
, binary_fd
);
* Open and configure the serial port
if((serial_fd
= open(device
, O_RDWR
| O_NOCTTY
)) < 0) {
fprintf(stderr
, "Failed to open %s\n", device
);
tcgetattr(serial_fd
, &options
);
options
.c_cflag
&= ~CSIZE
; /* Mask the character size bits */
options
.c_cflag
|= CS8
; /* Select 8 data bits */
options
.c_cflag
&= ~PARENB
; /* Select no parity */
options
.c_cflag
&= ~CSTOPB
; /* Select 1 stop bit */
options
.c_oflag
&= ~OPOST
; /* Select raw output */
options
.c_cflag
|= CLOCAL
; /* CLOCAL -> Succeed on open() even w/o connection */
options
.c_cflag
|= CREAD
; /* CREAD -> Enable receiver */
tcsetattr(serial_fd
, TCSANOW
, &options
); /* TCSANOW -> The change occurs immediately */
cfsetspeed(&options
, B9600
);
uint16_t words
= bytes
/ 2;
for(int i
= 0; i
< words
; i
++) checksum
+= buffer
[i
];
printf("Checksum: %o\n", checksum
);
printf("Bytes (for R1): %o\n", bytes
);
printf("Press ENTER to begin transmission.");
if((k
= getchar()) != 012) { /* Only continue on ENTER (LF -> 012) */
write(serial_fd
, buffer
, bytes
);