Skip to content

Commit 496c771

Browse files
committed
add files
0 parents  commit 496c771

File tree

285 files changed

+166895
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

285 files changed

+166895
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.vscode
2+
*.exe

LICENSE.txt

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
This is a **modified** version of the Casio emulator developed by [qiufuyu](https://github.com/qiufuyu123/CasioEmuX) and contains a nX/U8 disassembler written in lua and one written in cpp (their output formats are different).
2+
3+
Files are modified so that they can work on windows.
4+
5+
Note that ROMs are **not** included in the `models` folder (for copyright reasons), you have to obtain one from somewhere else or dump it from a real calculator or emulator. (note that models labeled with `_emu` are for ROMs dumped from official emulators)
6+
7+
8+
# CasioEmuX-win
9+
10+
An emulator and disassembler for the CASIO calculator series using the nX-U8/100 core.
11+
With debuggers.
12+
13+
To build it, install tdm-gcc and run build.bat
14+
15+
syntax:
16+
17+
`casioemu key1=value1 key2=value2 ...`
18+
19+
`model=<directory>` model directory, which should contain interface.png, model.lua, rom.bin(you can find it elsewhere) and _disas.txt(use disas-cpp on rom.bin to obtain this file)
20+
21+
these arguments are optional:
22+
23+
`script=<xxx.lua>` the supplied lua script will run on startup
24+
25+
`exit_on_console_shutdown=true/false` pretty self-evident, default to false
26+
27+
`history=<history file path>` input history

disas-cpp/Makefile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# folder names 'bin' and 'obj' are hardcoded
2+
# tdm-gcc
3+
4+
CCFLAGS = -D_GLIBCXX_DEBUG -O2 -std=c++14 -Wall -Wextra -Werror -pedantic
5+
CCFLAGS2 = -D_GLIBCXX_DEBUG -O2 -std=c++14 -Wall -Wextra -pedantic
6+
7+
all: u8-disas u8-disas-split
8+
9+
u8-disas: nX-U8_is.txt main Makefile example.cpp
10+
main $< temp.cpp
11+
g++ $(CCFLAGS) temp.cpp -o $@
12+
del temp.cpp
13+
14+
u8-disas-split: nX-U8_is_split.txt main Makefile example.cpp
15+
main $< temp.cpp
16+
g++ $(CCFLAGS) temp.cpp -o $@
17+
del temp.cpp
18+
19+
u8-disas-brief: nX-U8_brief.txt main Makefile example.cpp
20+
main $< temp.cpp
21+
g++ $(CCFLAGS2) temp.cpp -o $@
22+
del temp.cpp
23+
24+
main: main.cpp lib.h lib.cpp
25+
g++ $(CCFLAGS) main.cpp lib.cpp -o $@
26+
27+
clean:
28+
if exist main.exe del main.exe
29+
if exist u8-disas.exe del u8-disas.exe
30+
if exist u8-disas-split.exe del u8-disas-split.exe
31+
if exist u8-disas-split.exe del u8-disas-brief.exe
32+
if exist temp.cpp del temp.cpp

disas-cpp/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
how to build:
2+
Use tdm-gcc, run `mingw32-make all` in this directory. If something goes wrong, run `mingw32-make clean` to clean up and start again.
3+
4+
usage:
5+
`main` is for generating disassemblers, run it without arguments to show the help message
6+
`u8-disas` is the nX/u8 disassembler, run it without arguments to show the help message
7+
`u8-disas-split` splits 4-byte command into 2 2-byte commands, run it without arguments to show the help message
8+
`u8-disas-brief` well I do not know what it does, run it without arguments to show the help message

disas-cpp/example.cpp

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// Independent from the project.
2+
3+
#include <iostream>
4+
#include <fstream>
5+
#include <string>
6+
#include <deque>
7+
#include <cstring>
8+
9+
#define ip (totallen - length - buf.size())
10+
11+
std::string tohex(int n, int len) {
12+
std::string retval = "";
13+
for (int x = 0; x < len; x++) {
14+
retval = "0123456789ABCDEF"[n & 0xF] + retval;
15+
n >>= 4;
16+
}
17+
return retval;
18+
}
19+
// Those are important to the disassembler.
20+
21+
// ------------------------------------------------------------------ 1
22+
// ------------------------------------------------------------------ 2
23+
24+
int main(int argc, char** argv) {
25+
char* st = new char[0x400];
26+
if (argc != 5) { // argv[0] = executable file name
27+
std::ifstream fi {"help.txt"};
28+
do {
29+
fi.getline(st, 0x400);
30+
} while (std::strcmp(st, "*") != 0);
31+
while (true) {
32+
fi.getline(st, 0x400);
33+
if (fi.fail()) {
34+
fi.close();
35+
return 0;
36+
}
37+
std::cout << st << "\n";
38+
}
39+
}
40+
41+
std::ifstream in {argv[1], std::ios_base::binary};
42+
in.seekg(std::stoi(argv[2], nullptr, 0));
43+
int length = std::stoi(argv[3], nullptr, 0), l1, i, totallen = length;
44+
std::ofstream out {argv[4]};
45+
std::deque<std::uint8_t> buf {};
46+
char* readbuf = new char[0x10000];
47+
48+
l1 = std::min(length, 0x10000);
49+
in.read(readbuf, l1);
50+
length -= l1;
51+
for (i = 0; i < l1; i++) {
52+
buf.push_back(readbuf[i]);
53+
}
54+
55+
while (buf.size() > 0) { // assume the block is valid.
56+
// That part read number in dequeue, pop_front it for some bytes and write to (ofstream) out.
57+
58+
// ------------------------------------------------------------------ 3
59+
60+
// #1
61+
62+
// aaabbb00 f1 #{a}, #{b}
63+
if ((buf[0] & 0b00000011) == 0b00000000) {
64+
int a = buf[0] >> 5 & 0b111, b = buf[0] >> 2 & 0b111; // >> has higher precedence than &
65+
out << tohex(ip, 6) << " " << tohex(buf[0], 2) << ' ' << " " // IP and opcode
66+
<< "f1 #" << a << ", #" << b // command
67+
<< "\n";
68+
buf.pop_front();
69+
goto done;
70+
}
71+
72+
// aaabbb01 f2 #{a}, #{b}
73+
if ((buf[0] & 0b00000011) == 0b00000001) {
74+
int a = buf[0] >> 5 & 0b111, b = buf[0] >> 2 & 0b111;
75+
out << tohex(ip, 6) << " " << tohex(buf[0], 2) << ' ' << " " // def convenience: exceed 7 spaces, plus one
76+
<< "f2 #" << a << ", #" << b // command
77+
<< "\n";
78+
buf.pop_front();
79+
goto done;
80+
}
81+
82+
// #2
83+
84+
// aaaaaa11 bbbbbbbb f3 #{a}, #{b}
85+
if ((buf[0] & 0b00000011) == 0b00000011 && (buf[1] & 0b00000000) == 0b00000000) {
86+
int a = buf[0] >> 2 & 0b111111, b = buf[1] >> 0 & 0b11111111;
87+
out << tohex(ip, 6) << " " << tohex(buf[0], 2) << ' ' << tohex(buf[1], 2) << ' ' << " "
88+
<< "f3 #" << a << ", #" << b // command
89+
<< "\n";
90+
buf.pop_front(); buf.pop_front();
91+
goto done;
92+
}
93+
94+
// *
95+
96+
out << tohex(ip, 6) << " " << tohex(buf[0], 2) << ' ' << " "
97+
<< "Unrecognized command"
98+
<< "\n";
99+
buf.pop_front();
100+
101+
// ------------------------------------------------------------------ 4
102+
103+
done:
104+
if (buf.size() < 0x20 && length != 0) { // assume all opcode is shorter than 0x20 bytes
105+
l1 = std::min(length, 0x10000);
106+
in.read(readbuf, l1);
107+
length -= l1;
108+
for (i = 0; i < l1; i++) {
109+
buf.push_back(readbuf[i]);
110+
}
111+
}
112+
}
113+
114+
in.close();
115+
out.close();
116+
117+
return 0;
118+
}

disas-cpp/help.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Disassembler source code creator
2+
3+
Usage:
4+
5+
Disassembler instruction_set_file_name.txt output_file_name.cpp
6+
7+
*
8+
9+
??? disassembler
10+
11+
Usage:
12+
13+
a.exe file_to_disassemble start_position length output_file_name.txt
14+
15+
start_position, length are:
16+
+ In decimal if there is no prefix or suffix
17+
+ In hexadecimal if there is 0x prefix
18+
+ In octal if there is 0 prefix
19+
20+
Warning: If the disassembler work on invalid code it may crash!

disas-cpp/lib.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <string>
2+
3+
std::string tohex(int n, int len) {
4+
std::string retval = "";
5+
for (int x = 0; x < len; x++) {
6+
retval = "0123456789ABCDEF"[n & 0xF] + retval;
7+
n >>= 4;
8+
}
9+
return retval;
10+
}
11+
12+
std::string tobin(int n, int len) {
13+
std::string retval = "";
14+
for (int x = 0; x < len; x++) {
15+
retval = "01"[n & 1] + retval;
16+
n >>= 1;
17+
}
18+
return retval;
19+
}

disas-cpp/lib.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#pragma once
2+
3+
std::string tohex(int, int);
4+
std::string tobin(int, int);

0 commit comments

Comments
 (0)