Commit fa46899d authored by Vladimir Serbinenko's avatar Vladimir Serbinenko
Browse files

Move state to a structure bk_state

parent b2ab4b7f
......@@ -24,15 +24,6 @@
#include <libintl.h>
#define _(String) gettext (String)
/*
* BK-0011 has 8 8Kw RAM pages and 4 8 Kw ROM pages.
* RAM pages 1 and 7 are video RAM.
*/
d_word ram[8][8192];
d_word rom[4][8192];
d_word system_rom[8192];
unsigned char umr[65536];
/*
* Page mapping, per 8 Kw page. Default is a mapping mimicking BK-0010
*/
......@@ -40,14 +31,6 @@ d_word * pagemap[4] = { ram[6], ram[1], rom[0], system_rom };
#define mem(x) pagemap[(x)>>14][((x) & 037777) >> 1]
/*
* Each bit corresponds to a Kword,
* the lowest 8 Kwords are RAM, the next 8 are screen memory,
* the rest is usually ROM.
*/
unsigned long pdp_ram_map = 0x0000ffff;
unsigned long pdp_mem_map;
#define IS_RAM_ADDRESS(x) ((pdp_ram_map >> ((x) >> 11)) & 1)
#define IS_VALID_ADDRESS(x) ((pdp_mem_map >> ((x) >> 11)) & 1)
......
......@@ -59,7 +59,6 @@ void bkplip_init() {
static int len_left = 0;
static int curbyte = 0;
static flag_t nibble = 0;
static int txlen = 0, txbyte = 0;
/*
* When no data is present, returns 0.
......
......@@ -39,7 +39,6 @@
void load_rom(unsigned start, const char * rompath, unsigned min_size, unsigned max_size) {
char * path;
int i;
extern unsigned long pdp_ram_map;
unsigned long saved_ram_map = pdp_ram_map;
FILE * romf;
......
......@@ -6,12 +6,10 @@
#include "defines.h"
extern char * monitor10rom;
extern const char *const monitor10rom;
extern int upper_porch;
extern int lower_porch;
extern int io_sound_freq;
extern char * floppyA;
extern char * floppyB;
extern char * floppyC;
extern char * floppyD;
extern flag_t fake_tape, fake_disk, telegraph_enabled, fullscreen;
extern unsigned io_sound_freq;
extern flag_t fake_tape, telegraph_enabled, fullscreen;
extern flag_t traceflag;
extern FILE * tracefile;
......@@ -5,9 +5,6 @@
#include <libintl.h>
#define _(String) gettext (String)
unsigned char covox_val;
unsigned int covox_age;
void covox_init() {
covox_val = 0;
covox_age = ~0;
......
......@@ -152,7 +152,6 @@ extern unsigned int hasexit;
#define PDP_READABLE_MEM_SIZE (63 * 512) /* 0 - 175777 */
#define PDP_FULL_MEM_SIZE (64 * 512) /* 0 - 177777 */
extern d_word rom[4][8192], ram[8][8192], system_rom[8192];
extern void line_init(void);
void scr_init(void);
void boot_init(void);
......@@ -218,29 +217,132 @@ typedef int (*_itab_t)();
* Global variables.
*/
extern struct timeval real_time;
extern int ui_done;
extern unsigned short last_branch;
extern pdp_regs pdp;
extern event *event_list[NUM_PRI];
extern char * printer_file;
struct bk_state {
int ui_done;
unsigned short _last_branch;
pdp_regs _pdp; /* internal processor registers */
int _TICK_RATE;
unsigned short _tty_scroll;
flag_t _key_pressed;
flag_t _fake_disk;
/* 1 if interrupt requested while WAIT was in effect */
flag_t _in_wait_instr;
unsigned io_sound_val;
flag_t _io_stop_happened;
int io_tape_mode, io_tape_val, io_tape_bit;
flag_t _nflag; /* audio flag */
flag_t _mouseflag; /* mouse flag */
flag_t _fullspeed; /* do not slow down to real BK speed */
flag_t _tapeflag; /* Disable reading from tape */
double _frame_delay; /* Delay in ticks between video frames */
double _half_frame_delay;
flag_t _cflag, _bkmodel, _terak;
long long _ticks_timer;
long long _ticks, io_tape_ticks; /* in main clock freq, integral */
long long _tape_read_ticks, _tape_write_ticks;
flag_t _timer_intr_enabled;
volatile int _stop_it; /* set when a SIGINT happens during execution */
/*
* BK-0011 has 8 8Kw RAM pages and 4 8 Kw ROM pages.
* RAM pages 1 and 7 are video RAM.
*/
d_word _ram[8][8192];
d_word _rom[4][8192];
d_word _system_rom[8192];
unsigned char _umr[65536];
/*
* Each bit corresponds to a Kword,
* the lowest 8 Kwords are RAM, the next 8 are screen memory,
* the rest is usually ROM.
*/
unsigned long _pdp_ram_map;
unsigned long _pdp_mem_map;
d_word _timer_count, _timer_setup, _timer_control;
long long _ticks_start;
unsigned int _timer_period;
long long _framectr;
long long _soundctr;
unsigned _scan_line_duration;
unsigned char _covox_val;
unsigned int _covox_age;
unsigned _io_sound_val;
unsigned _io_max_sound_age;
unsigned _io_sound_age; /* in io_sound_pace's since last change */
double _io_sound_pace;
double _io_sound_count;
};
extern const char *printer_file;
extern const char *floppyA, *floppyB, *floppyC, *floppyD;
extern const char *rompath10, *rompath12, *rompath16;
extern const char *const bos11rom, *const diskrom, *const bos11extrom;
extern const char *const basic11arom, *const basic11brom;
extern struct bk_state current_state;
extern flag_t traceflag; /* print all instruction addresses */
extern FILE * tracefile; /* trace goes here */
extern char * romdir;
extern char * rompath10, *rompath12, *rompath16;
extern char * bos11rom, * diskrom, * bos11extrom, * basic11arom, * basic11brom;
extern int TICK_RATE;
extern char * floppyA, *floppyB, *floppyC, *floppyD;
extern const _itab_t itab[];
extern unsigned short tty_scroll;
extern unsigned scr_dirty;
extern flag_t key_pressed;
extern flag_t in_wait_instr;
extern unsigned io_sound_val;
extern flag_t io_stop_happened;
extern int io_tape_mode, io_tape_val, io_tape_bit;
extern flag_t cflag, mouseflag, bkmodel, terak, nflag, fullspeed;
extern double ticks, io_tape_ticks; /* in main clock freq, integral */
extern flag_t timer_intr_enabled;
extern const _itab_t itab[];
#define bkmodel current_state._bkmodel
#define stop_it current_state._stop_it
#define nflag current_state._nflag
#define io_stop_happened current_state._io_stop_happened
#define ticks current_state._ticks
#define in_wait_instr current_state._in_wait_instr
#define pdp current_state._pdp
#define timer_intr_enabled current_state._timer_intr_enabled
#define last_branch current_state._last_branch
#define ticks_timer current_state._ticks_timer
#define terak current_state._terak
#define TICK_RATE current_state._TICK_RATE
#define mouseflag current_state._mouseflag
#define fullspeed current_state._fullspeed
#define key_pressed current_state._key_pressed
#define fake_disk current_state._fake_disk
#define tapeflag current_state._tapeflag
#define frame_delay current_state._frame_delay
#define half_frame_delay current_state._half_frame_delay
#define cflag current_state._cflag
#define tty_scroll current_state._tty_scroll
#define ram current_state._ram
#define rom current_state._rom
#define system_rom current_state._system_rom
#define umr current_state._umr
#define pdp_ram_map current_state._pdp_ram_map
#define pdp_mem_map current_state._pdp_mem_map
#define timer_count current_state._timer_count
#define timer_setup current_state._timer_setup
#define timer_control current_state._timer_control
#define ticks_start current_state._ticks_start
#define timer_period current_state._timer_period
#define framectr current_state._framectr
#define soundctr current_state._soundctr
#define scan_line_duration current_state._scan_line_duration
#define covox_val current_state._covox_val
#define covox_age current_state._covox_age
#define io_sound_val current_state._io_sound_val
#define io_max_sound_age current_state._io_max_sound_age
#define io_sound_age current_state._io_sound_age
#define io_sound_pace current_state._io_sound_pace
#define io_sound_count current_state._io_sound_count
#define tape_read_ticks current_state._tape_read_ticks
#define tape_write_ticks current_state._tape_write_ticks
/*
* Inline defines.
......
......@@ -6,11 +6,6 @@
#include <libintl.h>
#define _(String) gettext (String)
extern double io_sound_count;
extern int io_sound_age;
extern flag_t nflag, fullspeed;
unsigned io_sound_val = 0;
flag_t io_stop_happened = 0;
flag_t telegraph_enabled = 0; /* Default */
void io_init() {
......
......@@ -30,6 +30,7 @@
#include "defines.h"
#include "scr.h"
#include "conf.h"
#include <SDL/SDL.h>
#include <libintl.h>
#include <locale.h>
......@@ -40,7 +41,9 @@
* Globals.
*/
char * printer_file = 0;
struct bk_state current_state;
const char * printer_file = 0;
char init_path[BUFSIZ];
char game_path[512];
......@@ -59,51 +62,35 @@ if (refreshtime > 64) flag = 0; }
* At start-up, bkmodel == 0, 1, or 2 means BK-0010, 3 means BK-0011M.
* During simulation, bkmodel == 0 is BK-0010, 1 is BK-0011M.
*/
flag_t bkmodel = 3; /* default BK model */
flag_t terak = 0; /* by default we emulate BK */
flag_t fake_disk = 1; /* true for BK-0011M and bkmodel == 2 */
/* Standard path and ROMs for basic hardware configurations */
char * romdir = "./roms"; /* default ROM path */
char * monitor10rom = "MONIT10.ROM";
const char *const monitor10rom = "MONIT10.ROM";
char * focal10rom = "FOCAL10.ROM";
char * basic10rom = "BASIC10.ROM";
char * diskrom = "DISK_327.ROM";
char * bos11rom = "B11M_BOS.ROM";
char * bos11extrom = "B11M_EXT.ROM";
char * basic11arom = "BAS11M_0.ROM";
char * basic11brom = "BAS11M_1.ROM";
char * rompath10 = 0;
char * rompath12 = 0;
char * rompath16 = 0;
int TICK_RATE; /* cpu clock speed */
const char *const diskrom = "DISK_327.ROM";
const char *const bos11rom = "B11M_BOS.ROM";
const char *const bos11extrom = "B11M_EXT.ROM";
const char *const basic11arom = "BAS11M_0.ROM";
const char *const basic11brom = "BAS11M_1.ROM";
char * floppyA = "A.img";
char * floppyB = "B.img";
char * floppyC = "C.img";
char * floppyD = "D.img";
const char * floppyA = "A.img";
const char * floppyB = "B.img";
const char * floppyC = "C.img";
const char * floppyD = "D.img";
unsigned short last_branch;
/*
* Command line flags and variables.
*/
flag_t aflag; /* autoboot flag */
flag_t nflag; /* audio flag */
flag_t mouseflag; /* mouse flag */
flag_t covoxflag; /* covox flag */
flag_t synthflag; /* AY-3-8910 flag */
flag_t plipflag; /* PLIP flag */
flag_t fullspeed; /* do not slow down to real BK speed */
flag_t traceflag; /* print all instruction addresses */
FILE * tracefile; /* trace goes here */
flag_t tapeflag; /* Disable reading from tape */
flag_t turboflag; /* "Turbo" mode with doubled clock speed */
double frame_delay; /* Delay in ticks between video frames */
double half_frame_delay;
/*
* main()
......@@ -389,10 +376,9 @@ char **argv;
return 0;
}
static int checkpoint(d_word pc);
pdp_regs pdp; /* internal processor registers */
volatile int stop_it; /* set when a SIGINT happens during execution */
const char *rompath10, *rompath12, *rompath16;
/*
* sim_init() - Initialize the cpu registers.
......@@ -408,6 +394,8 @@ sim_init()
}
pdp.ir = 0;
pdp.psw = 0200;
pdp_ram_map = 0x0000ffff;
}
/*
......@@ -455,7 +443,6 @@ run( int flag )
p->total = 0;
}
double ticks_timer = 0.0;
double ticks_screen = 0.0;
extern unsigned long pending_interrupts;
......@@ -505,7 +492,6 @@ int flag;
*/
if (traceflag) {
extern double io_sound_count;
disas(p->regs[PC], buf);
if (tracefile) fprintf(tracefile, "%s\t%s\n", buf, state(p));
else printf("%s\n", buf);
......@@ -667,11 +653,8 @@ void intr_hand()
stop_it = 1;
}
checkpoint(pc)
d_word pc;
static int checkpoint(d_word pc)
{
extern int breakpoint;
extern unsigned char fake_tape;
switch(pc) {
case 0116256:
if (fake_tape && !bkmodel) {
......
......@@ -5,7 +5,7 @@
#define _(String) gettext (String)
SDL_Surface * screen, *rl_screen;
flag_t cflag = 0, fullscreen = 0;
flag_t fullscreen = 0;
int cur_shift = 0;
int cur_width = 0; /* 0 = narrow, !0 = wide */
int horsize = 512, vertsize = 512;
......@@ -47,6 +47,8 @@ unsigned scr_dirty = 0;
unsigned char req_page[512], req_palette[512];
unsigned char active_palette, active_page;
unsigned char half_frame = 0;
unsigned char param_change_line;
unsigned char change_req;
int upper_porch = 0; /* Default */
int lower_porch = 3; /* Default */
......@@ -154,8 +156,6 @@ compute_icon_mask() {
return mask;
}
unsigned scan_line_duration;
/* BK-0010 screen refresh - no palettes */
extern void scr_refresh_bk0010(unsigned shift, unsigned full);
......@@ -295,7 +295,6 @@ scr_switch(int hsize, int vsize) {
* Each half frame is TICK_RATE/50 long and consists of 128 lines.
*/
unsigned current_scan_line() {
extern double half_frame_delay;
unsigned nframes = ticks/half_frame_delay;
unsigned frame_ticks = ticks - half_frame_delay * nframes;
unsigned line = frame_ticks / scan_line_duration;
......@@ -304,9 +303,6 @@ unsigned current_scan_line() {
if (line < 256) return line; else return 256;
}
unsigned char param_change_line;
unsigned char change_req;
void scr_param_change(int pal, int buf) {
int cur = current_scan_line();
uint i;
......
......@@ -14,10 +14,6 @@
#include <libintl.h>
#define _(String) gettext (String)
/* 1 if interrupt requested while WAIT was in effect */
unsigned char in_wait_instr = 0;
/* Allows up to 32 different HW interrupts,
* there can be no more than 1 pending interrupt of each kind.
*/
......
......@@ -11,15 +11,8 @@
#define SOUND_BUFSIZE 512
#define MAX_SOUND_AGE ~0 /* always play */
unsigned io_max_sound_age = MAX_SOUND_AGE;
unsigned io_sound_age = MAX_SOUND_AGE; /* in io_sound_pace's since last change */
unsigned io_sound_bufsize,
io_sound_freq = 11025,
io_sound_pace;
double io_sound_count;
extern unsigned io_sound_val, covox_age;
extern unsigned char covox_val;
extern flag_t nflag, fullspeed;
io_sound_freq = 11025;
typedef struct {
short * buf;
......@@ -90,6 +83,9 @@ SDL_AudioSpec desired;
void sound_init() {
static init_done = 0;
int iarg, i;
io_max_sound_age = MAX_SOUND_AGE;
io_sound_age = MAX_SOUND_AGE;
if (!nflag)
return;
if (fullspeed) {
......
......@@ -12,9 +12,6 @@ unsigned char tape_status = 1; /* 0 = tape moving, 1 = tape stopped */
flag_t fake_tape = 1; /* Default */
extern int tapeflag;
double tape_read_ticks, tape_write_ticks;
extern double ticks;
void tape_read_start(), tape_read_finish();
static enum { Idle, Addr, Len, Name, Data, Checksum } fake_state = Idle;
......
#include "defines.h"
d_word timer_count, timer_setup, timer_control;
double ticks_start;
unsigned int timer_period;
#define TIM_UNKNOWN1 1
#define TIM_CONTINUOUS 2
#define TIM_ENBEND 4
......
......@@ -2,8 +2,6 @@
#include <libintl.h>
#define _(String) gettext (String)
double ticks = 0; /* in clock ticks, integral */
#define REGREG 12
static const int a_time[8] = {0, 12, 12, 20, 12, 20, 20, 28};
......
......@@ -46,9 +46,6 @@
#define TTY_DOWNLOAD 0372 /* direct file load */
d_word tty_reg;
d_word tty_data;
d_word tty_scroll = 1330;
unsigned char key_pressed = 0100;
flag_t timer_intr_enabled = 0;
int special_keys[SDLK_LAST], shifted[256];
static tty_pending_int = 0;
......@@ -139,6 +136,7 @@ void tty_init()
tty_pending_int = 0;
tty_scroll = 01330;
timer_intr_enabled = 0;
key_pressed = 0100;
if (old_scroll != tty_scroll) {
scr_dirty = 1;
}
......
......@@ -42,7 +42,6 @@
int ui_done;
int breakpoint = -1;
extern int traceflag;
static char buf[BUFSIZ];
void ui_load(const char *s);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment