mirror of
https://github.com/anarkavre/pom1.git
synced 2024-06-03 02:29:27 +00:00
216 lines
3.9 KiB
C
216 lines
3.9 KiB
C
// Pom1 Apple 1 Emulator
|
|
// Copyright (C) 2000 Verhille Arnaud
|
|
// Copyright (C) 2012 John D. Corrado
|
|
//
|
|
// This program is free software; you can redistribute it and/or
|
|
// modify it under the terms of the GNU General Public License
|
|
// as published by the Free Software Foundation; either version 2
|
|
// of the License, or (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program; if not, write to the Free Software
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include "configuration.h"
|
|
#include "pia6820.h"
|
|
#include "memory.h"
|
|
|
|
static unsigned char mem[0x10000]; // 64K
|
|
static int ram8k = 0;
|
|
static int writeInRom = 1;
|
|
static int krusaderRom = 0;
|
|
|
|
static int loadMonitor(void)
|
|
{
|
|
const char *romdir = getRomDirectory();
|
|
char *filename;
|
|
FILE *fp;
|
|
|
|
filename = (char *)malloc(strlen(romdir) + 13);
|
|
sprintf(filename, "%s/monitor.rom", romdir);
|
|
|
|
fp = fopen(filename, "rb");
|
|
|
|
free(filename);
|
|
|
|
if (fp)
|
|
{
|
|
fread(&mem[0xFF00], 1, 0x100, fp);
|
|
fclose(fp);
|
|
}
|
|
else
|
|
return 0;
|
|
|
|
return 1;
|
|
}
|
|
|
|
static int loadBasic(void)
|
|
{
|
|
const char *romdir = getRomDirectory();
|
|
char *filename;
|
|
FILE *fp;
|
|
|
|
filename = (char *)malloc(strlen(romdir) + 11);
|
|
sprintf(filename, "%s/basic.rom", romdir);
|
|
|
|
fp = fopen(filename, "rb");
|
|
|
|
free(filename);
|
|
|
|
if (fp)
|
|
{
|
|
fread(&mem[0xE000], 1, 0x1000, fp);
|
|
fclose(fp);
|
|
}
|
|
else
|
|
return 0;
|
|
|
|
return 1;
|
|
}
|
|
|
|
static int loadKrusader() {
|
|
const char *romdir = getRomDirectory();
|
|
char *filename;
|
|
FILE *fp;
|
|
|
|
filename = (char *)malloc(strlen(romdir) + 14);
|
|
sprintf(filename, "%s/krusader.rom", romdir);
|
|
|
|
fp = fopen(filename, "rb");
|
|
|
|
free(filename);
|
|
|
|
if (fp) {
|
|
fread(&mem[0xE000], 1, 0x2000, fp);
|
|
fclose(fp);
|
|
}
|
|
else {
|
|
return 0;
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
static void loadRoms() {
|
|
if (krusaderRom) {
|
|
if (!loadKrusader()) {
|
|
fprintf(stderr, "stderr: Could not load krusader\n");
|
|
exit(1);
|
|
}
|
|
}
|
|
else {
|
|
if (!loadMonitor()) {
|
|
fprintf(stderr, "stderr: Could not load monitor\n");
|
|
exit(1);
|
|
}
|
|
|
|
if (!loadBasic()) {
|
|
fprintf(stderr, "stderr: Could not load basic\n");
|
|
exit(1);
|
|
}
|
|
}
|
|
}
|
|
|
|
int getKrusaderRom() {
|
|
return krusaderRom;
|
|
}
|
|
|
|
void setKrusaderRom(int b) {
|
|
krusaderRom = b;
|
|
}
|
|
|
|
void resetMemory(void) {
|
|
memset(mem, 0, 0xFFFF);
|
|
loadRoms();
|
|
}
|
|
|
|
void setRam8k(int b)
|
|
{
|
|
ram8k = b;
|
|
}
|
|
|
|
int getRam8k()
|
|
{
|
|
return ram8k;
|
|
}
|
|
|
|
void setWriteInRom(int b)
|
|
{
|
|
writeInRom = b;
|
|
}
|
|
|
|
int getWriteInRom(void)
|
|
{
|
|
return writeInRom;
|
|
}
|
|
|
|
unsigned char memRead(unsigned short address)
|
|
{
|
|
if (address == 0xD013)
|
|
return readDspCr();
|
|
if (address == 0xD012)
|
|
return readDsp();
|
|
if (address == 0xD011)
|
|
return readKbdCr();
|
|
if (address == 0xD010)
|
|
return readKbd();
|
|
|
|
return mem[address];
|
|
}
|
|
|
|
void memWrite(unsigned short address, unsigned char value)
|
|
{
|
|
if (address == 0xD013)
|
|
{
|
|
writeDspCr(value);
|
|
return;
|
|
}
|
|
if (address == 0xD012)
|
|
{
|
|
writeDsp((unsigned char)(value | 0x80));
|
|
return;
|
|
}
|
|
if (address == 0xD011)
|
|
{
|
|
writeKbdCr(value);
|
|
return;
|
|
}
|
|
if (address == 0xD010)
|
|
{
|
|
writeKbd(value);
|
|
return;
|
|
}
|
|
|
|
if (address >= 0xFF00 && !writeInRom)
|
|
return;
|
|
if (ram8k && address >= 0x2000 && address < 0xFF00)
|
|
return;
|
|
|
|
mem[address] = value;
|
|
}
|
|
|
|
unsigned char *dumpMemory(unsigned short start, unsigned short end)
|
|
{
|
|
unsigned char *fbrut = (unsigned char *)malloc(end - start + 1);
|
|
|
|
if (!fbrut)
|
|
fprintf(stderr, "stderr: Could not allocate memory block\n");
|
|
else
|
|
memcpy(fbrut, &mem[start], end - start + 1);
|
|
|
|
return fbrut;
|
|
}
|
|
|
|
void setMemory(const unsigned char *data, unsigned short start, unsigned int size)
|
|
{
|
|
memcpy(&mem[start], data, size);
|
|
}
|