CC = gcc
WARNINGS = -Wall -Wextra -pedantic
-CFLAGS = $(WARNINGS) -march=armv8-a -mfloat-abi=hard -mfpu=neon-fp-armv8 -O3 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
+CFLAGS = $(WARNINGS) -I. -march=armv8-a -mfloat-abi=hard -mfpu=neon-fp-armv8 -O3 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
LFLAGS = $(WARNINGS) `sdl2-config --libs`
TARGET = $(EXENAME)$(EXE)
#include <sys/types.h>
#include <unistd.h>
#include <sys/ioctl.h>
-#include "main.h"
+#include "emulator.h"
#include "gpio/gpio.h"
#include "platforms/amiga/gayle-ide/ide.h"
-#include "../platforms/platforms.h"
+#include "platforms/platforms.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
goto skip_line;
trim_whitespace(parse_line);
-
+
get_next_string(parse_line, cur_cmd, &str_pos, ' ');
switch (get_config_item_type(cur_cmd)) {
printf("Unknown config item %s on line %d.\n", cur_cmd, cur_line);
break;
}
-
+
skip_line:;
cur_line++;
}
-#include "../m68k.h"
+#ifndef _CONFIG_FILE_H
+#define _CONFIG_FILE_H
+
+#include "m68k.h"
+
+#include <unistd.h>
#define MAX_NUM_MAPPED_ITEMS 8
#define SIZE_KILO 1024
int get_named_mapped_item(struct emulator_config *cfg, char *name);
int get_mapped_item_by_address(struct emulator_config *cfg, uint32_t address);
unsigned int get_int(char *str);
+
+#endif /* _CONFIG_FILE_H */
+#include "m68k.h"
+#include "emulator.h"
+#include "platforms/platforms.h"
+#include "input/input.h"
+
+#include "platforms/amiga/Gayle.h"
+#include "platforms/amiga/gayle-ide/ide.h"
+#include "platforms/amiga/amiga-registers.h"
+#include "platforms/amiga/rtg/rtg.h"
+#include "platforms/amiga/hunk-reloc.h"
+#include "platforms/amiga/piscsi/piscsi.h"
+#include "platforms/amiga/piscsi/piscsi-enums.h"
+#include "platforms/amiga/net/pi-net.h"
+#include "platforms/amiga/net/pi-net-enums.h"
+#include "gpio/ps_protocol.h"
+
#include <assert.h>
#include <dirent.h>
#include <endian.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
-#include <sys/ioctl.h>
-#include "m68k.h"
-#include "main.h"
-#include "platforms/platforms.h"
-#include "input/input.h"
-#include "platforms/amiga/Gayle.h"
-#include "platforms/amiga/gayle-ide/ide.h"
-#include "platforms/amiga/amiga-registers.h"
-#include "platforms/amiga/rtg/rtg.h"
-#include "platforms/amiga/hunk-reloc.h"
-#include "platforms/amiga/piscsi/piscsi.h"
-#include "platforms/amiga/piscsi/piscsi-enums.h"
-#include "platforms/amiga/net/pi-net.h"
-#include "platforms/amiga/net/pi-net-enums.h"
-#include "gpio/ps_protocol.h"
unsigned char read_ranges;
unsigned int read_addr[8];
if (cfg->platform->handle_reset)
cfg->platform->handle_reset(cfg);
-
+
m68k_write_memory_16(INTENA, 0x7FFF);
ovl = 1;
m68k_write_memory_8(0xbfe201, 0x0001); // AMIGA OVL
-//
-// BCM283x SMI interface
-// Derived from Documentation
-// GVL 15-Oct-2014
-//
-#ifndef MAIN__HEADER
-#define MAIN__HEADER
+/**
+ * pistorm
+ * emulator function declarations
+ */
+#ifndef _EMULATOR_H
+#define _EMULATOR_H
+
+// see feature_set_macros(7)
+#define _GNU_SOURCE
#include <stdint.h>
uint16_t read8(uint32_t address);
*/
-
void cpu_pulse_reset(void);
void m68ki_int_ack(uint8_t int_level);
int cpu_irq_ack(int level);
void m68k_write_memory_16(unsigned int address, unsigned int value);
void m68k_write_memory_32(unsigned int address, unsigned int value);
-
-
-#endif /* MAIN__HEADER */
-
+#endif /* _EMULATOR_H */
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
-#include "../m68k.h"
-#include "../platforms/amiga/Gayle.h"
-#include "../platforms/amiga/gayle-ide/ide.h"
+#include "m68k.h"
+#include "platforms/amiga/Gayle.h"
+#include "platforms/amiga/gayle-ide/ide.h"
#include "gpio_old.h"
// I/O access
/*
Original Copyright 2020 Claude Schwarz
- Code reorganized and rewritten by
+ Code reorganized and rewritten by
Niklas Ekström 2021 (https://github.com/niklasekstrom)
*/
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
+
#include "ps_protocol.h"
+#include "m68k.h"
volatile unsigned int *gpio;
volatile unsigned int *gpclk;
-#include <termios.h>
-#include <unistd.h>
+#include <linux/input.h>
+#include <pthread.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
-#include <linux/input.h>
-#include "../platforms/platforms.h"
+#include <termios.h>
+#include <unistd.h>
+
+#include "platforms/platforms.h"
#include "input.h"
#define NONE 0x80
#define M68K_USE_64_BIT OPT_ON
-#include "main.h"
+#include "emulator.h"
//#define m68k_read_memory_8(A) read16(A)
#include <time.h>
#include <endian.h>
-#include "../shared/rtc.h"
-#include "../../config_file/config_file.h"
+#include "platforms/shared/rtc.h"
+#include "config_file/config_file.h"
#include "gayle-ide/ide.h"
#include "amiga-registers.h"
}
if (ide0)
ide_reset_begin(ide0);
-
+
if (num_ide_drives == 0) {
// No IDE drives mounted, disable IDE component of Gayle
printf("No IDE drives mounted, disabling Gayle IDE component.\n");
-#include "../platforms.h"
+#include "platforms/platforms.h"
#include "amiga-autoconf.h"
#include <stdio.h>
#include <stdlib.h>
break;
}
-
+
if ((address & 1) == 0 && (address / 2) < (int)sizeof(ac_fast_ram_rom)) {
if (ac_z2_type[ac_z2_current_pic] == ACTYPE_MAPFAST_Z2 && address / 2 == 1) {
val = get_autoconf_size(cfg->map_size[ac_z2_index[ac_z2_current_pic]]);
val <<= 4;
if (address != 0 && address != 2 && address != 0x40 && address != 0x42)
val ^= 0xff;
-
+
return (unsigned int)val;
}
+#include "config_file/config_file.h"
+
#define AC_Z2_BASE 0xE80000
#define AC_Z3_BASE 0xFF000000
#define AC_SIZE (64 * 1024)
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
-#include "../platforms.h"
#include "amiga-autoconf.h"
#include "amiga-registers.h"
-#include "../shared/rtc.h"
#include "hunk-reloc.h"
-#include "piscsi/piscsi.h"
-#include "piscsi/piscsi-enums.h"
-#include "net/pi-net.h"
#include "net/pi-net-enums.h"
+#include "net/pi-net.h"
+#include "piscsi/piscsi-enums.h"
+#include "piscsi/piscsi.h"
+#include "platforms/platforms.h"
+#include "platforms/shared/rtc.h"
#include "rtg/rtg.h"
int handle_register_read_amiga(unsigned int addr, unsigned char type, unsigned int *val);
index = get_named_mapped_item(cfg, z2_autoconf_id);
if (index != -1)
goto more_z2_fast;
-
+
for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i ++) {
// Restore any "zapped" autoconf items so they can be reinitialized if needed.
if (cfg->map_id[i] && strcmp(cfg->map_id[i], z2_autoconf_zap_id) == 0) {
fclose(in);
}
}
-
+
return 0;
}
#include "Gayle.h"
-#include "../../config_file/config_file.h"
+#include "config_file/config_file.h"
#include "amiga-registers.h"
uint8_t rtc_emulation_enabled = 1;
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
-#include "../../config_file/config_file.h"
+#include "config_file/config_file.h"
uint8_t dmac_reg_idx = 0;
uint8_t dmac_reg_values[0xFFFF];
#include <errno.h>
#include <time.h>
#include <arpa/inet.h>
-#include "../../../config_file/config_file.h"
+#include "config_file/config_file.h"
#include "ide.h"
#define IDE_IDLE 0
#define IDE_CMD 1
#define IDE_DATA_IN 2
#define IDE_DATA_OUT 3
-
+
#define DCR_NIEN 2
#define DCR_SRST 4
uint16_t cyl;
if (d->controller->lba4 & DEVH_LBA) {
-/* fprintf(stderr, "XLATE LBA %02X:%02X:%02X:%02X\n",
+/* fprintf(stderr, "XLATE LBA %02X:%02X:%02X:%02X\n",
t->lba4, t->lba3, t->lba2, t->lba1);*/
if (d->lba)
return ((d->header_present) ? 2 : 0) + (((t->drive->controller->lba4 & DEVH_HEAD) << 24) | (t->drive->controller->lba3 << 16) | (t->drive->controller->lba2 << 8) | t->drive->controller->lba1);
c->drive[0].taskfile.status |= ST_BSY;
if (c->drive[1].present)
c->drive[1].taskfile.status |= ST_BSY;
-}
+}
static void ide_srst_end(struct ide_controller *c)
{
if (d->dptr == d->data + 512) {
if (ide_write_sector(d) < 0) {
ide_set_error(d);
- return;
+ return;
}
d->length--;
d->intrq = 1;
t->status |= ST_BSY;
t->error = 0;
t->drive->state = IDE_CMD;
-
+
/* We could complete with delays but don't do so yet */
switch(t->command) {
case IDE_CMD_EDD: /* 0x90 */
c->lba4 = v & (DEVH_HEAD|/*DEVH_DEV|*/DEVH_LBA);
break;
case ide_command_w:
- t->command = v;
+ t->command = v;
ide_issue_command(t);
break;
case ide_devctrl_w:
/*
* Free up and release and IDE controller
- */
+ */
void ide_free(struct ide_controller *c)
{
if (c->drive[0].present)
}
if (reg == ide_data)
d |= (c->data_latch << 8);
- ide_write16(c, reg, d);
+ ide_write16(c, reg, d);
}
static void make_ascii(uint16_t *p, const char *t, int len)
*d = d[1];
d[1] = c;
d += 2;
- }
+ }
}
static void make_serial(uint16_t *p)
if (type < 1 || type > MAX_DRIVE_TYPE)
return -2;
-
+
memset(ident, 0, 512);
memcpy(ident, ide_magic, 8);
if (write(fd, ident, 512) != 512)
ident[47] = 0; /* no read multi for now */
ident[51] = le16(240 /* PIO2 */ << 8); /* PIO cycle time */
ident[53] = le16(1); /* Geometry words are valid */
-
+
switch(type) {
case ACME_ROADRUNNER:
/* 504MB drive with LBA support */
make_ascii(ident + 23, "A001.001", 8);
make_ascii(ident + 27, "ACME ROADRUNNER v0.1", 40);
ident[49] = le16(1 << 9); /* LBA */
- break;
+ break;
case ACME_ULTRASONICUS:
/* 40MB drive with LBA support */
c = 977;
s = 16;
make_ascii(ident + 23, "A001.001", 8);
make_ascii(ident + 27, "ACME COYOTE v0.1", 40);
- break;
+ break;
case ACME_ACCELLERATTI:
c = 1024;
h = 16;
ident[61] = ident[58];
if (write(fd, ident, 512) != 512)
return -1;
-
+
memset(ident, 0xE5, 512);
while(sectors--)
if (write(fd, ident, 512) != 512)
- return -1;
+ return -1;
return 0;
}
+#ifndef _HUNK_RELOC_H
+#define _HUNK_RELOC_H
+
struct hunk_reloc {
uint32_t src_hunk;
uint32_t target_hunk;
void reloc_hunk(struct hunk_reloc *h, uint8_t *buf, struct hunk_info *i);
void process_hunks(FILE *in, struct hunk_info *h_info, struct hunk_reloc *r, uint32_t offset);
void reloc_hunks(struct hunk_reloc *r, uint8_t *buf, struct hunk_info *h_info);
+
+#endif /* _HUNK_RELOC_H */
NewList(&dev_base->read_list);
InitSemaphore(&dev_base->read_list_sem);
-
+
ret = 0;
ok = 1;
//}
uint32_t sz = ((uint32_t)frm[0] << 8) | ((uint32_t)frm[1]);
uint32_t ser = ((uint32_t)frm[2] << 8) | ((uint32_t)frm[3]);
uint16_t tp = ((uint16_t)frm[16] << 8) | ((uint16_t)frm[17]);
-
+
if (req->ios2_Req.io_Flags & SANA2IOF_RAW) {
frame_ptr = frm + 4;
datasize = sz;
req->ios2_Req.io_Error = req->ios2_WireError = 0;
err = 0;
}
-
+
memcpy(req->ios2_SrcAddr, frame+4+6, HW_ADDRFIELDSIZE);
memcpy(req->ios2_DstAddr, frame+4, HW_ADDRFIELDSIZE);
-
+
//D(("RXSZ %ld\n",(LONG)sz));
//D(("RXPT %ld\n",(LONG)tp));
if (broadcast) {
req->ios2_Req.io_Flags |= SANA2IOF_BCAST;
}
-
+
req->ios2_PacketType = tp;*/
return err;
}
void pinet_write_frame(struct IOSana2Req *ioreq) {
-
+
}
void exit(int status) { }
ADDTABL_1(__TermIO,a1);
void __TermIO(struct IORequest *ioreq) {
struct IOSana2Req* ios2 = (struct IOSana2Req*)ioreq;
-
+
if (!(ios2->ios2_Req.io_Flags & SANA2IOF_QUICK)) {
ReplyMsg((struct Message *)ioreq);
} else {
ULONG sz = ((ULONG)frm[0]<<8)|((ULONG)frm[1]);
ULONG ser = ((ULONG)frm[2]<<8)|((ULONG)frm[3]);
USHORT tp = ((USHORT)frm[16]<<8)|((USHORT)frm[17]);
-
+
if (req->ios2_Req.io_Flags & SANA2IOF_RAW) {
frame_ptr = frm+4;
datasize = sz;
req->ios2_Req.io_Error = req->ios2_WireError = 0;
err = 0;
}
-
+
memcpy(req->ios2_SrcAddr, frame+4+6, HW_ADDRFIELDSIZE);
memcpy(req->ios2_DstAddr, frame+4, HW_ADDRFIELDSIZE);
-
+
//D(("RXSZ %ld\n",(LONG)sz));
//D(("RXPT %ld\n",(LONG)tp));
if (broadcast) {
req->ios2_Req.io_Flags |= SANA2IOF_BCAST;
}
-
+
req->ios2_PacketType = tp;
return err;
ULONG rc=0;
struct BufferManagement *bm;
USHORT sz=0;
-
+
if (req->ios2_Req.io_Flags & SANA2IOF_RAW) {
sz = req->ios2_DataLength;
} else {
#include <endian.h>
#include "pi-net.h"
#include "pi-net-enums.h"
-#include "../../../config_file/config_file.h"
-#include "../../../gpio/ps_protocol.h"
+#include "config_file/config_file.h"
+#include "gpio/ps_protocol.h"
uint32_t pinet_u32[4];
static const char *op_type_names[4] = {
#include <fcntl.h>
#include <unistd.h>
#include <endian.h>
-#include "../hunk-reloc.h"
-#include "piscsi.h"
+
+#include "config_file/config_file.h"
+#include "gpio/ps_protocol.h"
#include "piscsi-enums.h"
-#include "../../../config_file/config_file.h"
-#include "../../../gpio/ps_protocol.h"
+#include "piscsi.h"
+#include "platforms/amiga/hunk-reloc.h"
#define BE(val) be32toh(val)
#define BE16(val) be16toh(val)
void piscsi_find_filesystems(struct piscsi_dev *d) {
if (!d->num_partitions)
return;
-
+
uint8_t fs_found = 0;
-
+
uint8_t *fhb_block = malloc(512);
lseek64(d->fd, d->fshd_offs, SEEK_SET);
struct FileSysHeaderBlock *fhb = (struct FileSysHeaderBlock *)fhb_block;
read(d->fd, fhb_block, 512);
-
+
while (BE(fhb->fhb_ID) == FS_IDENTIFIER) {
char *dosID = (char *)&fhb->fhb_DosType;
#ifdef PISCSI_DEBUG
DEBUG("[FSHD] File system %c%c%c/%d already loaded. Skipping.\n", dosID[0], dosID[1], dosID[2], dosID[3]);
if (BE(fhb->fhb_Next) == 0xFFFFFFFF)
goto fs_done;
-
+
goto skip_fs_load_lseg;
}
}
memcpy(dst_data + addr, piscsi_rom_ptr + PISCSI_DRIVER_OFFSET, 0x4000 - PISCSI_DRIVER_OFFSET);
piscsi_hinfo.base_offset = val;
-
+
reloc_hunks(piscsi_hreloc, dst_data + addr, &piscsi_hinfo);
#define PUTNODELONG(val) *(uint32_t *)&dst_data[p_offs] = htobe32(val); p_offs += 4;
skip_disk:;
}
}
-
+
break;
}
case PISCSI_CMD_NEXTPART:
}
return 0;
}
-
+
switch (addr & 0xFFFF) {
case PISCSI_CMD_ADDR1: case PISCSI_CMD_ADDR2: case PISCSI_CMD_ADDR3: case PISCSI_CMD_ADDR4: {
int i = ((addr & 0xFFFF) - PISCSI_CMD_ADDR1) / 4;
+#include <stdint.h>
+
+#include "platforms/amiga/hunk-reloc.h"
+
#define TDF_EXTCOM (1<<15)
#define CMD_INVALID 0
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
-#include "../../../config_file/config_file.h"
+#include "config_file/config_file.h"
#ifndef FAKESTORM
-#include "../../../gpio/ps_protocol.h"
+#include "gpio/ps_protocol.h"
#endif
#include "rtg.h"
else {
SET_RTG_PIXELS2_COND_MASK(&dptr[xs << format], fg_color[format], bg_color[format], format);
}
-
+
xs += 7;
}
else {
else {
SET_RTG_PIXELS2_COND_MASK(&dptr[xs << format], fg_color[format], bg_color[format], format);
}
-
+
xs += 7;
}
else {
+#include "emulator.h"
+#include "rtg.h"
+
+#include <pthread.h>
#include <SDL2/SDL.h>
-#include <stdio.h>
#include <stdint.h>
+#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
-#include <pthread.h>
#include <string.h>
-#include "rtg.h"
+#include <unistd.h>
#define RTG_INIT_ERR(a) { printf(a); *data->running = 0; }
if (reinit)
goto reinit_sdl;
-
+
if (indexed_buf)
free(indexed_buf);
#include <string.h>
#include <time.h>
#include "rtg.h"
-#include "../../../config_file/config_file.h"
+#include "config_file/config_file.h"
uint8_t rtg_u8[4];
uint16_t rtg_x[8], rtg_y[8];
-#include "../platforms.h"
#include <stdlib.h>
#include <string.h>
+#include "platforms/platforms.h"
+
int handle_register_read_dummy(unsigned int addr, unsigned char type, unsigned int *val);
int handle_register_write_dummy(unsigned int addr, unsigned int value, unsigned char type);
-#include "../config_file/config_file.h"
+#include "config_file/config_file.h"
enum base_platforms {
PLATFORM_NONE,
=============================================================================*/
-#include "../m68kcpu.h" // which includes softfloat.h after defining the basic types
+#include "m68kcpu.h" // which includes softfloat.h after defining the basic types
/*----------------------------------------------------------------------------
| Floating-point rounding mode, extended double-precision rounding precision,