Skip to content

Commit

Permalink
[emulator] replace wg functions with f1/n1/f2/n2 options
Browse files Browse the repository at this point in the history
replaces the previous set of bit manipulations with a set that is more
representative of actual word generator operation

The wg n1 can have a '/' to set the B-Modifier:
  wg n1     # n1 and B are cleared
  wg n1 2   # n1=2  b=0
  wg n1 13/ # n1=15 b=1
  wg n1 16  # n1=31 b=1

This is the same as
  wg n1
  wg n1 31
  wg n1 /

Signed-off-by: Christopher Hall <[email protected]>
  • Loading branch information
hxw committed Sep 14, 2020
1 parent d3a57c6 commit 1056449
Show file tree
Hide file tree
Showing 4 changed files with 254 additions and 50 deletions.
126 changes: 126 additions & 0 deletions emulator/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseTab: Never
...
25 changes: 23 additions & 2 deletions emulator/README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Command Abbr. Description
help (?) this message
exit (x) exit emulation
list [ADDR [COUNT]] (l) display memory words
mw ADDR CODE|±DEC write memory word
mw ADDR CODE|±DEC write memory word (machine code or signed decimal)
reset reset all regs and stop execution
reset run reset all regs and restart from zero
run [ADDR] run from address or continue after a stop
Expand All @@ -32,9 +32,30 @@ regs (r) display registers and status
hello [ADDR [1|2|3]] load hello world [4096 1]
reader 1|2 [MODE] FILE attach an existing file to a reader (hex5)
punch 1|2 [MODE] FILE create file and attach to a punch (hex5)
wg [msb|o2l|lsb|CODE|±N] set or display word generator
wg display word generator
wg CODE|±DEC set word generator to machine code or signed decimal
wg f1|n1|f2|n2 clear a set of bits (Note: n1 also clears B-Modifier)
wg f1|f2 F 'or' octal value to function bits
wg n1|n2 N 'or' decimal value to address bits (Note: '/' sets B-Modifier)
wg b set the B-Modifier bit


Abbreviation Description
============= ============
lower case literal command text
digits literal command text
space literal command text
[] optional parameters
…|… choice of parameter value
COUNT unsigned decimal value
ADDR decimal address 0..8191
CODE machine code value (e.g. 74 29:40 123)
MODE see table below
FILE pathname of a file
±DEC signed 39 bit decimal value (must have '+' or '-' sign prefix)
F octal value 0…77 for logical or to word generator
N decimal value 0…8191 for logical or to word generator

## File Reading MODE Values

