Major code cleanup and code reformating

This commit is contained in:
Godzil 2021-04-05 14:19:35 +01:00
parent 4e5f796d6a
commit cc1060775c
28 changed files with 8068 additions and 7853 deletions

View File

@ -1,3 +1,10 @@
/*
* NewOswan
* dumpinfo.c: Tool to dump the metadata info about a cart rom image.
*
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
*
*/
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
@ -17,7 +24,7 @@ char *load_file(char *filename, uint32_t *fileSize)
fstat(fd, &FileStat); fstat(fd, &FileStat);
ret_ptr = (char *)mmap(NULL, FileStat.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); ret_ptr = (char *)mmap(NULL, FileStat.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
*fileSize = FileStat.st_size; *fileSize = FileStat.st_size;
@ -64,29 +71,26 @@ int main(int argc, char *argv[])
if (content != NULL) if (content != NULL)
{ {
data = (struct cart_metadata*)&(content[size - sizeof(struct cart_metadata)]); data = (struct cart_metadata *)&(content[size - sizeof(struct cart_metadata)]);
printf("%s:\n", argv[1]); printf("%s:\n", argv[1]);
if (data->farjump[0] == 0xEA) if (data->farjump[0] == 0xEA)
{ {
printf("[%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x]", printf("[%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x]", data->publishId, data->gameId[0],
data->publishId, data->gameId[0], data->gameId[1], data->flags2, data->romInfo, data->saveInfo, data->gameId[1], data->flags2, data->romInfo, data->saveInfo, data->flags & 0xFF,
data->flags & 0xFF, (data->flags>>8) & 0xFF, data->crc & 0xFF, (data->crc>>8) & 0xFF); (data->flags >> 8) & 0xFF, data->crc & 0xFF, (data->crc >> 8) & 0xFF);
printf(" - Reset @ %02X%02X:%02X%02Xh\n", printf(" - Reset @ %02X%02X:%02X%02Xh\n", data->farjump[4], data->farjump[3], data->farjump[2],
data->farjump[4], data->farjump[3], data->farjump[1]);
data->farjump[2], data->farjump[1]);
printf(" - publisher: %02X, gameId: %01X%02X\n", data->publishId, data->gameId[0], data->gameId[1]); printf(" - publisher: %02X, gameId: %01X%02X\n", data->publishId, data->gameId[0], data->gameId[1]);
printf(" - %s want to write to EEPROM\n", data->flags2&0x80?"Do":"Do not"); printf(" - %s want to write to EEPROM\n", data->flags2 & 0x80 ? "Do" : "Do not");
printf(" - %s user defined bootsplash\n", data->flagExt&0x80?"Dissallow":"Allow"); printf(" - %s user defined bootsplash\n", data->flagExt & 0x80 ? "Dissallow" : "Allow");
printf(" - Is %sbootable on a normal swan\n", data->flagExt&0x0F?"not ":""); printf(" - Is %sbootable on a normal swan\n", data->flagExt & 0x0F ? "not " : "");
printf(" - ROM Size: %02Xh\n", data->romInfo); printf(" - ROM Size: %02Xh\n", data->romInfo);
printf(" - Save type & Size: %02Xh\n", data->saveInfo); printf(" - Save type & Size: %02Xh\n", data->saveInfo);
printf(" - Flags: %d cycles ROM, %d bit ROM bus, %sRTC, %s orientation\n", printf(" - Flags: %d cycles ROM, %d bit ROM bus, %sRTC, %s orientation\n", data->flags & 0x004 ? 1 : 3,
data->flags & 0x004?1:3, data->flags & 0x002 ? 8 : 16, data->flags & 0x100 ? "" : "No ",
data->flags & 0x002?8:16, data->flags & 0x001 ? "Vertical" : "Horizontal");
data->flags & 0x100?"":"No ",
data->flags & 0x001?"Vertical":"Horizontal");
printf(" - CRC: %04Xh\n", data->crc); printf(" - CRC: %04Xh\n", data->crc);
ret = 0; ret = 0;
} }

34
main.c
View File

@ -1,5 +1,10 @@
/////////////////////////////////////////////////////////////////////////////// /*
// Wonderswan emulator * NewOswan
* main.c: Entry point
* Based on the original Oswan-unix
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
*
*/
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
// 13.04.2002: Fixed a small bug causing crashes // 13.04.2002: Fixed a small bug causing crashes
@ -7,7 +12,7 @@
// //
// //
// //
////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -38,14 +43,6 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#define LOG_PATH "oswan.log" #define LOG_PATH "oswan.log"
int gui_command=GUI_COMMAND_NONE;
int gui_mainDialogRunning;
int gui_controls_configuration_Running;
int gui_get_key_Running;
int gui_get_key_key;
int ws_videoEnhancementType=0;
int sram_path_explicit = 0; int sram_path_explicit = 0;
int ieep_path_explicit = 0; int ieep_path_explicit = 0;
@ -132,11 +129,11 @@ int main(int argc, char *argv[])
ws_rom_path = NULL; ws_rom_path = NULL;
for (int n = 1; n < argc; ++n) for (int n = 1 ; n < argc ; ++n)
{ {
if (argv[n][0] == '-') if (argv[n][0] == '-')
{ {
switch(argv[n][1]) switch (argv[n][1])
{ {
case 'C': case 'C':
if (++n < argc) if (++n < argc)
@ -165,8 +162,7 @@ int main(int argc, char *argv[])
sram_path_explicit = 1; sram_path_explicit = 1;
break; break;
default: default:break;
break;
} }
} }
else else
@ -181,7 +177,6 @@ int main(int argc, char *argv[])
{ {
if (!ws_rom_path) if (!ws_rom_path)
{ {
app_gameRunning=0;
exit(0); exit(0);
} }
@ -190,11 +185,6 @@ int main(int argc, char *argv[])
ws_set_system(ws_system); ws_set_system(ws_system);
if (ws_init(ws_rom_path)) if (ws_init(ws_rom_path))
{ {
app_rotated=ws_rotated();
app_gameRunning=1;
}
ws_reset(); ws_reset();
ws_emulate(); ws_emulate();
@ -205,6 +195,6 @@ int main(int argc, char *argv[])
} }
log_done(); log_done();
return(0); return (0);
} }

View File

@ -1,50 +0,0 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by gui.rc
//
#define IDD_DIALOG_MAIN 101
#define IDB_BITMAP1 102
#define IDB_BITMAP2 103
#define IDC_BUTTON_LOAD 1000
#define IDC_BUTTON_RESET 1001
#define IDC_BUTTON_EXIT 1002
#define IDC_RADIO1 1003
#define IDC_RADIO_WINDOWED 1003
#define IDC_RADIO2 1004
#define IDC_RADIO_FULLSCREEN 1004
#define IDC_BUTTON_LOADSTATE 1005
#define IDC_BUTTON_SAVESTATE 1006
#define IDC_RADIO3 1007
#define IDC_BUTTON_CONTINUE 1007
#define IDC_RADIO4 1008
#define IDC_BUTTON_CONTROLS 1008
#define IDC_RADIO5 1009
#define IDC_RADIO_STANDARD_MODE 1009
#define IDC_RADIO6 1010
#define IDC_RADIO_DOUBLESIZE_MODE 1010
#define IDC_RADIO7 1011
#define IDC_RADIO_SCANLINES_MODE 1011
#define IDC_RADIO8 1012
#define IDC_RADIO_50PRCTSCANLINES_MODE 1012
#define IDC_RADIO9 1013
#define IDC_RADIO_SPECIAL_MODE 1013
#define IDC_RADIO_SYSTEM_AUTODETECT 1014
#define IDC_RADIO_SYSTEM_MONO 1015
#define IDC_RADIO_SYSTEM_COLOR 1016
#define IDC_RADIO_2XSAI 1017
#define IDC_RADIO_SUPER2XSAI 1018
#define IDC_COLOUR_DEFAULT 1019
#define IDC_COLOUR_AMBER 1020
#define IDC_COLOUR_GREEN 1021
#define IDC_RADIO_SUPEREAGLE 1022
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 108
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1021
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@ -1,5 +1,5 @@
set(SOURCES audio.c emulate.c gpu.c io.c log.c memory.c rom.c ws.c) set(SOURCES audio.c emulate.c gpu.c io.c log.c memory.c rom.c ws.c)
set(HEADERS audio.h emulate.h gpu.h ieeprom.h io.h log.h memory.h rom.h ws.h) set(HEADERS audio.h emulate.h gpu.h io.h log.h memory.h rom.h ws.h)
add_library(wswan ${SOURCES} ${HEADERS}) add_library(wswan ${SOURCES} ${HEADERS})

View File

@ -1,5 +1,10 @@
//////////////////////////////////////////////////////////////////////////////// /*
// Audio * NewOswan
* audio.c:
* Based on the original Oswan-unix
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
*
*/
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
// Sound information thanks to toshi (wscamp wonderswan emulator) // Sound information thanks to toshi (wscamp wonderswan emulator)
@ -73,21 +78,21 @@ int SwpTime;
int SwpStep; int SwpStep;
unsigned int SwpCurPeriod; unsigned int SwpCurPeriod;
int MainVol=15; int MainVol = 15;
int HardVol=3; int HardVol = 3;
int ChCurVol[6]= {-1,-1,-1,-1,-1,-1}; int ChCurVol[6] = {-1, -1, -1, -1, -1, -1};
int ChCurPer[6]= {-1,-1,-1,-1,-1,-1}; int ChCurPer[6] = {-1, -1, -1, -1, -1, -1};
long ChCurPan[6]= {-1,-1,-1,-1,-1,-1}; long ChCurPan[6] = {-1, -1, -1, -1, -1, -1};
unsigned char PData[4][BUFSIZE]; unsigned char PData[4][BUFSIZE];
unsigned char PDataP[BUFSIZEP<<4]; unsigned char PDataP[BUFSIZEP << 4];
unsigned char PDataN[8][BUFSIZEN]; unsigned char PDataN[8][BUFSIZEN];
int RandData[BUFSIZEN]; int RandData[BUFSIZEN];
int CntSwp=0; int CntSwp = 0;
int PcmWrPos=0; int PcmWrPos = 0;
/* /*
const long TblChVol[16]= // n/15 n=0~15 const long TblChVol[16]= // n/15 n=0~15
@ -124,6 +129,7 @@ const long TblMainVol[4]= // 1,1/2,1/4,1/8
uint32_t ws_audio_channel_isPlaying[6]; uint32_t ws_audio_channel_isPlaying[6];
static unsigned int ws_audio_log; static unsigned int ws_audio_log;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -139,10 +145,11 @@ void ws_audio_init(void)
{ {
fprintf(log_get(), "audio init\n"); fprintf(log_get(), "audio init\n");
fflush(log_get()); fflush(log_get());
ws_audio_log=0; ws_audio_log = 0;
//ws_audio_seal_init(); //ws_audio_seal_init();
ws_audio_reset(); ws_audio_reset();
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -156,25 +163,26 @@ void ws_audio_init(void)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void ws_audio_reset(void) void ws_audio_reset(void)
{ {
WaveMap=-1; WaveMap = -1;
for (int i=0; i<6; i++) for (int i = 0 ; i < 6 ; i++)
{ {
ws_audio_stop_channel(i); ws_audio_stop_channel(i);
ws_audio_play_channel(i); ws_audio_play_channel(i);
ws_audio_set_channel_frequency(i,0); ws_audio_set_channel_frequency(i, 0);
if (i!=4) if (i != 4)
{ {
ws_audio_set_channel_pan(i,0,0); ws_audio_set_channel_pan(i, 0, 0);
} }
ws_audio_clear_channel(i); ws_audio_clear_channel(i);
} }
ws_audio_set_channel_frequency(4,0); ws_audio_set_channel_frequency(4, 0);
ws_audio_set_channel_frequency(4,1792); ws_audio_set_channel_frequency(4, 1792);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -188,95 +196,95 @@ void ws_audio_reset(void)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void ws_audio_port_write(uint32_t port, uint8_t value) void ws_audio_port_write(uint32_t port, uint8_t value)
{ {
uint32_t n,i,j,k,b; uint32_t n, i, j, k, b;
ws_ioRam[port]=value; ws_ioRam[port] = value;
switch (port) switch (port)
{ {
case 0x48: case 0x48:
if (value&0x80) if (value & 0x80)
{ {
n=(DMACH<<8)|DMACL; n = (DMACH << 8) | DMACL;
i=(DMASB<<16)|(DMASH<<8)|DMASL; i = (DMASB << 16) | (DMASH << 8) | DMASL;
j=(DMADH<<8)|DMADL; j = (DMADH << 8) | DMADL;
for(k=0; k<n; k++) for (k = 0 ; k < n ; k++)
{ {
b=cpu_readmem20(i); b = cpu_readmem20(i);
cpu_writemem20(j,b); cpu_writemem20(j, b);
i++; i++;
j++; j++;
} }
n=0; n = 0;
DMASB=(uint8_t)((i>>16)&0xFF); DMASB = (uint8_t)((i >> 16) & 0xFF);
DMASH=(uint8_t)((i>>8)&0xFF); DMASH = (uint8_t)((i >> 8) & 0xFF);
DMASL=(uint8_t)(i&0xFF); DMASL = (uint8_t)(i & 0xFF);
DMADB=(uint8_t)((j>>16)&0xFF); DMADB = (uint8_t)((j >> 16) & 0xFF);
DMADH=(uint8_t)((j>>8)&0xFF); DMADH = (uint8_t)((j >> 8) & 0xFF);
DMADL=(uint8_t)(j&0xFF); DMADL = (uint8_t)(j & 0xFF);
DMACH=(uint8_t)((n>>8)&0xFF); DMACH = (uint8_t)((n >> 8) & 0xFF);
DMACL=(uint8_t)(n&0xFF); DMACL = (uint8_t)(n & 0xFF);
value&=0x7F; value &= 0x7F;
} }
break; break;
case 0x80: case 0x80:
case 0x81: case 0x81:
i=(((unsigned int)ws_ioRam[0x81])<<8)+((unsigned int)ws_ioRam[0x80]); i = (((unsigned int)ws_ioRam[0x81]) << 8) + ((unsigned int)ws_ioRam[0x80]);
ws_audio_set_channel_frequency(0,i); ws_audio_set_channel_frequency(0, i);
break; break;
case 0x82: case 0x82:
case 0x83: case 0x83:
i=(((unsigned int)ws_ioRam[0x83])<<8)+((unsigned int)ws_ioRam[0x82]); i = (((unsigned int)ws_ioRam[0x83]) << 8) + ((unsigned int)ws_ioRam[0x82]);
ws_audio_set_channel_frequency(1,i); ws_audio_set_channel_frequency(1, i);
break; break;
case 0x84: case 0x84:
case 0x85: case 0x85:
i=(((unsigned int)ws_ioRam[0x85])<<8)+((unsigned int)ws_ioRam[0x84]); i = (((unsigned int)ws_ioRam[0x85]) << 8) + ((unsigned int)ws_ioRam[0x84]);
ws_audio_set_channel_frequency(2,i); ws_audio_set_channel_frequency(2, i);
break; break;
case 0x86: case 0x86:
case 0x87: case 0x87:
i=(((unsigned int)(ws_ioRam[0x87]&0x07))<<8)+((unsigned int)ws_ioRam[0x86]); i = (((unsigned int)(ws_ioRam[0x87] & 0x07)) << 8) + ((unsigned int)ws_ioRam[0x86]);
ws_audio_set_channel_frequency(5,i); ws_audio_set_channel_frequency(5, i);
ws_audio_set_channel_frequency(3,i); ws_audio_set_channel_frequency(3, i);
break; break;
case 0x88: case 0x88:
ws_audio_set_channel_pan(0,(value&0xF0)>>4,value&0x0F); ws_audio_set_channel_pan(0, (value & 0xF0) >> 4, value & 0x0F);
break; break;
case 0x89: case 0x89:
ws_audio_set_channel_pan(1,(value&0xF0)>>4,value&0x0F); ws_audio_set_channel_pan(1, (value & 0xF0) >> 4, value & 0x0F);
break; break;
case 0x8A: case 0x8A:
ws_audio_set_channel_pan(2,(value&0xF0)>>4,value&0x0F); ws_audio_set_channel_pan(2, (value & 0xF0) >> 4, value & 0x0F);
break; break;
case 0x8B: case 0x8B:
ws_audio_set_channel_pan(5,(value&0xF0)>>4,value&0x0F); ws_audio_set_channel_pan(5, (value & 0xF0) >> 4, value & 0x0F);
ws_audio_set_channel_pan(3,(value&0xF0)>>4,value&0x0F); ws_audio_set_channel_pan(3, (value & 0xF0) >> 4, value & 0x0F);
break; break;
case 0x8C: case 0x8C:
SwpStep=(signed char)value; SwpStep = (signed char)value;
break; break;
case 0x8D: case 0x8D:
SwpTime=(((unsigned int)value)+1)<<5; SwpTime = (((unsigned int)value) + 1) << 5;
break; break;
case 0x8E: case 0x8E:
if (value & 0x10) if (value & 0x10)
{ {
ws_audio_set_channel_pdata(5,value&0x07); ws_audio_set_channel_pdata(5, value & 0x07);
} }
else else
{ {
@ -286,11 +294,11 @@ void ws_audio_port_write(uint32_t port, uint8_t value)
break; break;
case 0x8F: case 0x8F:
WaveMap=((unsigned int)value)<<6; WaveMap = ((unsigned int)value) << 6;
break; break;
case 0x90: case 0x90:
if (value&0x01) if (value & 0x01)
{ {
ws_audio_play_channel(0); ws_audio_play_channel(0);
} }
@ -299,7 +307,7 @@ void ws_audio_port_write(uint32_t port, uint8_t value)
ws_audio_stop_channel(0); ws_audio_stop_channel(0);
} }
if ((value&0x22)==0x02) if ((value & 0x22) == 0x02)
{ {
ws_audio_play_channel(1); ws_audio_play_channel(1);
} }
@ -308,7 +316,7 @@ void ws_audio_port_write(uint32_t port, uint8_t value)
ws_audio_stop_channel(1); ws_audio_stop_channel(1);
} }
if (value&0x04) if (value & 0x04)
{ {
ws_audio_play_channel(2); ws_audio_play_channel(2);
} }
@ -317,7 +325,7 @@ void ws_audio_port_write(uint32_t port, uint8_t value)
ws_audio_stop_channel(2); ws_audio_stop_channel(2);
} }
if ((value&0x88)==0x08) if ((value & 0x88) == 0x08)
{ {
ws_audio_play_channel(3); ws_audio_play_channel(3);
} }
@ -326,7 +334,7 @@ void ws_audio_port_write(uint32_t port, uint8_t value)
ws_audio_stop_channel(3); ws_audio_stop_channel(3);
} }
if ((value&0x88)==0x88) if ((value & 0x88) == 0x88)
{ {
ws_audio_play_channel(5); ws_audio_play_channel(5);
} }
@ -338,28 +346,28 @@ void ws_audio_port_write(uint32_t port, uint8_t value)
break; break;
case 0x91: case 0x91:
value|=0x80; value |= 0x80;
HardVol = (value>>1)&0x3; HardVol = (value >> 1) & 0x3;
ws_ioRam[port]=value; // Always have external speaker ws_ioRam[port] = value; // Always have external speaker
value=ws_ioRam[0x88]; value = ws_ioRam[0x88];
ws_audio_set_channel_pan(0,(value&0xF0)>>4,value&0x0F); ws_audio_set_channel_pan(0, (value & 0xF0) >> 4, value & 0x0F);
value=ws_ioRam[0x89]; value = ws_ioRam[0x89];
ws_audio_set_channel_pan(1,(value&0xF0)>>4,value&0x0F); ws_audio_set_channel_pan(1, (value & 0xF0) >> 4, value & 0x0F);
value=ws_ioRam[0x8A]; value = ws_ioRam[0x8A];
ws_audio_set_channel_pan(2,(value&0xF0)>>4,value&0x0F); ws_audio_set_channel_pan(2, (value & 0xF0) >> 4, value & 0x0F);
value=ws_ioRam[0x8B]; value = ws_ioRam[0x8B];
ws_audio_set_channel_pan(3,(value&0xF0)>>4,value&0x0F); ws_audio_set_channel_pan(3, (value & 0xF0) >> 4, value & 0x0F);
ws_audio_set_channel_pan(5,(value&0xF0)>>4,value&0x0F); ws_audio_set_channel_pan(5, (value & 0xF0) >> 4, value & 0x0F);
break; break;
@ -376,24 +384,24 @@ void ws_audio_port_write(uint32_t port, uint8_t value)
case 0x94: case 0x94:
dbgprintf("0x94 <- 0x%2x\n", value); dbgprintf("0x94 <- 0x%2x\n", value);
fflush(stdout); fflush(stdout);
MainVol=(value&0x0f)>>2; MainVol = (value & 0x0f) >> 2;
value=ws_ioRam[0x88]; value = ws_ioRam[0x88];
ws_audio_set_channel_pan(0,(value&0xF0)>>4,value&0x0F); ws_audio_set_channel_pan(0, (value & 0xF0) >> 4, value & 0x0F);
value=ws_ioRam[0x89]; value = ws_ioRam[0x89];
ws_audio_set_channel_pan(1,(value&0xF0)>>4,value&0x0F); ws_audio_set_channel_pan(1, (value & 0xF0) >> 4, value & 0x0F);
value=ws_ioRam[0x8A]; value = ws_ioRam[0x8A];
ws_audio_set_channel_pan(2,(value&0xF0)>>4,value&0x0F); ws_audio_set_channel_pan(2, (value & 0xF0) >> 4, value & 0x0F);
value=ws_ioRam[0x8B]; value = ws_ioRam[0x8B];
ws_audio_set_channel_pan(3,(value&0xF0)>>4,value&0x0F); ws_audio_set_channel_pan(3, (value & 0xF0) >> 4, value & 0x0F);
ws_audio_set_channel_pan(5,(value&0xF0)>>4,value&0x0F); ws_audio_set_channel_pan(5, (value & 0xF0) >> 4, value & 0x0F);
break; break;
@ -401,6 +409,7 @@ void ws_audio_port_write(uint32_t port, uint8_t value)
break; break;
} }
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -414,8 +423,9 @@ void ws_audio_port_write(uint32_t port, uint8_t value)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
uint8_t ws_audio_port_read(uint8_t port) uint8_t ws_audio_port_read(uint8_t port)
{ {
return(ws_ioRam[port]); return (ws_ioRam[port]);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -431,6 +441,7 @@ void ws_audio_done(void)
{ {
ws_audio_seal_done(); ws_audio_seal_done();
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -452,37 +463,35 @@ unsigned int ws_audio_mrand(unsigned int Degree)
int Mask; int Mask;
} POLYNOMIAL; } POLYNOMIAL;
static POLYNOMIAL TblMask[]= static POLYNOMIAL TblMask[] = {{2, BIT(2), BIT(0) | BIT(1)},
{ {3, BIT(3), BIT(0) | BIT(1)},
{ 2,BIT(2),BIT(0)|BIT(1)}, {4, BIT(4), BIT(0) | BIT(1)},
{ 3,BIT(3),BIT(0)|BIT(1)}, {5, BIT(5), BIT(0) | BIT(2)},
{ 4,BIT(4),BIT(0)|BIT(1)}, {6, BIT(6), BIT(0) | BIT(1)},
{ 5,BIT(5),BIT(0)|BIT(2)}, {7, BIT(7), BIT(0) | BIT(1)},
{ 6,BIT(6),BIT(0)|BIT(1)}, {8, BIT(8), BIT(0) | BIT(2) | BIT(3) | BIT(4)},
{ 7,BIT(7),BIT(0)|BIT(1)}, {9, BIT(9), BIT(0) | BIT(4)},
{ 8,BIT(8),BIT(0)|BIT(2)|BIT(3)|BIT(4)}, {10, BIT(10), BIT(0) | BIT(3)},
{ 9,BIT(9),BIT(0)|BIT(4)}, {11, BIT(11), BIT(0) | BIT(2)},
{10,BIT(10),BIT(0)|BIT(3)}, {12, BIT(12), BIT(0) | BIT(1) | BIT(4) | BIT(6)},
{11,BIT(11),BIT(0)|BIT(2)}, {13, BIT(13), BIT(0) | BIT(1) | BIT(3) | BIT(4)},
{12,BIT(12),BIT(0)|BIT(1)|BIT(4)|BIT(6)}, {14, BIT(14), BIT(0) | BIT(1) | BIT(4) | BIT(5)},
{13,BIT(13),BIT(0)|BIT(1)|BIT(3)|BIT(4)}, {15, BIT(15), BIT(0) | BIT(1)},
{14,BIT(14),BIT(0)|BIT(1)|BIT(4)|BIT(5)}, {0, 0, 0},
{15,BIT(15),BIT(0)|BIT(1)},
{0,0,0},
}; };
static POLYNOMIAL *pTbl = TblMask; static POLYNOMIAL *pTbl = TblMask;
static int ShiftReg = 1; static int ShiftReg = 1;
int XorReg=0; int XorReg = 0;
int Masked; int Masked;
if(pTbl->N!=Degree) if (pTbl->N != Degree)
{ {
pTbl=TblMask; pTbl = TblMask;
while(pTbl->N) while (pTbl->N)
{ {
if(pTbl->N==Degree) if (pTbl->N == Degree)
{ {
break; break;
} }
@ -490,37 +499,37 @@ unsigned int ws_audio_mrand(unsigned int Degree)
pTbl++; pTbl++;
} }
if(!pTbl->N) if (!pTbl->N)
{ {
pTbl--; pTbl--;
} }
ShiftReg&=pTbl->InputBit-1; ShiftReg &= pTbl->InputBit - 1;
if(!ShiftReg) if (!ShiftReg)
{ {
ShiftReg=pTbl->InputBit-1; ShiftReg = pTbl->InputBit - 1;
} }
} }
Masked=ShiftReg&pTbl->Mask; Masked = ShiftReg & pTbl->Mask;
while(Masked) while (Masked)
{ {
XorReg^=Masked&0x01; XorReg ^= Masked & 0x01;
Masked>>=1; Masked >>= 1;
} }
if(XorReg) if (XorReg)
{ {
ShiftReg|=pTbl->InputBit; ShiftReg |= pTbl->InputBit;
} }
else else
{ {
ShiftReg&=~pTbl->InputBit; ShiftReg &= ~pTbl->InputBit;
} }
ShiftReg>>=1; ShiftReg >>= 1;
return ShiftReg; return ShiftReg;
} }
@ -682,6 +691,7 @@ int ws_audio_seal_init(void)
#endif #endif
return 1; return 1;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -736,6 +746,7 @@ void ws_audio_seal_done(void)
#endif #endif
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -771,6 +782,7 @@ void ws_audio_clear_channel(int Channel)
} }
#endif #endif
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// start playing a channel // start playing a channel
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -802,13 +814,14 @@ int ws_audio_play_channel(int Channel)
} }
else else
{ {
// ASetVoiceFrequency(ws_audio_pcm_voice[Channel],3072000/(2048-ChCurPer[Channel])); // ASetVoiceFrequency(ws_audio_pcm_voice[Channel],3072000/(2048-ChCurPer[Channel]));
APlayVoice(ws_audio_pcm_voice[Channel], &ws_audio_pcm_wave[Channel]); APlayVoice(ws_audio_pcm_voice[Channel], &ws_audio_pcm_wave[Channel]);
ASetVoiceFrequency(ws_audio_pcm_voice[Channel],3072000/(2048-ChCurPer[Channel])); ASetVoiceFrequency(ws_audio_pcm_voice[Channel],3072000/(2048-ChCurPer[Channel]));
} }
#endif #endif
return 0; return 0;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// stop playing a channel // stop playing a channel
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -843,8 +856,9 @@ int ws_audio_stop_channel(int Channel)
AStopVoice(ws_audio_pcm_voice[Channel]); AStopVoice(ws_audio_pcm_voice[Channel]);
} }
#endif #endif
return(0); return (0);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -856,7 +870,7 @@ int ws_audio_stop_channel(int Channel)
// //
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void ws_audio_set_channel_frequency(int Channel,int Period) void ws_audio_set_channel_frequency(int Channel, int Period)
{ {
#if 0 #if 0
uint32_t Freq; uint32_t Freq;
@ -900,6 +914,7 @@ void ws_audio_set_channel_frequency(int Channel,int Period)
} }
#endif #endif
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -911,7 +926,7 @@ void ws_audio_set_channel_frequency(int Channel,int Period)
// //
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void ws_audio_set_channel_volume(int Channel,int Vol) void ws_audio_set_channel_volume(int Channel, int Vol)
{ {
#if 0 #if 0
long volume; long volume;
@ -939,6 +954,7 @@ void ws_audio_set_channel_volume(int Channel,int Vol)
} }
#endif #endif
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -950,7 +966,7 @@ void ws_audio_set_channel_volume(int Channel,int Vol)
// //
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void ws_audio_set_channel_pan(int Channel,int Left,int Right) void ws_audio_set_channel_pan(int Channel, int Left, int Right)
{ {
#if 0 #if 0
long pan; long pan;
@ -1014,6 +1030,7 @@ void ws_audio_set_channel_pan(int Channel,int Left,int Right)
} }
#endif #endif
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -1025,7 +1042,7 @@ void ws_audio_set_channel_pan(int Channel,int Left,int Right)
// //
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void ws_audio_set_channel_pdata(int Channel,int Index) void ws_audio_set_channel_pdata(int Channel, int Index)
{ {
#if 0 #if 0
unsigned char *pData; unsigned char *pData;
@ -1051,6 +1068,7 @@ void ws_audio_set_channel_pdata(int Channel,int Index)
} }
#endif #endif
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -1062,7 +1080,7 @@ void ws_audio_set_channel_pdata(int Channel,int Index)
// //
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void ws_audio_set_channels_pbuf(int Addr,int Data) void ws_audio_set_channels_pbuf(int Addr, int Data)
{ {
#if 0 #if 0
int i,j; int i,j;
@ -1081,6 +1099,7 @@ void ws_audio_set_channels_pbuf(int Addr,int Data)
} }
#endif #endif
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -1102,6 +1121,7 @@ void ws_audio_rst_channel(int Channel)
} }
#endif #endif
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -1200,6 +1220,7 @@ void ws_audio_set_pcm(int Data)
} }
#endif #endif
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -1241,6 +1262,7 @@ void ws_audio_flash_pcm(void)
PCMPos=0; PCMPos=0;
#endif #endif
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -1254,12 +1276,13 @@ void ws_audio_flash_pcm(void)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void ws_audio_write_byte(uint32_t offset, uint8_t value) void ws_audio_write_byte(uint32_t offset, uint8_t value)
{ {
if (!((offset-WaveMap)&0xFFC0)) if (!((offset - WaveMap) & 0xFFC0))
{ {
ws_audio_set_channels_pbuf(offset&0x003F,value); ws_audio_set_channels_pbuf(offset & 0x003F, value);
internalRam[offset]=value; internalRam[offset] = value;
} }
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -1274,65 +1297,66 @@ void ws_audio_write_byte(uint32_t offset, uint8_t value)
void ws_audio_process(void) void ws_audio_process(void)
{ {
uint32_t i, j, b; uint32_t i, j, b;
i=ws_audio_int(); i = ws_audio_int();
PCSRL=(uint8_t)(i&0xFF); PCSRL = (uint8_t)(i & 0xFF);
PCSRH=(uint8_t)((i>>8)&0xFF); PCSRH = (uint8_t)((i >> 8) & 0xFF);
if((SDMACTL&0x88)==0x80) if ((SDMACTL & 0x88) == 0x80)
{ {
i=(SDMACH<<8)|SDMACL; i = (SDMACH << 8) | SDMACL;
j=(SDMASB<<16)|(SDMASH<<8)|SDMASL; j = (SDMASB << 16) | (SDMASH << 8) | SDMASL;
b=cpu_readmem20(j); b = cpu_readmem20(j);
if(!ws_audio_channel_isPlaying[5]) if (!ws_audio_channel_isPlaying[5])
{ {
b=0x80; b = 0x80;
} }
ws_ioRam[0x89]=b; ws_ioRam[0x89] = b;
i--; i--;
j++; j++;
if(i<32) if (i < 32)
{ {
i=0; i = 0;
SDMACTL&=0x7F; SDMACTL &= 0x7F;
} }
SDMASB=(uint8_t)((j>>16)&0xFF); SDMASB = (uint8_t)((j >> 16) & 0xFF);
SDMASH=(uint8_t)((j>>8)&0xFF); SDMASH = (uint8_t)((j >> 8) & 0xFF);
SDMASL=(uint8_t)(j&0xFF); SDMASL = (uint8_t)(j & 0xFF);
SDMACH=(uint8_t)((i>>8)&0xFF); SDMACH = (uint8_t)((i >> 8) & 0xFF);
SDMACL=(uint8_t)(i&0xFF); SDMACL = (uint8_t)(i & 0xFF);
} }
else if((SNDMOD&0x22)==0x22) else if ((SNDMOD & 0x22) == 0x22)
{ {
b=ws_ioRam[0x89]; b = ws_ioRam[0x89];
if(!ws_audio_channel_isPlaying[4]) if (!ws_audio_channel_isPlaying[4])
{ {
b=0x80; b = 0x80;
} }
} }
else else
{ {
b=0x80; b = 0x80;
} }
b>>=1; b >>= 1;
b+=0x40; b += 0x40;
if(b>0xAA) if (b > 0xAA)
{ {
b=0xAA; b = 0xAA;
} }
else if(b<0x55) else if (b < 0x55)
{ {
b=0x55; b = 0x55;
} }
ws_audio_set_pcm(b); ws_audio_set_pcm(b);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -1433,6 +1457,7 @@ void ws_audio_readState(int fp)
read(fp,&lpnStatus,sizeof(int)); read(fp,&lpnStatus,sizeof(int));
#endif #endif
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -1,5 +1,10 @@
////////////////////////////////////////////////////////////////////////////// /*
// * NewOswan
* audio.h:
* Based on the original Oswan-unix
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
*
*/
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// //
// //

View File

@ -1,6 +1,11 @@
//////////////////////////////////////////////////////////////////////////////// /*
// Main emulation loop * NewOswan
//////////////////////////////////////////////////////////////////////////////// * emulate.c:
* Based on the original Oswan-unix
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
*
*/
//////////////////////////////////////////////////////////////////////////////
// //
// //
// //
@ -23,6 +28,7 @@
#define GLFW_INCLUDE_GLEXT #define GLFW_INCLUDE_GLEXT
#define GL_SILENCE_DEPRECATION #define GL_SILENCE_DEPRECATION
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
/* "Apple" fix */ /* "Apple" fix */
#ifndef GL_TEXTURE_RECTANGLE #ifndef GL_TEXTURE_RECTANGLE
@ -40,11 +46,7 @@
#include "memory.h" #include "memory.h"
char app_window_title[256]; char app_window_title[256];
int app_gameRunning=0; int app_terminate = 0;
int app_terminate=0;
int app_fullscreen=0;
int app_rotated=0;
int ws_key_esc = 0; int ws_key_esc = 0;
@ -68,13 +70,13 @@ struct GLWindow_t
}; };
static GLWindow mainWindow; static GLWindow mainWindow;
static int window_num = 0; static int window_num = 0;
static void ShowScreen(GLWindow *g, int w, int h) static void ShowScreen(GLWindow *g, int w, int h)
{ {
glBindTexture(GL_TEXTURE_RECTANGLE, g->videoTexture); glBindTexture(GL_TEXTURE_RECTANGLE, g->videoTexture);
// glTexSubImage2D is faster when not using a texture range // glTexSubImage2D is faster when not using a texture range
glTexSubImage2D(GL_TEXTURE_RECTANGLE, 0, 0, 0, w, h, glTexSubImage2D(GL_TEXTURE_RECTANGLE, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, g->videoMemory);
GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, g->videoMemory);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glTexCoord2f(0.0f, 0.0f);
@ -92,12 +94,14 @@ static void ShowScreen(GLWindow *g, int w, int h)
glFlush(); glFlush();
} }
static void GLWindowInitEx(GLWindow *g, int w, int h) static void GLWindowInitEx(GLWindow *g, int w, int h)
{ {
g->WIDTH = w; g->WIDTH = w;
g->HEIGHT = h; g->HEIGHT = h;
g->videoTexture = window_num++; g->videoTexture = window_num++;
} }
static void setupGL(GLWindow *g, int w, int h) static void setupGL(GLWindow *g, int w, int h)
{ {
g->videoMemory = (uint8_t *)malloc(w * h * sizeof(uint16_t)); g->videoMemory = (uint8_t *)malloc(w * h * sizeof(uint16_t));
@ -120,10 +124,6 @@ static void setupGL(GLWindow *g, int w, int h)
glEnable(GL_TEXTURE_RECTANGLE); glEnable(GL_TEXTURE_RECTANGLE);
glBindTexture(GL_TEXTURE_RECTANGLE, g->videoTexture); glBindTexture(GL_TEXTURE_RECTANGLE, g->videoTexture);
// glTextureRangeAPPLE(GL_TEXTURE_RECTANGLE_NV_EXT, 0, NULL);
// glTexParameteri(GL_TEXTURE_RECTANGLE_NV_EXT, GL_TEXTURE_STORAGE_HINT_APPLE , GL_STORAGE_CACHED_APPLE);
// glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
@ -134,6 +134,7 @@ static void setupGL(GLWindow *g, int w, int h)
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
} }
void restoreGL(GLWindow *g) void restoreGL(GLWindow *g)
{ {
//Tell OpenGL how to convert from coordinates to pixel values //Tell OpenGL how to convert from coordinates to pixel values
@ -154,6 +155,7 @@ void restoreGL(GLWindow *g)
glEnable(GL_TEXTURE_RECTANGLE); glEnable(GL_TEXTURE_RECTANGLE);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
} }
static void kbHandler(GLFWwindow *window, int key, int scan, int action, int mod) static void kbHandler(GLFWwindow *window, int key, int scan, int action, int mod)
{ {
struct KeyArray *keyArray; struct KeyArray *keyArray;
@ -174,16 +176,19 @@ static void kbHandler(GLFWwindow *window, int key, int scan, int action, int mod
/*printf("key:%d, state:%d debounce:%d, laststate:%d\n", key, keyArray[key].curState, /*printf("key:%d, state:%d debounce:%d, laststate:%d\n", key, keyArray[key].curState,
keyArray[key].debounced, keyArray[key].lastState);*/ keyArray[key].debounced, keyArray[key].lastState);*/
} }
static void sizeHandler(GLFWwindow *window, int xs, int ys) static void sizeHandler(GLFWwindow *window, int xs, int ys)
{ {
glfwMakeContextCurrent(window); glfwMakeContextCurrent(window);
glViewport(0, 0, xs, ys); glViewport(0, 0, xs, ys);
ShowScreen(&mainWindow, 244, 144); ShowScreen(&mainWindow, 244, 144);
} }
static void error_callback(int error, const char *description) static void error_callback(int error, const char *description)
{ {
puts(description); puts(description);
} }
static void initDisplay(GLWindow *g) static void initDisplay(GLWindow *g)
{ {
int h = g->HEIGHT; int h = g->HEIGHT;
@ -216,10 +221,12 @@ static void initDisplay(GLWindow *g)
glfwSetKeyCallback(g->windows, kbHandler); glfwSetKeyCallback(g->windows, kbHandler);
glfwSetWindowSizeCallback(g->windows, sizeHandler); glfwSetWindowSizeCallback(g->windows, sizeHandler);
} }
static void clearScreen(GLWindow *g) static void clearScreen(GLWindow *g)
{ {
memset(g->videoMemory, 0, sizeof(uint8_t) * g->WIDTH * g->HEIGHT * 4); memset(g->videoMemory, 0, sizeof(uint8_t) * g->WIDTH * g->HEIGHT * 4);
} }
static void updateScreen(GLWindow *g) static void updateScreen(GLWindow *g)
{ {
/* Update windows code */ /* Update windows code */
@ -228,6 +235,7 @@ static void updateScreen(GLWindow *g)
glfwSwapBuffers(g->windows); glfwSwapBuffers(g->windows);
glfwPollEvents(); glfwPollEvents();
} }
uint64_t getTicks() uint64_t getTicks()
{ {
struct timeval curTime; struct timeval curTime;
@ -235,7 +243,7 @@ uint64_t getTicks()
/* Get datetime */ /* Get datetime */
gettimeofday(&curTime, NULL); gettimeofday(&curTime, NULL);
ticks = (curTime.tv_sec* 1000) + curTime.tv_usec / 1000; ticks = (curTime.tv_sec * 1000) + curTime.tv_usec / 1000;
return ticks; return ticks;
} }
@ -247,17 +255,17 @@ static inline int getKeyState(int key)
static void read_keys() static void read_keys()
{ {
ws_key_start=0; ws_key_start = 0;
ws_key_x4=0; ws_key_x4 = 0;
ws_key_x2=0; ws_key_x2 = 0;
ws_key_x1=0; ws_key_x1 = 0;
ws_key_x3=0; ws_key_x3 = 0;
ws_key_y4=0; ws_key_y4 = 0;
ws_key_y2=0; ws_key_y2 = 0;
ws_key_y1=0; ws_key_y1 = 0;
ws_key_y3=0; ws_key_y3 = 0;
ws_key_button_a=0; ws_key_button_a = 0;
ws_key_button_b=0; ws_key_button_b = 0;
if (getKeyState(GLFW_KEY_E)) if (getKeyState(GLFW_KEY_E))
{ {
@ -275,69 +283,69 @@ static void read_keys()
ws_key_esc = 1; ws_key_esc = 1;
} }
if ( getKeyState(GLFW_KEY_UP)) if (getKeyState(GLFW_KEY_UP))
{ {
ws_key_x1=1; ws_key_x1 = 1;
} }
if ( getKeyState(GLFW_KEY_DOWN)) if (getKeyState(GLFW_KEY_DOWN))
{ {
ws_key_x3=1; ws_key_x3 = 1;
} }
if (getKeyState(GLFW_KEY_RIGHT)) if (getKeyState(GLFW_KEY_RIGHT))
{ {
ws_key_x2=1; ws_key_x2 = 1;
} }
if (getKeyState(GLFW_KEY_LEFT)) if (getKeyState(GLFW_KEY_LEFT))
{ {
ws_key_x4=1; ws_key_x4 = 1;
} }
if (getKeyState(GLFW_KEY_ENTER)) if (getKeyState(GLFW_KEY_ENTER))
{ {
ws_key_start=1; ws_key_start = 1;
} }
if (getKeyState(GLFW_KEY_C)) if (getKeyState(GLFW_KEY_C))
{ {
ws_key_button_a=1; ws_key_button_a = 1;
} }
if (getKeyState(GLFW_KEY_X)) if (getKeyState(GLFW_KEY_X))
{ {
ws_key_button_b=1; ws_key_button_b = 1;
} }
if (getKeyState(GLFW_KEY_W)) if (getKeyState(GLFW_KEY_W))
{ {
ws_key_y1=1; ws_key_y1 = 1;
} }
if (getKeyState(GLFW_KEY_A)) if (getKeyState(GLFW_KEY_A))
{ {
ws_key_y4=1; ws_key_y4 = 1;
} }
if (getKeyState(GLFW_KEY_S)) if (getKeyState(GLFW_KEY_S))
{ {
ws_key_y3=1; ws_key_y3 = 1;
} }
if (getKeyState(GLFW_KEY_D)) if (getKeyState(GLFW_KEY_D))
{ {
ws_key_y2=1; ws_key_y2 = 1;
} }
if (getKeyState(GLFW_KEY_O)) if (getKeyState(GLFW_KEY_O))
{ {
ws_cyclesByLine+=10; ws_cyclesByLine += 10;
} }
if (getKeyState(GLFW_KEY_L)) if (getKeyState(GLFW_KEY_L))
{ {
ws_cyclesByLine-=10; ws_cyclesByLine -= 10;
} }
} }

View File

@ -1,32 +1,26 @@
/*
* NewOswan
* emulate.h:
* Based on the original Oswan-unix
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
*
*/
//////////////////////////////////////////////////////////////////////////////
//
//
//
//
//
//
//////////////////////////////////////////////////////////////////////////////
#ifndef EMULATE_H #ifndef EMULATE_H
#define EMULATE_H #define EMULATE_H
#include <stdint.h> #include <stdint.h>
#define KEY_ENTER 0x0D
#define KEY_SPACE 0x20
#define KEY_ESC 0x1b
#define KEY_UP 0x26
#define KEY_DOWN 0x28
#define KEY_LEFT 0x25
#define KEY_RIGHT 0x27
#define KEY_BUTTON1 0x57
#define KEY_BUTTON2 0x58
#define GUI_COMMAND_NONE 0
#define GUI_COMMAND_RESET 1
#define GUI_COMMAND_SCHEME_CHANGE 2
#define GUI_COMMAND_FILTER_CHANGE 3
extern char app_window_title[256]; extern char app_window_title[256];
extern int app_gameRunning;
extern int app_terminate; extern int app_terminate;
extern int app_fullscreen;
extern int app_rotated;
void ws_emulate(void); void ws_emulate(void);
#endif /* EMULATE_H */ #endif /* EMULATE_H */

File diff suppressed because it is too large Load Diff

View File

@ -1,34 +1,25 @@
////////////////////////////////////////////////////////////////////////////// /*
// * NewOswan
////////////////////////////////////////////////////////////////////////////// * gpu.h:
// * Based on the original Oswan-unix
// * Copyright (c) 2014-2021 986-Studio. All rights reserved.
// *
// */
//
//
//////////////////////////////////////////////////////////////////////////////
#ifndef __GPU_H__ #ifndef __GPU_H__
#define __GPU_H__ #define __GPU_H__
#include <stdint.h> #include <stdint.h>
#define COLOUR_SCHEME_DEFAULT 0
#define COLOUR_SCHEME_AMBER 1
#define COLOUR_SCHEME_GREEN 2
extern uint8_t ws_gpu_scanline; extern uint8_t ws_gpu_scanline;
extern uint8_t ws_gpu_operatingInColor; extern uint8_t ws_gpu_operatingInColor;
extern uint8_t ws_videoMode; extern uint8_t ws_videoMode;
extern int16_t ws_palette[16*4]; extern int16_t ws_palette[16 * 4];
extern int8_t ws_paletteColors[8]; extern int8_t ws_paletteColors[8];
extern int16_t wsc_palette[16*16]; extern int16_t wsc_palette[16 * 16];
extern unsigned int ws_gpu_unknownPort; extern unsigned int ws_gpu_unknownPort;
extern uint32_t vblank_count; extern uint32_t vblank_count;
void ws_gpu_init(void); void ws_gpu_init(void);
void ws_gpu_done(void); void ws_gpu_done(void);
void ws_gpu_reset(void); void ws_gpu_reset(void);

View File

@ -1,191 +0,0 @@
//////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////
//
//
//
//
//
//
//////////////////////////////////////////////////////////////////////////////
uint8_t DefaultBWEEprom[]=
{
0xff,0xff,0xff,0xff,0xff,0xff,192,0xff,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,127,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,252,0xff,1,0xff,253,0xff,253,0xff,253,0xff,253,
0xff,253,0xff,253,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,3,3,0x00,0x00,0x00,64,128,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
135,5,140,9,5,12,139,12,144,0x00,0x00,2,
0x00,76,165,0x00,128,0x00,0x00,0x00,0xff,127,0xff,127,
0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,
0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,
0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,
0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,
0xff,127,0xff,127,0xff,127,0xff,127,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,6,6,6,6,6,0x00,0x00,0x00,0x00,0x00,
1,128,15,0x00,1,1,1,15,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
'W'-54,'O'-54,'N'-54,'D'-54,'E'-54,'R'-54,'S'-54,'W'-54,'A'-54,'N'-54,0x00,0x00,0x00,0x00,0x00,
0x00,32,1,1,33,1,4,0x00,1,
0x00,152,60,127,74,1,53,1,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff
};
uint8_t DefaultColorEEprom[]=
{
0xff,0xff,0xff,0xff,0xff,0xff,192,0xff,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,127,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,252,0xff,1,0xff,253,0xff,253,0xff,253,0xff,253,
0xff,253,0xff,253,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,3,3,0x00,0x00,0x00,64,128,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
135,5,140,9,5,12,139,12,144,0x00,0x00,2,
0x00,76,165,0x00,128,0x00,0x00,0x00,0xff,127,0xff,127,
0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,
0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,
0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,
0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,
0xff,127,0xff,127,0xff,127,0xff,127,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,6,6,6,6,6,0x00,0x00,0x00,0x00,0x00,
1,128,15,0x00,1,1,1,15,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
'W'-54,'O'-54,'N'-54,'D'-54,'E'-54,'R'-54,'S'-54,'W'-54,'A'-54,'N'-54,0x00,0x00,0x00,0x00,0x00,
0x00,32,1,1,33,1,4,0x00,1,
0x00,152,60,127,74,1,53,1,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff
};

View File

@ -1,6 +1,11 @@
//////////////////////////////////////////////////////////////////////////////// /*
// I/O ports * NewOswan
//////////////////////////////////////////////////////////////////////////////// * io.c: I/O ports implementaton
* Based on the original Oswan-unix
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
*
*/
//////////////////////////////////////////////////////////////////////////////
// //
// //
// //
@ -8,7 +13,6 @@
// //
// //
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
@ -50,16 +54,8 @@ enum
EEPROM_WRITEENABLE /* 00 11 */ EEPROM_WRITEENABLE /* 00 11 */
}; };
char *eii_CommandName[] = char *eii_CommandName[] = {
{ "SUB", "WRI", "RED", "ERA", "WRD", "WRA", "ERL", "WRE",
"SUB",
"WRI",
"RED",
"ERA",
"WRD",
"WRA",
"ERL",
"WRE",
}; };
uint8_t iee_WriteEnable = false; uint8_t iee_WriteEnable = false;
@ -73,7 +69,7 @@ uint16_t cee_Databuffer = 0;
uint8_t cee_Mode = EEPROM_READ; uint8_t cee_Mode = EEPROM_READ;
uint8_t *ws_ioRam=NULL; uint8_t *ws_ioRam = NULL;
uint8_t ws_key_start; uint8_t ws_key_start;
uint8_t ws_key_x4; uint8_t ws_key_x4;
@ -88,7 +84,7 @@ uint8_t ws_key_button_a;
uint8_t ws_key_button_b; uint8_t ws_key_button_b;
uint8_t ws_key_flipped; uint8_t ws_key_flipped;
int rtcDataRegisterReadCount=0; int rtcDataRegisterReadCount = 0;
FILE *ioLogFp = NULL; FILE *ioLogFp = NULL;
@ -105,17 +101,17 @@ FILE *ioLogFp = NULL;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void ws_io_reset(void) void ws_io_reset(void)
{ {
ws_key_start=0; ws_key_start = 0;
ws_key_x4=0; ws_key_x4 = 0;
ws_key_x2=0; ws_key_x2 = 0;
ws_key_x1=0; ws_key_x1 = 0;
ws_key_x3=0; ws_key_x3 = 0;
ws_key_y4=0; ws_key_y4 = 0;
ws_key_y2=0; ws_key_y2 = 0;
ws_key_y1=0; ws_key_y1 = 0;
ws_key_y3=0; ws_key_y3 = 0;
ws_key_button_a=0; ws_key_button_a = 0;
ws_key_button_b=0; ws_key_button_b = 0;
int i; int i;
for (i = 0 ; i < 0x100 ; i++) for (i = 0 ; i < 0x100 ; i++)
@ -133,8 +129,9 @@ void ws_io_reset(void)
ws_ioRam[0xC2] = 0xFF; ws_ioRam[0xC2] = 0xFF;
ws_ioRam[0xC3] = 0xFF; ws_ioRam[0xC3] = 0xFF;
rtcDataRegisterReadCount=0; rtcDataRegisterReadCount = 0;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -148,18 +145,19 @@ void ws_io_reset(void)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void ws_io_init(void) void ws_io_init(void)
{ {
if (ws_ioRam==NULL) if (ws_ioRam == NULL)
{ {
ws_ioRam=(uint8_t*)malloc(0x100); ws_ioRam = (uint8_t *)malloc(0x100);
} }
ws_io_reset(); ws_io_reset();
ws_key_flipped=0; ws_key_flipped = 0;
#ifdef IO_DUMP #ifdef IO_DUMP
ioLogFp = fopen("iodump.csv", "wt"); ioLogFp = fopen("iodump.csv", "wt");
#endif #endif
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -173,8 +171,9 @@ void ws_io_init(void)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void ws_io_flipControls(void) void ws_io_flipControls(void)
{ {
ws_key_flipped=!ws_key_flipped; ws_key_flipped = !ws_key_flipped;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -188,7 +187,7 @@ void ws_io_flipControls(void)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void ws_io_done(void) void ws_io_done(void)
{ {
if (ws_ioRam==NULL) if (ws_ioRam == NULL)
{ {
free(ws_ioRam); free(ws_ioRam);
} }
@ -206,6 +205,7 @@ int serialfd = -1;
int serial_have_data = 0; int serial_have_data = 0;
unsigned char serial_data = 0; unsigned char serial_data = 0;
int serial_speed = BDR_9600; int serial_speed = BDR_9600;
void open_serial() void open_serial()
{ {
if (serialfd < 0) if (serialfd < 0)
@ -288,14 +288,14 @@ void check_serial_data()
} }
} }
if(serial_have_data > 0) if (serial_have_data > 0)
{ {
/* Gen an int if enabled */ /* Gen an int if enabled */
if(ws_ioRam[0xB2] & 0x04) if (ws_ioRam[0xB2] & 0x04)
{ {
ws_ioRam[0xb6] &= ~ 0x04; ws_ioRam[0xb6] &= ~0x04;
printf("SERIAL INNNNNTTTT!!!!!!!"); printf("SERIAL INNNNNTTTT!!!!!!!");
nec_int((ws_ioRam[0xb0]+3)*4); nec_int((ws_ioRam[0xb0] + 3) * 4);
} }
} }
} }
@ -390,10 +390,12 @@ uint8_t cpu_readport(uint8_t port)
case 0x91: case 0x91:
case 0x92: case 0x92:
case 0x93: case 0x93:
case 0x94:retVal = ws_audio_port_read(port); case 0x94:
retVal = ws_audio_port_read(port);
break; break;
case 0xb5:w1 = ws_ioRam[0xb5]; case 0xb5:
w1 = ws_ioRam[0xb5];
if (w1 & 0x40) if (w1 & 0x40)
{ {
@ -445,10 +447,12 @@ uint8_t cpu_readport(uint8_t port)
{ {
case WS_SYSTEM_AUTODETECT: case WS_SYSTEM_AUTODETECT:
case WS_SYSTEM_MONO: case WS_SYSTEM_MONO:
case WS_SYSTEM_COLOR:retVal = 0x00; case WS_SYSTEM_COLOR:
retVal = 0x00;
break; break;
case WS_SYSTEM_CRYSTAL:retVal = 0x80; case WS_SYSTEM_CRYSTAL:
retVal = 0x80;
break; break;
} }
break; break;
@ -509,31 +513,38 @@ uint8_t cpu_readport(uint8_t port)
switch (rtcDataRegisterReadCount) switch (rtcDataRegisterReadCount)
{ {
case 0:rtcDataRegisterReadCount++; case 0:
rtcDataRegisterReadCount++;
retVal = BCD(newtime->tm_year - 100); retVal = BCD(newtime->tm_year - 100);
goto exit; goto exit;
case 1:rtcDataRegisterReadCount++; case 1:
rtcDataRegisterReadCount++;
retVal = BCD(newtime->tm_mon); retVal = BCD(newtime->tm_mon);
goto exit; goto exit;
case 2:rtcDataRegisterReadCount++; case 2:
rtcDataRegisterReadCount++;
retVal = BCD(newtime->tm_mday); retVal = BCD(newtime->tm_mday);
goto exit; goto exit;
case 3:rtcDataRegisterReadCount++; case 3:
rtcDataRegisterReadCount++;
retVal = BCD(newtime->tm_wday); retVal = BCD(newtime->tm_wday);
goto exit; goto exit;
case 4:rtcDataRegisterReadCount++; case 4:
rtcDataRegisterReadCount++;
retVal = BCD(newtime->tm_hour); retVal = BCD(newtime->tm_hour);
goto exit; goto exit;
case 5:rtcDataRegisterReadCount++; case 5:
rtcDataRegisterReadCount++;
retVal = BCD(newtime->tm_min); retVal = BCD(newtime->tm_min);
goto exit; goto exit;
case 6:rtcDataRegisterReadCount = 0; case 6:
rtcDataRegisterReadCount = 0;
retVal = BCD(newtime->tm_sec); retVal = BCD(newtime->tm_sec);
goto exit; goto exit;
} }
@ -547,15 +558,18 @@ uint8_t cpu_readport(uint8_t port)
goto exit; goto exit;
} }
case 0xD0:retVal = 0; case 0xD0:
retVal = 0;
goto exit; goto exit;
/* Serial port link.. */ /* Serial port link.. */
case 0xB1:retVal = read_serial(); case 0xB1:
retVal = read_serial();
printf("RS232: Read %02X\n", retVal); printf("RS232: Read %02X\n", retVal);
goto exit; goto exit;
case 0xB3:check_serial_data(); case 0xB3:
check_serial_data();
if (ws_ioRam[0xB3] & 0x80) if (ws_ioRam[0xB3] & 0x80)
{ {
@ -572,10 +586,12 @@ uint8_t cpu_readport(uint8_t port)
goto exit; goto exit;
case 0xCC: case 0xCC:
case 0xCD:retVal = 0; case 0xCD:
retVal = 0;
break; break;
default:retVal = ws_ioRam[port]; default:
retVal = ws_ioRam[port];
if (port > 0xD0) if (port > 0xD0)
{ {
printf("ReadIO %02X <= %02X\n", port, retVal); printf("ReadIO %02X <= %02X\n", port, retVal);
@ -586,7 +602,8 @@ uint8_t cpu_readport(uint8_t port)
case 0xAA: case 0xAA:
case 0xAB: case 0xAB:
case 0xAC: case 0xAC:
case 0xAD:retVal = ws_gpu_port_read(port); case 0xAD:
retVal = ws_gpu_port_read(port);
break; break;
} }
@ -645,7 +662,8 @@ void cpu_writeport(uint32_t port, uint8_t value)
switch (port) switch (port)
{ {
/* GPU IOs */ /* GPU IOs */
case 0x00:break; case 0x00:
break;
case 0x04: case 0x04:
case 0x07: case 0x07:
@ -666,7 +684,8 @@ void cpu_writeport(uint32_t port, uint8_t value)
case 0x11: case 0x11:
case 0x12: case 0x12:
case 0x13: case 0x13:
case 0x14:break; case 0x14:
break;
case 0x15: case 0x15:
printf("Icons %c %c %c %c %c %c %c %c\n", (value >> 7) & 1 ? '?' : ' ', (value >> 6) & 1 ? '?' : ' ', printf("Icons %c %c %c %c %c %c %c %c\n", (value >> 7) & 1 ? '?' : ' ', (value >> 6) & 1 ? '?' : ' ',
@ -708,7 +727,8 @@ void cpu_writeport(uint32_t port, uint8_t value)
case 0x36: case 0x36:
case 0x24: case 0x24:
case 0x2E: case 0x2E:
case 0x37:break; case 0x37:
break;
/* DMAs */ /* DMAs */
case 0x40: case 0x40:
@ -718,7 +738,8 @@ void cpu_writeport(uint32_t port, uint8_t value)
case 0x44: case 0x44:
case 0x45: case 0x45:
case 0x46: case 0x46:
case 0x47:break; case 0x47:
break;
case 0x48: // DMA case 0x48: // DMA
@ -753,14 +774,17 @@ void cpu_writeport(uint32_t port, uint8_t value)
case 0x4c: case 0x4c:
case 0x4d: case 0x4d:
case 0x4e: case 0x4e:
case 0x4f:ws_audio_port_write(port, value); case 0x4f:
ws_audio_port_write(port, value);
break; break;
/* DMA Start! */ /* DMA Start! */
case 0x52:break; case 0x52:
break;
/* GPU (again) */ /* GPU (again) */
case 0x60:break; case 0x60:
break;
/* System */ /* System */
case 0x62: case 0x62:
printf("HeyHo!"); printf("HeyHo!");
@ -797,7 +821,8 @@ void cpu_writeport(uint32_t port, uint8_t value)
case 0x9B: case 0x9B:
case 0x9C: case 0x9C:
case 0x9D: case 0x9D:
case 0x9E:ws_audio_port_write(port, value); case 0x9E:
ws_audio_port_write(port, value);
break; break;
/* Hardware */ /* Hardware */
@ -815,17 +840,20 @@ void cpu_writeport(uint32_t port, uint8_t value)
case 0xA8: case 0xA8:
case 0xA9: case 0xA9:
case 0xAA: case 0xAA:
case 0xAB:break; case 0xAB:
break;
/* Intc */ /* Intc */
case 0xB0: case 0xB0:
case 0xB2: case 0xB2:
case 0xB4: case 0xB4:
case 0xB6:break; case 0xB6:
break;
/* Serial */ /* Serial */
case 0xB1:write_serial(value); case 0xB1:
write_serial(value);
break; break;
case 0xB3: case 0xB3:
@ -850,7 +878,8 @@ void cpu_writeport(uint32_t port, uint8_t value)
break; break;
/* buttons */ /* buttons */
case 0xB5:break; case 0xB5:
break;
/* Internal EEPROM */ /* Internal EEPROM */
case 0xba: /* DATA Low */ case 0xba: /* DATA Low */
@ -1058,9 +1087,9 @@ void cpu_writeport(uint32_t port, uint8_t value)
break; break;
case 0xca: case 0xca:
if(value==0x15) if (value == 0x15)
{ {
rtcDataRegisterReadCount=0; rtcDataRegisterReadCount = 0;
} }
break; break;
@ -1085,16 +1114,16 @@ void cpu_writeport(uint32_t port, uint8_t value)
break; /* Somwthing to write there, but what? */ break; /* Somwthing to write there, but what? */
default: default:
unknown_io_port=1; unknown_io_port = 1;
} }
if ((ws_gpu_port_write(port,value) == 1) && (unknown_io_port == 1)) if ((ws_gpu_port_write(port, value) == 1) && (unknown_io_port == 1))
{ {
fprintf(log_get(),"WriteIO(%02X, %02X) [%04X:%04Xh];\n",port, value, I.sregs[CS], I.ip); fprintf(log_get(), "WriteIO(%02X, %02X) [%04X:%04Xh];\n", port, value, I.sregs[CS], I.ip);
} }
if (port >= 0xC4) if (port >= 0xC4)
{ {
fprintf(log_get(),"WriteMBCIO(%02X, %02X);\n",port, value); fprintf(log_get(), "WriteMBCIO(%02X, %02X);\n", port, value);
} }
} }

View File

@ -1,5 +1,10 @@
////////////////////////////////////////////////////////////////////////////// /*
// * NewOswan
* io.h:
* Based on the original Oswan-unix
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
*
*/
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// //
// //

View File

@ -1,5 +1,10 @@
////////////////////////////////////////////////////////////////////////////// /*
// * NewOswan
* log.c:
* Based on the original Oswan-unix
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
*
*/
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// //
// //
@ -13,7 +18,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "log.h" #include "log.h"
FILE *log_stream=NULL; FILE *log_stream = NULL;
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// //
@ -30,13 +35,14 @@ int log_init(char *path)
//log_stream=fopen(path,"wrt"); //log_stream=fopen(path,"wrt");
log_stream = stdout; log_stream = stdout;
if (log_stream==NULL) if (log_stream == NULL)
{ {
return(0); return (0);
} }
return(1); return (1);
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// //
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@ -49,8 +55,9 @@ int log_init(char *path)
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
FILE *log_get(void) FILE *log_get(void)
{ {
return(log_stream); return (log_stream);
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// //
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////

View File

@ -1,5 +1,10 @@
////////////////////////////////////////////////////////////////////////////// /*
// * NewOswan
* log.h:
* Based on the original Oswan-unix
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
*
*/
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// //
// //

View File

@ -1,5 +1,10 @@
//////////////////////////////////////////////////////////////////////////////// /*
// Memory * NewOswan
* memory.c: Memory implementatoion
* Based on the original Oswan-unix
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
*
*/
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Notes: need to optimize cpu_writemem20 // Notes: need to optimize cpu_writemem20
// //
@ -16,6 +21,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <time.h> #include <time.h>
#include <errno.h> #include <errno.h>
#include <stdbool.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -29,7 +35,6 @@
#include "gpu.h" #include "gpu.h"
#include "audio.h" #include "audio.h"
#include "memory.h" #include "memory.h"
#include <stdbool.h>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
@ -62,6 +67,7 @@ extern uint8_t *ws_ioRam;
uint16_t ws_rom_checksum; uint16_t ws_rom_checksum;
uint8_t ws_haveCrystalIRom;
uint8_t ws_haveColorIRom; uint8_t ws_haveColorIRom;
uint8_t ws_haveBWIRom; uint8_t ws_haveBWIRom;
@ -95,13 +101,13 @@ void dump_memory()
fwrite(internalRam, 1, 0x10000, fp); fwrite(internalRam, 1, 0x10000, fp);
/* page 1 */ /* page 1 */
fwrite(&(ws_staticRam[0 & sramAddressMask]), 1, 0x10000, fp); fwrite(&(ws_staticRam[0 & sramAddressMask]), 1, 0x10000, fp);
fwrite(&(ws_rom[((ws_ioRam[IO_ROM_BANK_BASE_SELECTOR+2]&((romSize>>16)-1))<<16)]), 1, 0x10000, fp); fwrite(&(ws_rom[((ws_ioRam[IO_ROM_BANK_BASE_SELECTOR + 2] & ((romSize >> 16) - 1)) << 16)]), 1, 0x10000, fp);
fwrite(&(ws_rom[((ws_ioRam[IO_ROM_BANK_BASE_SELECTOR+3]&((romSize>>16)-1))<<16)]), 1, 0x10000, fp); fwrite(&(ws_rom[((ws_ioRam[IO_ROM_BANK_BASE_SELECTOR + 3] & ((romSize >> 16) - 1)) << 16)]), 1, 0x10000, fp);
for(i = 4; i < 0x10; i++) for (i = 4 ; i < 0x10 ; i++)
{ {
int romBank=(256-(((ws_ioRam[IO_ROM_BANK_BASE_SELECTOR]&0xf)<<4)|(i&0xf))); int romBank = (256 - (((ws_ioRam[IO_ROM_BANK_BASE_SELECTOR] & 0xf) << 4) | (i & 0xf)));
fwrite(&(ws_rom[(unsigned)(romSize-(romBank<<16))]), 1, 0x10000, fp); fwrite(&(ws_rom[(unsigned)(romSize - (romBank << 16))]), 1, 0x10000, fp);
} }
fclose(fp); fclose(fp);
@ -131,24 +137,25 @@ void dump_memory()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void cpu_writemem20(uint32_t addr, uint8_t value) void cpu_writemem20(uint32_t addr, uint8_t value)
{ {
uint32_t offset=addr&0xffff; uint32_t offset = addr & 0xffff;
uint32_t bank=addr>>16; uint32_t bank = addr >> 16;
if (!bank) if (!bank)
{ {
// 0 - RAM - 16 KB (WS) / 64 KB (WSC) internal RAM // 0 - RAM - 16 KB (WS) / 64 KB (WSC) internal RAM
ws_gpu_write_byte(offset,value); ws_gpu_write_byte(offset, value);
ws_audio_write_byte(offset,value); ws_audio_write_byte(offset, value);
} }
else if (bank==1) else if (bank == 1)
{ {
// 1 - SRAM (cart) // 1 - SRAM (cart)
ws_staticRam[offset&sramAddressMask]=value; ws_staticRam[offset & sramAddressMask] = value;
ws_sram_dirty = 1; ws_sram_dirty = 1;
} }
// other banks are read-only // other banks are read-only
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -206,7 +213,8 @@ uint8_t cpu_readmem20(uint32_t addr)
temp &= (romSize - 1); temp &= (romSize - 1);
return ws_rom[temp]; return ws_rom[temp];
case 0xF:hwReg = ws_ioRam[0xA0]; case 0xF:
hwReg = ws_ioRam[0xA0];
if (!(hwReg & 1)) if (!(hwReg & 1))
{ {
@ -237,7 +245,8 @@ uint8_t cpu_readmem20(uint32_t addr)
} }
// fall through // fall through
default:hwReg = ws_ioRam[0xC0]; default:
hwReg = ws_ioRam[0xC0];
temp = hwReg << 20; temp = hwReg << 20;
temp += addr & 0xFFFFF; temp += addr & 0xFFFFF;
temp &= (romSize - 1); temp &= (romSize - 1);
@ -246,6 +255,7 @@ uint8_t cpu_readmem20(uint32_t addr)
return (0x90); return (0x90);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -267,9 +277,9 @@ char *load_file(char *filename)
fstat(fd, &FileStat); fstat(fd, &FileStat);
printf("Trying to load %s, size = %lu...\n",filename, (unsigned long)FileStat.st_size); printf("Trying to load %s, size = %lu...\n", filename, (unsigned long)FileStat.st_size);
ret_ptr = (char *)mmap(NULL, FileStat.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); ret_ptr = (char *)mmap(NULL, FileStat.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
close(fd); close(fd);
@ -280,6 +290,7 @@ char *load_file(char *filename)
return ret_ptr; return ret_ptr;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -296,9 +307,9 @@ char *create_file(char *filename, uint32_t size)
int fd; int fd;
uint32_t i; uint32_t i;
char *ret_ptr; char *ret_ptr;
char buf[] = { 0 }; char buf[] = {0};
printf("Trying to create %s, size = %u...\n",filename, size); printf("Trying to create %s, size = %u...\n", filename, size);
fd = open(filename, O_CREAT | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH | O_TRUNC, 0644); fd = open(filename, O_CREAT | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH | O_TRUNC, 0644);
fchmod(fd, 0644); fchmod(fd, 0644);
close(fd); close(fd);
@ -306,7 +317,7 @@ char *create_file(char *filename, uint32_t size)
fd = open(filename, O_RDWR); fd = open(filename, O_RDWR);
for(i = 0; i < size; i++) for (i = 0 ; i < size ; i++)
{ {
write(fd, buf, 1); write(fd, buf, 1);
} }
@ -315,7 +326,7 @@ char *create_file(char *filename, uint32_t size)
sync(); sync();
fd = open(filename, O_RDWR); fd = open(filename, O_RDWR);
ret_ptr = (char *)mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); ret_ptr = (char *)mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
close(fd); close(fd);
@ -326,6 +337,7 @@ char *create_file(char *filename, uint32_t size)
return ret_ptr; return ret_ptr;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -403,6 +415,7 @@ void ws_memory_init(uint8_t *rom, uint32_t wsRomSize)
romAddressMask = romSize - 1; romAddressMask = romSize - 1;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -416,8 +429,9 @@ void ws_memory_init(uint8_t *rom, uint32_t wsRomSize)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void ws_memory_reset(void) void ws_memory_reset(void)
{ {
memset(internalRam,0,0x10000); memset(internalRam, 0, 0x10000);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -433,6 +447,7 @@ void ws_memory_done(void)
{ {
free(internalRam); free(internalRam);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -446,8 +461,9 @@ void ws_memory_done(void)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
uint8_t *memory_getRom(void) uint8_t *memory_getRom(void)
{ {
return(ws_rom); return (ws_rom);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -461,8 +477,9 @@ uint8_t *memory_getRom(void)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
uint32_t memory_getRomSize(void) uint32_t memory_getRomSize(void)
{ {
return(romSize); return (romSize);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -476,5 +493,5 @@ uint32_t memory_getRomSize(void)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
uint16_t memory_getRomCrc(void) uint16_t memory_getRomCrc(void)
{ {
return(ws_rom_checksum); return (ws_rom_checksum);
} }

View File

@ -1,5 +1,10 @@
////////////////////////////////////////////////////////////////////////////// /*
// * NewOswan
* memory.h:
* Based on the original Oswan-unix
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
*
*/
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// //
// //

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,28 @@
/*
* NewOswan
* nec.h:
* Based on the original Oswan-unix
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
*
*/
#ifndef __NEC_H_ #ifndef __NEC_H_
#define __NEC_H_ #define __NEC_H_
#include <stdint.h> #include <stdint.h>
#include "necintrf.h" #include "necintrf.h"
typedef enum { ES, CS, SS, DS } SREGS; typedef enum
typedef enum { AW, CW, DW, BW, SP, BP, IX, IY } WREGS; {
typedef enum { AL,AH,CL,CH,DL,DH,BL,BH,SPL,SPH,BPL,BPH,IXL,IXH,IYL,IYH } BREGS; ES, CS, SS, DS
} SREGS;
typedef enum
{
AW, CW, DW, BW, SP, BP, IX, IY
} WREGS;
typedef enum
{
AL, AH, CL, CH, DL, DH, BL, BH, SPL, SPH, BPL, BPH, IXL, IXH, IYL, IYH
} BREGS;
#pragma pack(1) #pragma pack(1)
typedef union typedef union
@ -15,6 +31,7 @@ typedef union
uint16_t w[8]; /* viewed as 16 bits registers */ uint16_t w[8]; /* viewed as 16 bits registers */
uint8_t b[16]; /* or as 8 bit registers */ uint8_t b[16]; /* or as 8 bit registers */
} necbasicregs; } necbasicregs;
typedef struct typedef struct
{ {
necbasicregs regs; necbasicregs regs;
@ -57,9 +74,7 @@ typedef struct
#define SetCFB(x) (I.CarryVal = (x) & 0x100) #define SetCFB(x) (I.CarryVal = (x) & 0x100)
#define SetCFW(x) (I.CarryVal = (x) & 0x10000) #define SetCFW(x) (I.CarryVal = (x) & 0x10000)
#define SetAF(x,y,z) (I.AuxVal = ((x) ^ ((y) ^ (z))) & 0x10) #define SetAF(x, y, z) (I.AuxVal = ((x) ^ ((y) ^ (z))) & 0x10)
#define SetSF(x) (I.SignVal = (x)) #define SetSF(x) (I.SignVal = (x))
@ -69,10 +84,10 @@ typedef struct
#define SetSZPF_Byte(x) (I.SignVal=I.ZeroVal=I.ParityVal=(int8_t)(x)) #define SetSZPF_Byte(x) (I.SignVal=I.ZeroVal=I.ParityVal=(int8_t)(x))
#define SetSZPF_Word(x) (I.SignVal=I.ZeroVal=I.ParityVal=(int16_t)(x)) #define SetSZPF_Word(x) (I.SignVal=I.ZeroVal=I.ParityVal=(int16_t)(x))
#define SetOFW_Add(x,y,z) (I.OverVal = ((x) ^ (y)) & ((x) ^ (z)) & 0x8000) #define SetOFW_Add(x, y, z) (I.OverVal = ((x) ^ (y)) & ((x) ^ (z)) & 0x8000)
#define SetOFB_Add(x,y,z) (I.OverVal = ((x) ^ (y)) & ((x) ^ (z)) & 0x80) #define SetOFB_Add(x, y, z) (I.OverVal = ((x) ^ (y)) & ((x) ^ (z)) & 0x80)
#define SetOFW_Sub(x,y,z) (I.OverVal = ((z) ^ (y)) & ((z) ^ (x)) & 0x8000) #define SetOFW_Sub(x, y, z) (I.OverVal = ((z) ^ (y)) & ((z) ^ (x)) & 0x8000)
#define SetOFB_Sub(x,y,z) (I.OverVal = ((z) ^ (y)) & ((z) ^ (x)) & 0x80) #define SetOFB_Sub(x, y, z) (I.OverVal = ((z) ^ (y)) & ((z) ^ (x)) & 0x80)
#define ADDB { uint32_t res=dst+src; SetCFB(res); SetOFB_Add(res,src,dst); SetAF(res,src,dst); SetSZPF_Byte(res); dst=(uint8_t)res; } #define ADDB { uint32_t res=dst+src; SetCFB(res); SetOFB_Add(res,src,dst); SetAF(res,src,dst); SetSZPF_Byte(res); dst=(uint8_t)res; }
#define ADDW { uint32_t res=dst+src; SetCFW(res); SetOFW_Add(res,src,dst); SetAF(res,src,dst); SetSZPF_Word(res); dst=(uint16_t)res; } #define ADDW { uint32_t res=dst+src; SetCFW(res); SetOFW_Add(res,src,dst); SetAF(res,src,dst); SetSZPF_Word(res); dst=(uint16_t)res; }
@ -103,20 +118,20 @@ typedef struct
#define DefaultBase(Seg) ((seg_prefix && (Seg==DS || Seg==SS)) ? prefix_base : I.sregs[Seg] << 4) #define DefaultBase(Seg) ((seg_prefix && (Seg==DS || Seg==SS)) ? prefix_base : I.sregs[Seg] << 4)
#define GetMemB(Seg,Off) (/*nec_ICount-=((Off)&1)?1:0,*/ (uint8_t)cpu_readmem20((DefaultBase(Seg)+(Off)))) #define GetMemB(Seg, Off) (/*nec_ICount-=((Off)&1)?1:0,*/ (uint8_t)cpu_readmem20((DefaultBase(Seg)+(Off))))
#define GetMemW(Seg,Off) (/*nec_ICount-=((Off)&1)?1:0,*/ (uint16_t) cpu_readmem20((DefaultBase(Seg)+(Off))) + (cpu_readmem20((DefaultBase(Seg)+((Off)+1)))<<8) ) #define GetMemW(Seg, Off) (/*nec_ICount-=((Off)&1)?1:0,*/ (uint16_t) cpu_readmem20((DefaultBase(Seg)+(Off))) + (cpu_readmem20((DefaultBase(Seg)+((Off)+1)))<<8) )
#define PutMemB(Seg,Off,x) { /*nec_ICount-=((Off)&1)?1:0*/; cpu_writemem20((DefaultBase(Seg)+(Off)),(x)); } #define PutMemB(Seg, Off, x) { /*nec_ICount-=((Off)&1)?1:0*/; cpu_writemem20((DefaultBase(Seg)+(Off)),(x)); }
#define PutMemW(Seg,Off,x) { /*nec_ICount-=((Off)&1)?1:0*/; PutMemB(Seg,Off,(x)&0xff); PutMemB(Seg,(Off)+1,(uint8_t)((x)>>8)); } #define PutMemW(Seg, Off, x) { /*nec_ICount-=((Off)&1)?1:0*/; PutMemB(Seg,Off,(x)&0xff); PutMemB(Seg,(Off)+1,(uint8_t)((x)>>8)); }
/* Todo: Remove these later - plus readword could overflow */ /* Todo: Remove these later - plus readword could overflow */
#define ReadByte(ea) (/*nec_ICount-=((ea)&1)?1:0,*/ (uint8_t)cpu_readmem20((ea))) #define ReadByte(ea) (/*nec_ICount-=((ea)&1)?1:0,*/ (uint8_t)cpu_readmem20((ea)))
#define ReadWord(ea) (/*nec_ICount-=((ea)&1)?1:0,*/ cpu_readmem20((ea))+(cpu_readmem20(((ea)+1))<<8)) #define ReadWord(ea) (/*nec_ICount-=((ea)&1)?1:0,*/ cpu_readmem20((ea))+(cpu_readmem20(((ea)+1))<<8))
#define WriteByte(ea,val) { /*nec_ICount-=((ea)&1)?1:0*/; cpu_writemem20((ea),val); } #define WriteByte(ea, val) { /*nec_ICount-=((ea)&1)?1:0*/; cpu_writemem20((ea),val); }
#define WriteWord(ea,val) { /*nec_ICount-=((ea)&1)?1:0*/; cpu_writemem20((ea),(uint8_t)(val)); cpu_writemem20(((ea)+1),(val)>>8); } #define WriteWord(ea, val) { /*nec_ICount-=((ea)&1)?1:0*/; cpu_writemem20((ea),(uint8_t)(val)); cpu_writemem20(((ea)+1),(val)>>8); }
#define read_port(port) cpu_readport(port) #define read_port(port) cpu_readport(port)
#define write_port(port,val) cpu_writeport(port,val) #define write_port(port, val) cpu_writeport(port,val)
#define FETCH (cpu_readop_arg((I.sregs[CS]<<4)+I.ip++)) #define FETCH (cpu_readop_arg((I.sregs[CS]<<4)+I.ip++))
#define FETCHOP (cpu_readop((I.sregs[CS]<<4)+I.ip++)) #define FETCHOP (cpu_readop((I.sregs[CS]<<4)+I.ip++))
@ -145,12 +160,12 @@ typedef struct
#define CLKM(v20,v30,v33,v20m,v30m,v33m) { const uint32_t ccount=(v20<<16)|(v30<<8)|v33, mcount=(v20m<<16)|(v30m<<8)|v33m; nec_ICount-=( ModRM >=0xc0 )?((ccount>>cpu_type)&0x7f):((mcount>>cpu_type)&0x7f); } #define CLKM(v20,v30,v33,v20m,v30m,v33m) { const uint32_t ccount=(v20<<16)|(v30<<8)|v33, mcount=(v20m<<16)|(v30m<<8)|v33m; nec_ICount-=( ModRM >=0xc0 )?((ccount>>cpu_type)&0x7f):((mcount>>cpu_type)&0x7f); }
#define CLKR(v20o,v30o,v33o,v20e,v30e,v33e,vall) { const uint32_t ocount=(v20o<<16)|(v30o<<8)|v33o, ecount=(v20e<<16)|(v30e<<8)|v33e; if (ModRM >=0xc0) nec_ICount-=vall; else nec_ICount-=(I.ip&1)?((ocount>>cpu_type)&0x7f):((ecount>>cpu_type)&0x7f); } #define CLKR(v20o,v30o,v33o,v20e,v30e,v33e,vall) { const uint32_t ocount=(v20o<<16)|(v30o<<8)|v33o, ecount=(v20e<<16)|(v30e<<8)|v33e; if (ModRM >=0xc0) nec_ICount-=vall; else nec_ICount-=(I.ip&1)?((ocount>>cpu_type)&0x7f):((ecount>>cpu_type)&0x7f); }
*/ */
#define CLKS(v20,v30,v33) { const uint32_t ccount=(v20<<16)|(v30<<8)|v33; nec_ICount-=(ccount>>cpu_type)&0x7f; } #define CLKS(v20, v30, v33) { const uint32_t ccount=(v20<<16)|(v30<<8)|v33; nec_ICount-=(ccount>>cpu_type)&0x7f; }
#define CLK(all) nec_ICount-=all #define CLK(all) nec_ICount-=all
#define CLKW(v30MZo,v30MZe) { nec_ICount-=(I.ip&1)?v30MZo:v30MZe; } #define CLKW(v30MZo, v30MZe) { nec_ICount-=(I.ip&1)?v30MZo:v30MZe; }
#define CLKM(v30MZm,v30MZ) { nec_ICount-=( ModRM >=0xc0 )?v30MZ:v30MZm; } #define CLKM(v30MZm, v30MZ) { nec_ICount-=( ModRM >=0xc0 )?v30MZ:v30MZm; }
#define CLKR(v30MZo,v30MZe,vall) { if (ModRM >=0xc0) nec_ICount-=vall; else nec_ICount-=(I.ip&1)?v30MZo:v30MZe; } #define CLKR(v30MZo, v30MZe, vall) { if (ModRM >=0xc0) nec_ICount-=vall; else nec_ICount-=(I.ip&1)?v30MZo:v30MZe; }
#define CompressFlags() (uint16_t)(CF | (PF << 2) | (AF << 4) | (ZF << 6) \ #define CompressFlags() (uint16_t)(CF | (PF << 2) | (AF << 4) | (ZF << 6) \
| (SF << 7) | (I.TF << 8) | (I.IF << 9) \ | (SF << 7) | (I.TF << 8) | (I.IF << 9) \
@ -172,7 +187,6 @@ typedef struct
} }
#define IncWordReg(Reg) \ #define IncWordReg(Reg) \
uint16_t tmp = (uint16_t)I.regs.w[Reg]; \ uint16_t tmp = (uint16_t)I.regs.w[Reg]; \
uint16_t tmp1 = tmp+1; \ uint16_t tmp1 = tmp+1; \
@ -182,7 +196,6 @@ typedef struct
I.regs.w[Reg]=tmp1 I.regs.w[Reg]=tmp1
#define DecWordReg(Reg) \ #define DecWordReg(Reg) \
uint16_t tmp = (uint16_t)I.regs.w[Reg]; \ uint16_t tmp = (uint16_t)I.regs.w[Reg]; \
uint16_t tmp1 = tmp-1; \ uint16_t tmp1 = tmp-1; \
@ -200,7 +213,7 @@ typedef struct
return; \ return; \
} }
#define ADJ4(param1,param2) \ #define ADJ4(param1, param2) \
if (AF || ((I.regs.b[AL] & 0xf) > 9)) \ if (AF || ((I.regs.b[AL] & 0xf) > 9)) \
{ \ { \
int tmp; \ int tmp; \
@ -214,7 +227,7 @@ typedef struct
} \ } \
SetSZPF_Byte(I.regs.b[AL]) SetSZPF_Byte(I.regs.b[AL])
#define ADJB(param1,param2) \ #define ADJB(param1, param2) \
if (AF || ((I.regs.b[AL] & 0xf) > 9)) \ if (AF || ((I.regs.b[AL] & 0xf) > 9)) \
{ \ { \
I.regs.b[AL] += param1; \ I.regs.b[AL] += param1; \

View File

@ -1,3 +1,10 @@
/*
* NewOswan
* necea.h:
* Based on the original Oswan-unix
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
*
*/
static uint32_t EA; static uint32_t EA;
static uint16_t EO; static uint16_t EO;
@ -5,194 +12,206 @@ static uint16_t E16;
static unsigned EA_000(void) static unsigned EA_000(void)
{ {
EO=I.regs.w[BW]+I.regs.w[IX]; EO = I.regs.w[BW] + I.regs.w[IX];
EA=DefaultBase(DS)+EO; EA = DefaultBase(DS) + EO;
return EA; return EA;
} }
static unsigned EA_001(void) static unsigned EA_001(void)
{ {
EO=I.regs.w[BW]+I.regs.w[IY]; EO = I.regs.w[BW] + I.regs.w[IY];
EA=DefaultBase(DS)+EO; EA = DefaultBase(DS) + EO;
return EA; return EA;
} }
static unsigned EA_002(void) static unsigned EA_002(void)
{ {
EO=I.regs.w[BP]+I.regs.w[IX]; EO = I.regs.w[BP] + I.regs.w[IX];
EA=DefaultBase(SS)+EO; EA = DefaultBase(SS) + EO;
return EA; return EA;
} }
static unsigned EA_003(void) static unsigned EA_003(void)
{ {
EO=I.regs.w[BP]+I.regs.w[IY]; EO = I.regs.w[BP] + I.regs.w[IY];
EA=DefaultBase(SS)+EO; EA = DefaultBase(SS) + EO;
return EA; return EA;
} }
static unsigned EA_004(void) static unsigned EA_004(void)
{ {
EO=I.regs.w[IX]; EO = I.regs.w[IX];
EA=DefaultBase(DS)+EO; EA = DefaultBase(DS) + EO;
return EA; return EA;
} }
static unsigned EA_005(void) static unsigned EA_005(void)
{ {
EO=I.regs.w[IY]; EO = I.regs.w[IY];
EA=DefaultBase(DS)+EO; EA = DefaultBase(DS) + EO;
return EA; return EA;
} }
static unsigned EA_006(void) static unsigned EA_006(void)
{ {
EO=FETCH; EO = FETCH;
EO+=FETCH<<8; EO += FETCH << 8;
EA=DefaultBase(DS)+EO; EA = DefaultBase(DS) + EO;
return EA; return EA;
} }
static unsigned EA_007(void) static unsigned EA_007(void)
{ {
EO=I.regs.w[BW]; EO = I.regs.w[BW];
EA=DefaultBase(DS)+EO; EA = DefaultBase(DS) + EO;
return EA; return EA;
} }
static unsigned EA_100(void) static unsigned EA_100(void)
{ {
EO=(I.regs.w[BW]+I.regs.w[IX]+(int8_t)FETCH); EO = (I.regs.w[BW] + I.regs.w[IX] + (int8_t)FETCH);
EA=DefaultBase(DS)+EO; EA = DefaultBase(DS) + EO;
return EA; return EA;
} }
static unsigned EA_101(void) static unsigned EA_101(void)
{ {
EO=(I.regs.w[BW]+I.regs.w[IY]+(int8_t)FETCH); EO = (I.regs.w[BW] + I.regs.w[IY] + (int8_t)FETCH);
EA=DefaultBase(DS)+EO; EA = DefaultBase(DS) + EO;
return EA; return EA;
} }
static unsigned EA_102(void) static unsigned EA_102(void)
{ {
EO=(I.regs.w[BP]+I.regs.w[IX]+(int8_t)FETCH); EO = (I.regs.w[BP] + I.regs.w[IX] + (int8_t)FETCH);
EA=DefaultBase(SS)+EO; EA = DefaultBase(SS) + EO;
return EA; return EA;
} }
static unsigned EA_103(void) static unsigned EA_103(void)
{ {
EO=(I.regs.w[BP]+I.regs.w[IY]+(int8_t)FETCH); EO = (I.regs.w[BP] + I.regs.w[IY] + (int8_t)FETCH);
EA=DefaultBase(SS)+EO; EA = DefaultBase(SS) + EO;
return EA; return EA;
} }
static unsigned EA_104(void) static unsigned EA_104(void)
{ {
EO=(I.regs.w[IX]+(int8_t)FETCH); EO = (I.regs.w[IX] + (int8_t)FETCH);
EA=DefaultBase(DS)+EO; EA = DefaultBase(DS) + EO;
return EA; return EA;
} }
static unsigned EA_105(void) static unsigned EA_105(void)
{ {
EO=(I.regs.w[IY]+(int8_t)FETCH); EO = (I.regs.w[IY] + (int8_t)FETCH);
EA=DefaultBase(DS)+EO; EA = DefaultBase(DS) + EO;
return EA; return EA;
} }
static unsigned EA_106(void) static unsigned EA_106(void)
{ {
EO=(I.regs.w[BP]+(int8_t)FETCH); EO = (I.regs.w[BP] + (int8_t)FETCH);
EA=DefaultBase(SS)+EO; EA = DefaultBase(SS) + EO;
return EA; return EA;
} }
static unsigned EA_107(void) static unsigned EA_107(void)
{ {
EO=(I.regs.w[BW]+(int8_t)FETCH); EO = (I.regs.w[BW] + (int8_t)FETCH);
EA=DefaultBase(DS)+EO; EA = DefaultBase(DS) + EO;
return EA; return EA;
} }
static unsigned EA_200(void) static unsigned EA_200(void)
{ {
E16=FETCH; E16 = FETCH;
E16+=FETCH<<8; E16 += FETCH << 8;
EO=I.regs.w[BW]+I.regs.w[IX]+(int16_t)E16; EO = I.regs.w[BW] + I.regs.w[IX] + (int16_t)E16;
EA=DefaultBase(DS)+EO; EA = DefaultBase(DS) + EO;
return EA; return EA;
} }
static unsigned EA_201(void) static unsigned EA_201(void)
{ {
E16=FETCH; E16 = FETCH;
E16+=FETCH<<8; E16 += FETCH << 8;
EO=I.regs.w[BW]+I.regs.w[IY]+(int16_t)E16; EO = I.regs.w[BW] + I.regs.w[IY] + (int16_t)E16;
EA=DefaultBase(DS)+EO; EA = DefaultBase(DS) + EO;
return EA; return EA;
} }
static unsigned EA_202(void) static unsigned EA_202(void)
{ {
E16=FETCH; E16 = FETCH;
E16+=FETCH<<8; E16 += FETCH << 8;
EO=I.regs.w[BP]+I.regs.w[IX]+(int16_t)E16; EO = I.regs.w[BP] + I.regs.w[IX] + (int16_t)E16;
EA=DefaultBase(SS)+EO; EA = DefaultBase(SS) + EO;
return EA; return EA;
} }
static unsigned EA_203(void) static unsigned EA_203(void)
{ {
E16=FETCH; E16 = FETCH;
E16+=FETCH<<8; E16 += FETCH << 8;
EO=I.regs.w[BP]+I.regs.w[IY]+(int16_t)E16; EO = I.regs.w[BP] + I.regs.w[IY] + (int16_t)E16;
EA=DefaultBase(SS)+EO; EA = DefaultBase(SS) + EO;
return EA; return EA;
} }
static unsigned EA_204(void) static unsigned EA_204(void)
{ {
E16=FETCH; E16 = FETCH;
E16+=FETCH<<8; E16 += FETCH << 8;
EO=I.regs.w[IX]+(int16_t)E16; EO = I.regs.w[IX] + (int16_t)E16;
EA=DefaultBase(DS)+EO; EA = DefaultBase(DS) + EO;
return EA; return EA;
} }
static unsigned EA_205(void) static unsigned EA_205(void)
{ {
E16=FETCH; E16 = FETCH;
E16+=FETCH<<8; E16 += FETCH << 8;
EO=I.regs.w[IY]+(int16_t)E16; EO = I.regs.w[IY] + (int16_t)E16;
EA=DefaultBase(DS)+EO; EA = DefaultBase(DS) + EO;
return EA; return EA;
} }
static unsigned EA_206(void) static unsigned EA_206(void)
{ {
E16=FETCH; E16 = FETCH;
E16+=FETCH<<8; E16 += FETCH << 8;
EO=I.regs.w[BP]+(int16_t)E16; EO = I.regs.w[BP] + (int16_t)E16;
EA=DefaultBase(SS)+EO; EA = DefaultBase(SS) + EO;
return EA; return EA;
} }
static unsigned EA_207(void) static unsigned EA_207(void)
{ {
E16=FETCH; E16 = FETCH;
E16+=FETCH<<8; E16 += FETCH << 8;
EO=I.regs.w[BW]+(int16_t)E16; EO = I.regs.w[BW] + (int16_t)E16;
EA=DefaultBase(DS)+EO; EA = DefaultBase(DS) + EO;
return EA; return EA;
} }
static unsigned (*GetEA[192])(void)= static unsigned (*GetEA[192])(void) =
{ {
EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, EA_000, EA_001, EA_002, EA_003, EA_004, EA_005,
EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, EA_006, EA_007, EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, EA_000, EA_001, EA_002, EA_003,
EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, EA_004, EA_005, EA_006, EA_007, EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, EA_000, EA_001,
EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007,
EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007,
EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007,
EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007,
EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007,
EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, EA_100, EA_101, EA_102, EA_103, EA_104, EA_105,
EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, EA_106, EA_107, EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, EA_100, EA_101, EA_102, EA_103,
EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, EA_104, EA_105, EA_106, EA_107, EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, EA_100, EA_101,
EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107,
EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107,
EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107,
EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107,
EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107,
EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, EA_200, EA_201, EA_202, EA_203, EA_204, EA_205,
EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, EA_206, EA_207, EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, EA_200, EA_201, EA_202, EA_203,
EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, EA_204, EA_205, EA_206, EA_207, EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, EA_200, EA_201,
EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207,
EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207,
EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207,
EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207,
EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207 EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207
}; };

View File

@ -1,3 +1,11 @@
/*
* NewOswan
* necinstr.h:
* Based on the original Oswan-unix
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
*
*/
static void i_add_br8(void); static void i_add_br8(void);
static void i_add_wr16(void); static void i_add_wr16(void);
static void i_add_r8b(void); static void i_add_r8b(void);
@ -247,7 +255,7 @@ static void i_ffpre(void);
static void i_wait(void); static void i_wait(void);
void (*nec_instruction[256])(void) = void (*nec_instruction[256])(void) =
{ {
i_add_br8, /* 0x00 */ i_add_br8, /* 0x00 */
i_add_wr16, /* 0x01 */ i_add_wr16, /* 0x01 */
i_add_r8b, /* 0x02 */ i_add_r8b, /* 0x02 */
@ -263,7 +271,7 @@ void (*nec_instruction[256])(void) =
i_or_ald8, /* 0x0c */ i_or_ald8, /* 0x0c */
i_or_axd16, /* 0x0d */ i_or_axd16, /* 0x0d */
i_push_cs, /* 0x0e */ i_push_cs, /* 0x0e */
i_pre_nec /* 0x0f */, i_pre_nec, /* 0x0f */
i_adc_br8, /* 0x10 */ i_adc_br8, /* 0x10 */
i_adc_wr16, /* 0x11 */ i_adc_wr16, /* 0x11 */
i_adc_r8b, /* 0x12 */ i_adc_r8b, /* 0x12 */
@ -462,7 +470,7 @@ void (*nec_instruction[256])(void) =
i_rotshft_wcl, /* 0xd3 */ i_rotshft_wcl, /* 0xd3 */
i_aam, /* 0xd4 */ i_aam, /* 0xd4 */
i_aad, /* 0xd5 */ i_aad, /* 0xd5 */
i_setalc, i_setalc, /* 0xd6 */
i_trans, /* 0xd7 */ i_trans, /* 0xd7 */
i_fpo, /* 0xd8 */ i_fpo, /* 0xd8 */
i_fpo, /* 0xd9 */ i_fpo, /* 0xd9 */
@ -504,4 +512,4 @@ void (*nec_instruction[256])(void) =
i_std, /* 0xfd */ i_std, /* 0xfd */
i_fepre, /* 0xfe */ i_fepre, /* 0xfe */
i_ffpre /* 0xff */ i_ffpre /* 0xff */
}; };

View File

@ -1,3 +1,10 @@
/*
* NewOswan
* necintrf.h:
* Based on the original Oswan-unix
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
*
*/
/* ASG 971222 -- rewrote this interface */ /* ASG 971222 -- rewrote this interface */
#ifndef __NECITRF_H_ #ifndef __NECITRF_H_
#define __NECITRF_H_ #define __NECITRF_H_
@ -6,65 +13,35 @@
enum enum
{ {
NEC_IP=1, NEC_AW, NEC_CW, NEC_DW, NEC_BW, NEC_SP, NEC_BP, NEC_IX, NEC_IY, NEC_IP = 1,
NEC_FLAGS, NEC_ES, NEC_CS, NEC_SS, NEC_DS, NEC_AW,
NEC_VECTOR, NEC_PENDING, NEC_NMI_STATE, NEC_IRQ_STATE NEC_CW,
NEC_DW,
NEC_BW,
NEC_SP,
NEC_BP,
NEC_IX,
NEC_IY,
NEC_FLAGS,
NEC_ES,
NEC_CS,
NEC_SS,
NEC_DS,
NEC_VECTOR,
NEC_PENDING,
NEC_NMI_STATE,
NEC_IRQ_STATE
}; };
/* Public variables */ /* Public variables */
extern int nec_ICount; extern int nec_ICount;
/* Public functions */ /* Public functions */
/*
#define v20_ICount nec_ICount
extern void v20_init(void);
extern void v20_reset(void *param);
extern void v20_exit(void);
extern int v20_execute(int cycles);
extern unsigned v20_get_context(void *dst);
extern void v20_set_context(void *src);
extern unsigned v20_get_reg(int regnum);
extern void v20_set_reg(int regnum, unsigned val);
extern void v20_set_irq_line(int irqline, int state);
extern void v20_set_irq_callback(int (*callback)(int irqline));
extern const char *v20_info(void *context, int regnum);
extern unsigned v20_dasm(char *buffer, unsigned pc);
#define v30_ICount nec_ICount
extern void v30_init(void);
extern void v30_reset(void *param);
extern void v30_exit(void);
extern int v30_execute(int cycles);
extern unsigned v30_get_context(void *dst);
extern void v30_set_context(void *src);
extern unsigned v30_get_reg(int regnum);
extern void v30_set_reg(int regnum, unsigned val);
extern void v30_set_irq_line(int irqline, int state);
extern void v30_set_irq_callback(int (*callback)(int irqline));
extern const char *v30_info(void *context, int regnum);
extern unsigned v30_dasm(char *buffer, unsigned pc);
#define v33_ICount nec_ICount
extern void v33_init(void);
extern void v33_reset(void *param);
extern void v33_exit(void);
extern int v33_execute(int cycles);
extern unsigned v33_get_context(void *dst);
extern void v33_set_context(void *src);
extern unsigned v33_get_reg(int regnum);
extern void v33_set_reg(int regnum, unsigned val);
extern void v33_set_irq_line(int irqline, int state);
extern void v33_set_irq_callback(int (*callback)(int irqline));
extern const char *v33_info(void *context, int regnum);
extern unsigned v33_dasm(char *buffer, unsigned pc);
*/
void nec_set_irq_line(int irqline, int state); void nec_set_irq_line(int irqline, int state);
void nec_set_reg(int regnum, uint32_t val); void nec_set_reg(int regnum, uint32_t val);
int nec_execute(int cycles); int nec_execute(int cycles);
unsigned nec_get_reg(int regnum); unsigned nec_get_reg(int regnum);
void nec_reset (void *param); void nec_reset(void *param);
void nec_int(uint16_t vector); void nec_int(uint16_t vector);
uint8_t cpu_readport(uint8_t); uint8_t cpu_readport(uint8_t);

View File

@ -1,3 +1,11 @@
/*
* NewOswan
* necmodrm.h:
* Based on the original Oswan-unix
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
*
*/
static struct static struct
{ {
struct struct
@ -18,7 +26,7 @@ static struct
#define GetRMWord(ModRM) \ #define GetRMWord(ModRM) \
((ModRM) >= 0xc0 ? I.regs.w[Mod_RM.RM.w[ModRM]] : ( (*GetEA[ModRM])(), ReadWord( EA ) )) ((ModRM) >= 0xc0 ? I.regs.w[Mod_RM.RM.w[ModRM]] : ( (*GetEA[ModRM])(), ReadWord( EA ) ))
#define PutbackRMWord(ModRM,val) \ #define PutbackRMWord(ModRM, val) \
{ \ { \
if (ModRM >= 0xc0) I.regs.w[Mod_RM.RM.w[ModRM]]=val; \ if (ModRM >= 0xc0) I.regs.w[Mod_RM.RM.w[ModRM]]=val; \
else WriteWord(EA,val); \ else WriteWord(EA,val); \
@ -26,7 +34,7 @@ static struct
#define GetnextRMWord ReadWord((EA&0xf0000)|((EA+2)&0xffff)) #define GetnextRMWord ReadWord((EA&0xf0000)|((EA+2)&0xffff))
#define PutRMWord(ModRM,val) \ #define PutRMWord(ModRM, val) \
{ \ { \
if (ModRM >= 0xc0) \ if (ModRM >= 0xc0) \
I.regs.w[Mod_RM.RM.w[ModRM]]=val; \ I.regs.w[Mod_RM.RM.w[ModRM]]=val; \
@ -51,7 +59,7 @@ static struct
#define GetRMByte(ModRM) \ #define GetRMByte(ModRM) \
((ModRM) >= 0xc0 ? I.regs.b[Mod_RM.RM.b[ModRM]] : ReadByte( (*GetEA[ModRM])() )) ((ModRM) >= 0xc0 ? I.regs.b[Mod_RM.RM.b[ModRM]] : ReadByte( (*GetEA[ModRM])() ))
#define PutRMByte(ModRM,val) \ #define PutRMByte(ModRM, val) \
{ \ { \
if (ModRM >= 0xc0) \ if (ModRM >= 0xc0) \
I.regs.b[Mod_RM.RM.b[ModRM]]=val; \ I.regs.b[Mod_RM.RM.b[ModRM]]=val; \
@ -69,7 +77,7 @@ static struct
} \ } \
} }
#define PutbackRMByte(ModRM,val) \ #define PutbackRMByte(ModRM, val) \
{ \ { \
if (ModRM >= 0xc0) \ if (ModRM >= 0xc0) \
I.regs.b[Mod_RM.RM.b[ModRM]]=val; \ I.regs.b[Mod_RM.RM.b[ModRM]]=val; \

View File

@ -1,5 +1,10 @@
////////////////////////////////////////////////////////////////////////////// /*
// * NewOswan
* tom.c:
* Based on the original Oswan-unix
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
*
*/
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// //
// //
@ -21,7 +26,6 @@
#include "log.h" #include "log.h"
#include "rom.h" #include "rom.h"
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -45,7 +49,7 @@ uint8_t *ws_rom_load(char *path, uint32_t *romSize)
*romSize = FileStat.st_size; *romSize = FileStat.st_size;
ret_ptr = (uint8_t *)mmap(NULL, FileStat.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); ret_ptr = (uint8_t *)mmap(NULL, FileStat.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
close(fd); close(fd);
@ -57,6 +61,7 @@ uint8_t *ws_rom_load(char *path, uint32_t *romSize)
return ret_ptr; return ret_ptr;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -70,66 +75,67 @@ uint8_t *ws_rom_load(char *path, uint32_t *romSize)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void ws_rom_dumpInfo(uint8_t *wsrom, uint32_t romSize) void ws_rom_dumpInfo(uint8_t *wsrom, uint32_t romSize)
{ {
ws_romHeaderStruct *romHeader=ws_rom_getHeader(wsrom,romSize); ws_romHeaderStruct *romHeader = ws_rom_getHeader(wsrom, romSize);
fprintf(log_get(),"rom: developper Id 0x%.2x\n",romHeader->developperId); fprintf(log_get(), "rom: developper Id 0x%.2x\n", romHeader->developperId);
fprintf(log_get(),"rom: cart Id 0x%.2x\n",romHeader->cartId); fprintf(log_get(), "rom: cart Id 0x%.2x\n", romHeader->cartId);
fprintf(log_get(),"rom: minimum system %s\n",(romHeader->minimumSupportSystem==0)?"Wonderswan mono":"Wonderswan color"); fprintf(log_get(), "rom: minimum system %s\n",
fprintf(log_get(),"rom: size %i Mbits\n",(romSize>>20)<<3); (romHeader->minimumSupportSystem == 0) ? "Wonderswan mono" : "Wonderswan color");
fprintf(log_get(),"rom: eeprom "); fprintf(log_get(), "rom: size %i Mbits\n", (romSize >> 20) << 3);
fprintf(log_get(), "rom: eeprom ");
switch (romHeader->eepromSize&0xf) switch (romHeader->eepromSize & 0xf)
{ {
case WS_EEPROM_SIZE_NONE: case WS_EEPROM_SIZE_NONE:
{ {
fprintf(log_get(),"none\n"); fprintf(log_get(), "none\n");
break; break;
} }
case WS_EEPROM_SIZE_64k: case WS_EEPROM_SIZE_64k:
{ {
fprintf(log_get(),"64 kb\n"); fprintf(log_get(), "64 kb\n");
break; break;
} }
case WS_EEPROM_SIZE_256k: case WS_EEPROM_SIZE_256k:
{ {
fprintf(log_get(),"256 kb\n"); fprintf(log_get(), "256 kb\n");
break; break;
} }
} }
fprintf(log_get(),"rom: sram "); fprintf(log_get(), "rom: sram ");
switch (romHeader->eepromSize&0xf0) switch (romHeader->eepromSize & 0xf0)
{ {
case WS_SRAM_SIZE_NONE: case WS_SRAM_SIZE_NONE:
{ {
fprintf(log_get(),"none\n"); fprintf(log_get(), "none\n");
break; break;
} }
case WS_SRAM_SIZE_1k: case WS_SRAM_SIZE_1k:
{ {
fprintf(log_get(),"1 kb\n"); fprintf(log_get(), "1 kb\n");
break; break;
} }
case WS_SRAM_SIZE_16k: case WS_SRAM_SIZE_16k:
{ {
fprintf(log_get(),"16 kb\n"); fprintf(log_get(), "16 kb\n");
break; break;
} }
case WS_SRAM_SIZE_8k: case WS_SRAM_SIZE_8k:
{ {
fprintf(log_get(),"8 kn\n"); fprintf(log_get(), "8 kn\n");
break; break;
} }
} }
fprintf(log_get(),"rom: rtc %s\n",(romHeader->realtimeClock)?"Yes":"None"); fprintf(log_get(), "rom: rtc %s\n", (romHeader->realtimeClock) ? "Yes" : "None");
fprintf(log_get(),"checksum 0x%.4x\n",romHeader->checksum); fprintf(log_get(), "checksum 0x%.4x\n", romHeader->checksum);
} }
@ -148,8 +154,9 @@ ws_romHeaderStruct *ws_rom_getHeader(uint8_t *wsrom, uint32_t wsromSize)
{ {
ws_romHeaderStruct *wsromHeader = (ws_romHeaderStruct *)(wsrom + wsromSize - 10); ws_romHeaderStruct *wsromHeader = (ws_romHeaderStruct *)(wsrom + wsromSize - 10);
return(wsromHeader); return (wsromHeader);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -163,25 +170,26 @@ ws_romHeaderStruct *ws_rom_getHeader(uint8_t *wsrom, uint32_t wsromSize)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
uint32_t ws_rom_sramSize(uint8_t *wsrom, uint32_t wsromSize) uint32_t ws_rom_sramSize(uint8_t *wsrom, uint32_t wsromSize)
{ {
ws_romHeaderStruct *romHeader=ws_rom_getHeader(wsrom,wsromSize); ws_romHeaderStruct *romHeader = ws_rom_getHeader(wsrom, wsromSize);
switch (romHeader->eepromSize&0xf0) switch (romHeader->eepromSize & 0xf0)
{ {
case WS_SRAM_SIZE_NONE: case WS_SRAM_SIZE_NONE:
return(0); return (0);
case WS_SRAM_SIZE_1k: case WS_SRAM_SIZE_1k:
return(0x400); return (0x400);
case WS_SRAM_SIZE_16k: case WS_SRAM_SIZE_16k:
return(0x4000); return (0x4000);
case WS_SRAM_SIZE_8k: case WS_SRAM_SIZE_8k:
return(0x2000); return (0x2000);
} }
return(0); return (0);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -195,20 +203,20 @@ uint32_t ws_rom_sramSize(uint8_t *wsrom, uint32_t wsromSize)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
uint32_t ws_rom_eepromSize(uint8_t *wsrom, uint32_t wsromSize) uint32_t ws_rom_eepromSize(uint8_t *wsrom, uint32_t wsromSize)
{ {
ws_romHeaderStruct *romHeader=ws_rom_getHeader(wsrom,wsromSize); ws_romHeaderStruct *romHeader = ws_rom_getHeader(wsrom, wsromSize);
switch (romHeader->eepromSize&0xf) switch (romHeader->eepromSize & 0xf)
{ {
case WS_EEPROM_SIZE_NONE: case WS_EEPROM_SIZE_NONE:
return(0); return (0);
case WS_EEPROM_SIZE_64k: case WS_EEPROM_SIZE_64k:
return(0x10000); return (0x10000);
case WS_EEPROM_SIZE_256k: case WS_EEPROM_SIZE_256k:
return(0x40000); return (0x40000);
} }
return(0); return (0);
} }

View File

@ -1,5 +1,10 @@
////////////////////////////////////////////////////////////////////////////// /*
// * NewOswan
* rom.h:
* Based on the original Oswan-unix
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
*
*/
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// //
// //
@ -32,7 +37,6 @@
#define WS_SRAM_SIZE_16k 20 #define WS_SRAM_SIZE_16k 20
#define WS_SRAM_SIZE_8k 50 #define WS_SRAM_SIZE_8k 50
typedef struct ws_romHeaderStruct typedef struct ws_romHeaderStruct
{ {
uint8_t developperId; uint8_t developperId;
@ -45,7 +49,6 @@ typedef struct ws_romHeaderStruct
uint16_t checksum; uint16_t checksum;
} ws_romHeaderStruct; } ws_romHeaderStruct;
uint8_t *ws_rom_load(char *path, uint32_t *romSize); uint8_t *ws_rom_load(char *path, uint32_t *romSize);
void ws_rom_dumpInfo(uint8_t *wsrom, uint32_t wsromSize); void ws_rom_dumpInfo(uint8_t *wsrom, uint32_t wsromSize);
ws_romHeaderStruct *ws_rom_getHeader(uint8_t *wsrom, uint32_t wsromSize); ws_romHeaderStruct *ws_rom_getHeader(uint8_t *wsrom, uint32_t wsromSize);
@ -53,4 +56,3 @@ uint32_t ws_rom_sramSize(uint8_t *wsrom, uint32_t wsromSize);
uint32_t ws_rom_eepromSize(uint8_t *wsrom, uint32_t wsromSize); uint32_t ws_rom_eepromSize(uint8_t *wsrom, uint32_t wsromSize);
#endif #endif

View File

@ -1,5 +1,10 @@
//////////////////////////////////////////////////////////////////////////////// /*
// Wonderswan emulator * NewOswan
* ws.c: Base wonderswan implementation
* Based on the original Oswan-unix
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
*
*/
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
// //
@ -45,8 +50,8 @@
uint32_t ws_cycles; uint32_t ws_cycles;
uint32_t ws_skip; uint32_t ws_skip;
uint32_t ws_cyclesByLine=0; uint32_t ws_cyclesByLine = 0;
uint32_t vblank_count=0; uint32_t vblank_count = 0;
char *ws_sram_path = NULL; char *ws_sram_path = NULL;
char *ws_ieep_path = NULL; char *ws_ieep_path = NULL;
@ -67,14 +72,14 @@ wssystem_t systemType;
void ws_patchRom(void) void ws_patchRom(void)
{ {
uint8_t *rom=memory_getRom(); uint8_t *rom = memory_getRom();
uint32_t romSize=memory_getRomSize(); uint32_t romSize = memory_getRomSize();
fprintf(log_get(),"developper Id: 0x%.2x\nGame Id: 0x%.2x\n",rom[romSize-10],rom[romSize-8]); fprintf(log_get(), "developper Id: 0x%.2x\nGame Id: 0x%.2x\n", rom[romSize - 10], rom[romSize - 8]);
if (!ws_cyclesByLine) if (!ws_cyclesByLine)
{ {
ws_cyclesByLine=256; ws_cyclesByLine = 256;
} }
} }
@ -94,13 +99,12 @@ int ws_init(char *rompath)
uint8_t *rom; uint8_t *rom;
uint32_t romSize; uint32_t romSize;
if ((rom=ws_rom_load(rompath,&romSize))==NULL) if ((rom = ws_rom_load(rompath, &romSize)) == NULL)
{ {
printf("Error: cannot load %s\n",rompath); printf("Error: cannot load %s\n", rompath);
return(0); return (0);
} }
ws_memory_init(rom, romSize); ws_memory_init(rom, romSize);
ws_patchRom(); ws_patchRom();
@ -136,8 +140,9 @@ int ws_init(char *rompath)
ws_io_flipControls(); ws_io_flipControls();
} }
return(1); return (1);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -156,8 +161,9 @@ void ws_reset(void)
ws_audio_reset(); ws_audio_reset();
ws_gpu_reset(); ws_gpu_reset();
nec_reset(NULL); nec_reset(NULL);
nec_set_reg(NEC_SP,0x2000); nec_set_reg(NEC_SP, 0x2000);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -171,29 +177,29 @@ void ws_reset(void)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int ws_executeLine(int16_t *framebuffer, int renderLine) int ws_executeLine(int16_t *framebuffer, int renderLine)
{ {
int drawWholeScreen=0; int drawWholeScreen = 0;
ws_audio_process(); ws_audio_process();
// update scanline register // update scanline register
ws_ioRam[2]=ws_gpu_scanline; ws_ioRam[2] = ws_gpu_scanline;
/* Why twice like that and random cycle count???? */ /* Why twice like that and random cycle count???? */
ws_cycles=nec_execute((ws_cyclesByLine>>1)+(rand()&7)); ws_cycles = nec_execute((ws_cyclesByLine >> 1) + (rand() & 7));
ws_cycles+=nec_execute((ws_cyclesByLine>>1)+(rand()&7)); ws_cycles += nec_execute((ws_cyclesByLine >> 1) + (rand() & 7));
if(ws_cycles>=ws_cyclesByLine+ws_cyclesByLine) if (ws_cycles >= ws_cyclesByLine + ws_cyclesByLine)
{ {
ws_skip=ws_cycles/ws_cyclesByLine; ws_skip = ws_cycles / ws_cyclesByLine;
} }
else else
{ {
ws_skip=1; ws_skip = 1;
} }
ws_cycles%=ws_cyclesByLine; ws_cycles %= ws_cyclesByLine;
for(uint32_t uI=0; uI<ws_skip; uI++) for (uint32_t uI = 0 ; uI < ws_skip ; uI++)
{ {
if (renderLine) if (renderLine)
{ {
@ -202,69 +208,70 @@ int ws_executeLine(int16_t *framebuffer, int renderLine)
ws_gpu_scanline++; ws_gpu_scanline++;
if(ws_gpu_scanline==144) if (ws_gpu_scanline == 144)
{ {
drawWholeScreen=1; drawWholeScreen = 1;
} }
} }
if(ws_gpu_scanline>158) if (ws_gpu_scanline > 158)
{ {
ws_gpu_scanline=0; ws_gpu_scanline = 0;
{ {
if((ws_ioRam[0xb2]&32)) /* VBLANK Timer */ if ((ws_ioRam[0xb2] & 32)) /* VBLANK Timer */
{ {
/* TODO: REPAIR THAT SHIT */ /* TODO: REPAIR THAT SHIT */
ws_ioRam[0xb6]&=~32; ws_ioRam[0xb6] &= ~32;
nec_int((ws_ioRam[0xb0]+5)*4); nec_int((ws_ioRam[0xb0] + 5) * 4);
} }
} }
} }
ws_ioRam[2]=ws_gpu_scanline; ws_ioRam[2] = ws_gpu_scanline;
if(drawWholeScreen) if (drawWholeScreen)
{ {
if(ws_ioRam[0xb2]&64) /* VBLANK INT */ if (ws_ioRam[0xb2] & 64) /* VBLANK INT */
{ {
ws_ioRam[0xb6]&=~64; ws_ioRam[0xb6] &= ~64;
nec_int((ws_ioRam[0xb0]+6)*4); nec_int((ws_ioRam[0xb0] + 6) * 4);
} }
vblank_count++; vblank_count++;
} }
if(ws_ioRam[0xa4]&&(ws_ioRam[0xb2]&128)) /*HBLANK TMR*/ if (ws_ioRam[0xa4] && (ws_ioRam[0xb2] & 128)) /*HBLANK TMR*/
{ {
/* TODO: Check that shit */ /* TODO: Check that shit */
if(!ws_ioRam[0xa5]) if (!ws_ioRam[0xa5])
{ {
ws_ioRam[0xa5]=ws_ioRam[0xa4]; ws_ioRam[0xa5] = ws_ioRam[0xa4];
} }
if(ws_ioRam[0xa5]) if (ws_ioRam[0xa5])
{ {
ws_ioRam[0xa5]--; ws_ioRam[0xa5]--;
} }
if((!ws_ioRam[0xa5])&&(ws_ioRam[0xb2]&128)) if ((!ws_ioRam[0xa5]) && (ws_ioRam[0xb2] & 128))
{ {
ws_ioRam[0xb6]&=~128; ws_ioRam[0xb6] &= ~128;
nec_int((ws_ioRam[0xb0]+7)*4); nec_int((ws_ioRam[0xb0] + 7) * 4);
} }
} }
if((ws_ioRam[0x2]==ws_ioRam[0x3])&&(ws_ioRam[0xb2]&16)) /*SCANLINE INT*/ if ((ws_ioRam[0x2] == ws_ioRam[0x3]) && (ws_ioRam[0xb2] & 16)) /*SCANLINE INT*/
{ {
ws_ioRam[0xb6]&=~16; ws_ioRam[0xb6] &= ~16;
nec_int((ws_ioRam[0xb0]+4)*4); nec_int((ws_ioRam[0xb0] + 4) * 4);
} }
return(drawWholeScreen); return (drawWholeScreen);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -283,6 +290,7 @@ void ws_done(void)
ws_audio_done(); ws_audio_done();
ws_gpu_done(); ws_gpu_done();
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -318,14 +326,14 @@ wssystem_t ws_get_system()
// //
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#define MacroLoadNecRegisterFromFile(F,R) \ #define MacroLoadNecRegisterFromFile(F, R) \
read(fp,&value,sizeof(value)); \ read(fp,&value,sizeof(value)); \
nec_set_reg(R,value); nec_set_reg(R,value);
int ws_loadState(char *statepath) int ws_loadState(char *statepath)
{ {
fprintf(log_get(),"loading %s\n",statepath); fprintf(log_get(), "loading %s\n", statepath);
uint16_t crc=memory_getRomCrc(); uint16_t crc = memory_getRomCrc();
uint16_t newCrc; uint16_t newCrc;
unsigned value; unsigned value;
uint8_t ws_newVideoMode; uint8_t ws_newVideoMode;
@ -334,51 +342,51 @@ int ws_loadState(char *statepath)
if (fp == -1) if (fp == -1)
{ {
return(0); return (0);
} }
read(fp, &newCrc, 2); read(fp, &newCrc, 2);
if (newCrc!=crc) if (newCrc != crc)
{ {
return(-1); return (-1);
} }
MacroLoadNecRegisterFromFile(fp,NEC_IP); MacroLoadNecRegisterFromFile(fp, NEC_IP);
MacroLoadNecRegisterFromFile(fp,NEC_AW); MacroLoadNecRegisterFromFile(fp, NEC_AW);
MacroLoadNecRegisterFromFile(fp,NEC_BW); MacroLoadNecRegisterFromFile(fp, NEC_BW);
MacroLoadNecRegisterFromFile(fp,NEC_CW); MacroLoadNecRegisterFromFile(fp, NEC_CW);
MacroLoadNecRegisterFromFile(fp,NEC_DW); MacroLoadNecRegisterFromFile(fp, NEC_DW);
MacroLoadNecRegisterFromFile(fp,NEC_CS); MacroLoadNecRegisterFromFile(fp, NEC_CS);
MacroLoadNecRegisterFromFile(fp,NEC_DS); MacroLoadNecRegisterFromFile(fp, NEC_DS);
MacroLoadNecRegisterFromFile(fp,NEC_ES); MacroLoadNecRegisterFromFile(fp, NEC_ES);
MacroLoadNecRegisterFromFile(fp,NEC_SS); MacroLoadNecRegisterFromFile(fp, NEC_SS);
MacroLoadNecRegisterFromFile(fp,NEC_IX); MacroLoadNecRegisterFromFile(fp, NEC_IX);
MacroLoadNecRegisterFromFile(fp,NEC_IY); MacroLoadNecRegisterFromFile(fp, NEC_IY);
MacroLoadNecRegisterFromFile(fp,NEC_BP); MacroLoadNecRegisterFromFile(fp, NEC_BP);
MacroLoadNecRegisterFromFile(fp,NEC_SP); MacroLoadNecRegisterFromFile(fp, NEC_SP);
MacroLoadNecRegisterFromFile(fp,NEC_FLAGS); MacroLoadNecRegisterFromFile(fp, NEC_FLAGS);
MacroLoadNecRegisterFromFile(fp,NEC_VECTOR); MacroLoadNecRegisterFromFile(fp, NEC_VECTOR);
MacroLoadNecRegisterFromFile(fp,NEC_PENDING); MacroLoadNecRegisterFromFile(fp, NEC_PENDING);
MacroLoadNecRegisterFromFile(fp,NEC_NMI_STATE); MacroLoadNecRegisterFromFile(fp, NEC_NMI_STATE);
MacroLoadNecRegisterFromFile(fp,NEC_IRQ_STATE); MacroLoadNecRegisterFromFile(fp, NEC_IRQ_STATE);
read(fp,internalRam,65536); read(fp, internalRam, 65536);
read(fp,ws_staticRam,65536); read(fp, ws_staticRam, 65536);
read(fp,ws_ioRam,256); read(fp, ws_ioRam, 256);
read(fp,ws_paletteColors,8); read(fp, ws_paletteColors, 8);
read(fp,ws_palette,16*4*2); read(fp, ws_palette, 16 * 4 * 2);
read(fp,wsc_palette,16*16*2); read(fp, wsc_palette, 16 * 16 * 2);
read(fp,&ws_newVideoMode,1); read(fp, &ws_newVideoMode, 1);
read(fp,&ws_gpu_scanline,1); read(fp, &ws_gpu_scanline, 1);
read(fp,externalEeprom,131072); read(fp, externalEeprom, 131072);
ws_audio_readState(fp); ws_audio_readState(fp);
close(fp); close(fp);
// force a video mode change to make all tiles dirty // force a video mode change to make all tiles dirty
ws_gpu_clearCache(); ws_gpu_clearCache();
return(1); return (1);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
@ -391,89 +399,90 @@ int ws_loadState(char *statepath)
// //
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#define MacroStoreNecRegisterToFile(F,R) \ #define MacroStoreNecRegisterToFile(F, R) \
value=nec_get_reg(R); \ value=nec_get_reg(R); \
write(fp,&value,sizeof(value)); write(fp,&value,sizeof(value));
int ws_saveState(char *statepath) int ws_saveState(char *statepath)
{ {
uint16_t crc=memory_getRomCrc(); uint16_t crc = memory_getRomCrc();
uint32_t value; uint32_t value;
char newPath[1024]; char newPath[1024];
fprintf(log_get(),"saving %s\n",statepath); fprintf(log_get(), "saving %s\n", statepath);
if (strlen(statepath)<4) if (strlen(statepath) < 4)
{ {
sprintf(newPath,"%s.wss",statepath); sprintf(newPath, "%s.wss", statepath);
} }
else else
{ {
int len=strlen(statepath); int len = strlen(statepath);
if ((statepath[len-1]!='s')&&(statepath[len-1]!='S')) if ((statepath[len - 1] != 's') && (statepath[len - 1] != 'S'))
{ {
sprintf(newPath,"%s.wss",statepath); sprintf(newPath, "%s.wss", statepath);
} }
else if ((statepath[len-2]!='s')&&(statepath[len-2]!='S')) else if ((statepath[len - 2] != 's') && (statepath[len - 2] != 'S'))
{ {
sprintf(newPath,"%s.wss",statepath); sprintf(newPath, "%s.wss", statepath);
} }
else if ((statepath[len-3]!='w')&&(statepath[len-3]!='w')) else if ((statepath[len - 3] != 'w') && (statepath[len - 3] != 'w'))
{ {
sprintf(newPath,"%s.wss",statepath); sprintf(newPath, "%s.wss", statepath);
} }
else if (statepath[len-4]!='.') else if (statepath[len - 4] != '.')
{ {
sprintf(newPath,"%s.wss",statepath); sprintf(newPath, "%s.wss", statepath);
} }
else else
{ {
sprintf(newPath,"%s",statepath); sprintf(newPath, "%s", statepath);
} }
} }
int fp=open(newPath, O_RDWR|O_CREAT, 0644); int fp = open(newPath, O_RDWR | O_CREAT, 0644);
if (fp==-1) if (fp == -1)
{ {
return(0); return (0);
} }
write(fp,&crc,2); write(fp, &crc, 2);
MacroStoreNecRegisterToFile(fp,NEC_IP); MacroStoreNecRegisterToFile(fp, NEC_IP);
MacroStoreNecRegisterToFile(fp,NEC_AW); MacroStoreNecRegisterToFile(fp, NEC_AW);
MacroStoreNecRegisterToFile(fp,NEC_BW); MacroStoreNecRegisterToFile(fp, NEC_BW);
MacroStoreNecRegisterToFile(fp,NEC_CW); MacroStoreNecRegisterToFile(fp, NEC_CW);
MacroStoreNecRegisterToFile(fp,NEC_DW); MacroStoreNecRegisterToFile(fp, NEC_DW);
MacroStoreNecRegisterToFile(fp,NEC_CS); MacroStoreNecRegisterToFile(fp, NEC_CS);
MacroStoreNecRegisterToFile(fp,NEC_DS); MacroStoreNecRegisterToFile(fp, NEC_DS);
MacroStoreNecRegisterToFile(fp,NEC_ES); MacroStoreNecRegisterToFile(fp, NEC_ES);
MacroStoreNecRegisterToFile(fp,NEC_SS); MacroStoreNecRegisterToFile(fp, NEC_SS);
MacroStoreNecRegisterToFile(fp,NEC_IX); MacroStoreNecRegisterToFile(fp, NEC_IX);
MacroStoreNecRegisterToFile(fp,NEC_IY); MacroStoreNecRegisterToFile(fp, NEC_IY);
MacroStoreNecRegisterToFile(fp,NEC_BP); MacroStoreNecRegisterToFile(fp, NEC_BP);
MacroStoreNecRegisterToFile(fp,NEC_SP); MacroStoreNecRegisterToFile(fp, NEC_SP);
MacroStoreNecRegisterToFile(fp,NEC_FLAGS); MacroStoreNecRegisterToFile(fp, NEC_FLAGS);
MacroStoreNecRegisterToFile(fp,NEC_VECTOR); MacroStoreNecRegisterToFile(fp, NEC_VECTOR);
MacroStoreNecRegisterToFile(fp,NEC_PENDING); MacroStoreNecRegisterToFile(fp, NEC_PENDING);
MacroStoreNecRegisterToFile(fp,NEC_NMI_STATE); MacroStoreNecRegisterToFile(fp, NEC_NMI_STATE);
MacroStoreNecRegisterToFile(fp,NEC_IRQ_STATE); MacroStoreNecRegisterToFile(fp, NEC_IRQ_STATE);
write(fp,internalRam,65536); write(fp, internalRam, 65536);
write(fp,ws_staticRam,65536); write(fp, ws_staticRam, 65536);
write(fp,ws_ioRam,256); write(fp, ws_ioRam, 256);
write(fp,ws_paletteColors,8); write(fp, ws_paletteColors, 8);
write(fp,ws_palette,16*4*2); write(fp, ws_palette, 16 * 4 * 2);
write(fp,wsc_palette,16*16*2); write(fp, wsc_palette, 16 * 16 * 2);
write(fp,&ws_videoMode,1); write(fp, &ws_videoMode, 1);
write(fp,&ws_gpu_scanline,1); write(fp, &ws_gpu_scanline, 1);
write(fp,externalEeprom,131072); write(fp, externalEeprom, 131072);
ws_audio_writeState(fp); ws_audio_writeState(fp);
close(fp); close(fp);
return(1); return (1);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -487,8 +496,8 @@ int ws_saveState(char *statepath)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int ws_rotated(void) int ws_rotated(void)
{ {
uint8_t *rom=memory_getRom(); uint8_t *rom = memory_getRom();
uint32_t romSize=memory_getRomSize(); uint32_t romSize = memory_getRomSize();
return(rom[romSize-4]&1); return (rom[romSize - 4] & 1);
} }

View File

@ -1,5 +1,10 @@
////////////////////////////////////////////////////////////////////////////// /*
// * NewOswan
* ws.h:
* Based on the original Oswan-unix
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
*
*/
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// //
// //
@ -14,11 +19,9 @@
#include <stdint.h> #include <stdint.h>
typedef enum wssystem_t { typedef enum wssystem_t
WS_SYSTEM_AUTODETECT = 0, {
WS_SYSTEM_MONO, WS_SYSTEM_AUTODETECT = 0, WS_SYSTEM_MONO, WS_SYSTEM_COLOR, WS_SYSTEM_CRYSTAL,
WS_SYSTEM_COLOR,
WS_SYSTEM_CRYSTAL,
} wssystem_t; } wssystem_t;
extern uint32_t ws_cyclesByLine; extern uint32_t ws_cyclesByLine;

View File

@ -1,3 +1,10 @@
/*
* NewOswan
* testserial.c: A simple tool to test serial in/out
* Based on the original Oswan-unix
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
*
*/
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>