mirror of
https://github.com/dschmenk/apple2pi.git
synced 2025-02-19 18:31:32 +00:00
Added binary load and binary run commands
Load a binary file to an address on the Apple II. Then run it if using brun. Modelled after DOS BLOAD and BRUN.
This commit is contained in:
parent
269bc8c9ab
commit
9971e7c348
@ -1,4 +1,4 @@
|
||||
BIN=a2serclk a2pid a2mon dskread dskwrite bintomon
|
||||
BIN=a2serclk a2pid a2mon dskread dskwrite bintomon bload brun
|
||||
|
||||
all: $(BIN)
|
||||
|
||||
|
BIN
src/a2slideshow.bin
Executable file
BIN
src/a2slideshow.bin
Executable file
Binary file not shown.
64
src/bload.c
Executable file
64
src/bload.c
Executable file
@ -0,0 +1,64 @@
|
||||
#include "a2lib.c"
|
||||
#define MAXSIZE 65536
|
||||
|
||||
unsigned char membuff[MAXSIZE];
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
FILE *binfile;
|
||||
unsigned char *memptr;
|
||||
int i, addr, len, result, fd;
|
||||
int pifd = a2open(argc > 3 ? argv[3] : "127.0.0.1");
|
||||
if (pifd < 0)
|
||||
{
|
||||
perror("Unable to connect to Apple II Pi");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (argc < 3)
|
||||
{
|
||||
perror("Usage: bload <filename> <address> [ip address]\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
addr = (int)strtol(argv[2], NULL, 0);
|
||||
if (addr > MAXSIZE)
|
||||
{
|
||||
perror("Address out of range\n");
|
||||
a2close(pifd);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
sleep(1);
|
||||
fflush(stdin);
|
||||
if ((binfile = fopen(argv[1], "rb")))
|
||||
{
|
||||
len = fread(membuff, 1, MAXSIZE, binfile);
|
||||
fclose(binfile);
|
||||
}
|
||||
else
|
||||
{
|
||||
perror("Unable to read file\n");
|
||||
a2close(pifd);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (addr + len > MAXSIZE)
|
||||
len = MAXSIZE - addr;
|
||||
memptr = membuff;
|
||||
while (len)
|
||||
{
|
||||
printf(".");
|
||||
fflush(stdout);
|
||||
if (len > 512)
|
||||
{
|
||||
a2write(pifd, addr, 512, memptr);
|
||||
addr += 512;
|
||||
memptr += 512;
|
||||
len -= 512;
|
||||
}
|
||||
else
|
||||
{
|
||||
a2write(pifd, addr, len, memptr);
|
||||
len = 0;
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
a2close(pifd);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
69
src/brun.c
Executable file
69
src/brun.c
Executable file
@ -0,0 +1,69 @@
|
||||
#include "a2lib.c"
|
||||
#define MAXSIZE 65536
|
||||
|
||||
unsigned char membuff[MAXSIZE];
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
FILE *binfile;
|
||||
unsigned char *memptr;
|
||||
int i, entry, addr, len, result, fd;
|
||||
int pifd = a2open(argc > 3 ? argv[3] : "127.0.0.1");
|
||||
if (pifd < 0)
|
||||
{
|
||||
perror("Unable to connect to Apple II Pi");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (argc < 3)
|
||||
{
|
||||
perror("Usage: bload <filename> <address> [ip address]\n");
|
||||
a2close(pifd);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
entry = addr = (int)strtol(argv[2], NULL, 0);
|
||||
if (addr > MAXSIZE)
|
||||
{
|
||||
perror("Address out of range\n");
|
||||
a2close(pifd);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
sleep(1);
|
||||
fflush(stdin);
|
||||
if ((binfile = fopen(argv[1], "rb")))
|
||||
{
|
||||
len = fread(membuff, 1, MAXSIZE, binfile);
|
||||
fclose(binfile);
|
||||
}
|
||||
else
|
||||
{
|
||||
perror("Unable to read file\n");
|
||||
a2close(pifd);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (addr + len > MAXSIZE)
|
||||
len = MAXSIZE - addr;
|
||||
memptr = membuff;
|
||||
printf("Loading");
|
||||
while (len)
|
||||
{
|
||||
printf(".");
|
||||
fflush(stdout);
|
||||
if (len > 512)
|
||||
{
|
||||
a2write(pifd, addr, 512, memptr);
|
||||
addr += 512;
|
||||
memptr += 512;
|
||||
len -= 512;
|
||||
}
|
||||
else
|
||||
{
|
||||
a2write(pifd, addr, len, memptr);
|
||||
len = 0;
|
||||
}
|
||||
}
|
||||
printf("\nCalling Apple II...");
|
||||
fflush(stdout);
|
||||
a2call(pifd, entry, &result);
|
||||
a2close(pifd);
|
||||
printf("\nReturned: %d\n", result);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user