Names Description
Expand Down
39 changes: 21 additions & 18 deletions emulator/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,30 +414,33 @@ command_word_generator(commands_t *cmd, const wchar_t *name, wchar_t **ptr) {

// help

// clang-format: off
static void command_help(commands_t *cmd, const wchar_t *name, wchar_t **ptr) {
const wchar_t *m =
// clang-format: off
L"help (?) this message\n"
L"exit (x) exit emulation\n"
L"wait wait for stop or wg polling\n"
L"list [ADDR [COUNT]] (l) display memory words\n"
L"mw ADDR CODE|±DEC write memory word\n"
L"reset reset all regs and stop execution\n"
L"reset run reset all regs and restart from zero\n"
L"run [ADDR] run from address or continue after a stop\n"
L"stop stop execution\n"
L"regs (r) display registers and status\n"
L"hello [ADDR [1|2|3]] load hello world [4096 1]\n"
L"reader 1|2 [MODE] FILE attach an existing file to a reader "
L"(hex5)\n"
L"punch 1|2 [MODE] FILE create file and attach to a punch (hex5)\n"
L"screen 1|2|3|4 select current screen as Fn\n"
L"wg [msb|o2l|lsb|CODE|±N] set or display word generator\n"
// clang-format: on
L"help (?) this message\n" //
L"exit (x) exit emulation\n" //
L"wait wait for stop or wg polling\n" //
L"list [ADDR [COUNT]] (l) display memory words\n" //
L"mw ADDR CODE|±DEC write memory word\n" //
L"reset reset regs and stop execution\n" //
L"reset run reset regs and start from zero\n" //
L"run [ADDR] run from address or continue after stop\n" //
L"stop stop execution\n" //
L"regs (r) display registers and status\n" //
L"hello [ADDR [1|2|3]] load hello world [4096 1]\n" //
L"reader 1|2 [MODE] FILE attach existing file to a reader (hex5)\n" //
L"punch 1|2 [MODE] FILE create file, attach to a punch (hex5)\n" //
L"screen 1|2|3|4 select current screen as Fn\n" //
L"wg displays word generator value\n" //
L"wg CODE|±N set word generator code or signed number\n" //
L"wg f1|f2 [F] clear/or wg function 1/2 bits (octal)\n" //
L"wg n1 [N][/] clear/or wg address 1 + B bits (decimal)\n" //
L"wg n2 [N] clear/or wg address 2 bits (decimal)\n" //
;

cmd->error = wcsdup(m);
}
// clang-format: on

// lookup command

Expand Down
114 changes: 84 additions & 30 deletions emulator/cpu/processor.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,29 +506,75 @@ static bool action_word_generator(elliott803_t *proc, const char *params) {

if ('\0' != params[0]) {
uint64_t w = proc->word_generator;
if (0 == strcmp(params, "msb")) {
// if sign not set, set it
// if sign set clear all op1 bits
if (0 == (w & sign_bit)) {
w |= sign_bit;
} else {
w &= ~(op_bits << first_op_shift);
if (0 == strcmp(params, "b")) {
// set the B-Modifier
w |= b_mod_bit;
} else if ('f' == params[0] && ('1' == params[1] || '2' == params[1])) {
uint64_t shift = '1' == params[1] ? first_op_shift : second_op_shift;
uint64_t value = 0;
params += 2;
for (;;) {
char c = *params++;
if (c >= '0' && c <= '7') {
value = value * 8 + c - '0';
} else if (' ' == c) {
continue;
} else if ('\0' == c) {
break;
} else {
const_reply(proc, "error invalid octal value");
return true;
}
}
} else if (0 == strcmp(params, "o2l")) {
// if op2 LSB not set, set it
// if op2 LSB set clear all op2 bits
if (0 == (w & (1LL << second_op_shift))) {
w |= 1LL << second_op_shift;
if (value > op_bits) {
const_reply(proc, "error octal value too large");
return true;
}
if (0 == value) {
w &= ~(op_bits << shift);
} else {
w &= ~(op_bits << second_op_shift);
w |= value << shift;
}
} else if ('n' == params[0] && ('1' == params[1] || '2' == params[1])) {
uint64_t shift =
'1' == params[1] ? first_address_shift : second_address_shift;
uint64_t value = 0;
bool bmod = false;
params += 2;
for (;;) {
char c = *params++;
if (c >= '0' && c <= '9') {
value = value * 10 + c - '0';
} else if ('b' == c || '/' == c) {
if (first_address_shift == shift) {
bmod = true;
} else {
const_reply(proc, "error invalid b-modifier");
return true;
}
} else if (' ' == c) {
continue;
} else if ('\0' == c) {
break;
} else {
const_reply(proc, "error invalid decimal value");
return true;
}
}
if (value >= memory_size) {
const_reply(proc, "error decimal value too large");
return true;
}
} else if (0 == strcmp(params, "lsb")) {
// if LSB not set, set it
// if LSB set clear all address2 bits
if (0 == (w & one_bit)) {
w |= one_bit;
if (0 == value && !bmod) {
w &= ~(address_bits << shift);
if (first_address_shift == shift) {
w &= ~b_mod_bit;
}
} else {
w &= ~(address_bits << second_address_shift);
w |= value << shift;
if (bmod) {
w |= b_mod_bit;
}
}
} else {
// otherwise treat as code or ±N
Expand Down Expand Up @@ -573,19 +619,25 @@ static bool action_check(elliott803_t *proc, const char *params) {

static bool action_help(elliott803_t *proc, const char *params) {

// clang-format: off
static const char *help[] = {
"?? reset [run] reset CPU and optionally run T1 loader", //
"?? mw ADDRESS CODE|±N store code or signed number to address", //
"?? mr ADDRESS display code and numeric for address", //
"?? status display registers and flags", //
"?? run ADDRESS[.5] run from specific address", //
"?? cont continue after stop", //
"?? stop halt the CPU", //
"?? reader UNIT HEX buffer up to 32 bytes for a reader", //
"?? wg [CODE|±N|msb|o2l|lsb] set word generator code or signed number", //
"?? check check for stop or word generator polling", //
"?? ", //
"?? reset [run] reset CPU and optionally run T1 loader", //
"?? mw ADDRESS CODE|±N store code or signed number to address", //
"?? mr ADDRESS display code and numeric for address", //
"?? status display registers and flags", //
"?? run ADDRESS[.5] run from specific address", //
"?? cont continue after stop", //
"?? stop halt the CPU", //
"?? reader UNIT HEX buffer up to 32 bytes for a reader", //
"?? wg displays word generator value", //
"?? wg CODE|±N set word generator code or signed number", //
"?? wg f1|f2 [F] clear/or wg function 1/2 bits (octal)", //
"?? wg n1 [N][/] clear/or wg address 1 + B bits (decimal)", //
"?? wg n2 [N] clear/or wg address 2 bits (decimal)", //
"?? check check for stop or word generator polling", //
"?? ", //
};
// clang-format: on
for (size_t i = 0; i < SizeOfArray(help); ++i) {
const_reply(proc, help[i]);
}
Expand All @@ -598,6 +650,7 @@ typedef struct {
bool (*fn)(elliott803_t *proc, const char *params);
} cmd_t;

// clang-format: off
static const cmd_t command_list[] = {
{"reset", action_reset}, //
{"mw", action_memory_write}, //
Expand All @@ -612,6 +665,7 @@ static const cmd_t command_list[] = {
{"?", action_help}, //
{"terminate", action_terminate}, // last item (for internal use)
};
// clang-format: on

// main processor control loop
static void *main_loop(void *arg) {
Expand Down

0 comments on commit 1056449

Please sign in to comment.