Initial code commit

This commit is contained in:
Furry12 committed 2026-10-23 00:07:07 +08:00
commit 96130738b8
40 files changed
+2753

No files matched your search

+78
View File
@@ -0,0 +1,78 @@
package sega.a7;
import javacard.framework.Util;
/**
* Ordinal-to-command dispatcher.
*/
public class CommandServer {
private Command m_ee_noCommand;
private Command[] m_ee_list;
private short m_ee_listCount;
public CommandServer() {
m_ee_noCommand = null;
m_ee_list = new Command[4];
m_ee_listCount = 0;
}
public void setNoCommand(Command cmdClass) {
m_ee_noCommand = cmdClass;
}
public void attachCommand(Command cmdClass) {
if (cmdClass == null) {
return;
}
if (m_ee_listCount >= m_ee_list.length) {
Command[] tmp = new Command[(short) (m_ee_list.length * 2)];
for (short i = 0; i < m_ee_list.length; i++) {
tmp[i] = m_ee_list[i];
}
m_ee_list = tmp;
}
m_ee_list[m_ee_listCount] = cmdClass;
m_ee_listCount = (short) (m_ee_listCount + 1);
}
public short findCommand(short cmd) {
for (short i = 0; i < m_ee_listCount; i++) {
if (cmd == m_ee_list[i].getCmd_ee()) {
return i;
}
}
return -1;
}
public boolean select() {
boolean ret = true;
for (short i = 0; i < m_ee_listCount; i++) {
if (!m_ee_list[i].select()) {
ret = false;
}
}
return ret;
}
public short execute(byte[] data, short dataOffset, short dataLength,
byte[] dst, short dstOffset, short dstLength) {
short cmd = -1;
if (data != null && dataOffset >= 0 && dataLength >= AppConfig.HEADER_SIZE
&& dataOffset <= (short) (data.length - AppConfig.HEADER_SIZE)) {
cmd = Util.getShort(data,
(short) (dataOffset + AppConfig.CMD_OFFSET));
}
short index = findCommand(cmd);
if (index >= 0) {
return m_ee_list[index].execute(data, dataOffset, dataLength,
dst, dstOffset, dstLength);
}
if (m_ee_noCommand != null) {
return m_ee_noCommand.execute(data, dataOffset, dataLength,
dst, dstOffset, dstLength);
}
return -1;
}
}