Skip to content

Commit

Permalink
Barcode and IC card reader stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpd002 committed Nov 24, 2023
1 parent 799f5f7 commit 84e0f17
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 9 deletions.
141 changes: 132 additions & 9 deletions Source/iop/namco_sys147/Iop_NamcoSys147.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,20 +235,38 @@ bool CSys147::Invoke99(uint32 method, uint32* args, uint32 argsSize, uint32* ret
}
else if(packet->command == 0x31)
{
//Seems related to barcode reader
//data[0] = ?
//Barcode Reader & IC Card
//data[0] = channel?
//data[1] = size of data
//data[4] = start of data
uint8 channel = packet->data[0];
uint8 inputSize = packet->data[1];
CLog::GetInstance().Warn(LOG_NAME, "Received command buffer channel: %d, size: %d\r\n",
channel, inputSize);
MODULE_99_PACKET reply = {};
reply.type = 2;
reply.command = 0x31;
reply.data[1] = 0x6;
reply.data[4 + 0] = 0x02;
reply.data[4 + 1] = 0x02;
reply.data[4 + 2] = 0x80;
reply.data[4 + 3] = 0x02; //This is used for result
reply.data[4 + 4] = 0x03;
reply.data[4 + 5] = 0x03;
if(channel == 0)
{
assert(inputSize == 4);
//Barcode Reader
reply.data[0] = channel;
reply.data[1] = 0x6; //Data Size
reply.data[4 + 0] = 0x02;
reply.data[4 + 1] = 0x02;
reply.data[4 + 2] = 0x80;
reply.data[4 + 3] = 0x02; //This is used for result
reply.data[4 + 4] = 0x03;
reply.data[4 + 5] = 0x03;
}
else if(channel == 2)
{
ProcessIcCard(reply, *packet);
}
else
{
assert(false);
}
reply.checksum = ComputePacketChecksum(reply);
m_pendingReplies.emplace_back(reply);
}
Expand Down Expand Up @@ -304,6 +322,111 @@ bool CSys147::Invoke99(uint32 method, uint32* args, uint32 argsSize, uint32* ret
return true;
}

void CSys147::ProcessIcCard(MODULE_99_PACKET& output, const MODULE_99_PACKET& input)
{
uint32 channel = input.data[0];
assert(channel == 2);
uint32 dataSize = input.data[1];
uint32 commandId = input.data[5];
uint32 replySize = 0;
static const uint32 replyBase = 4;
output.data[replyBase + 0] = 0x02;
output.data[replyBase + 1] = commandId; //Command ID
switch(commandId)
{
case 0x78:
{
//??
assert(dataSize == 0x07);
replySize = 6;
output.data[replyBase + 3] = 0x00; //Command result?
output.data[replyBase + 4] = 0x00;
output.data[replyBase + 5] = 0xFF;

}
break;
case 0x7A:
{
//Ok next?
assert(dataSize == 0x12);
replySize = 4;
output.data[replyBase + 3] = 0x00; //Command result?
}
break;
case 0x7B:
{
assert(dataSize == 0x05);
replySize = 6;
output.data[replyBase + 3] = 0x00; //Command result? (0x03 -> No IC card)
output.data[replyBase + 4] = 0x00; //??
output.data[replyBase + 5] = 0x00; //??
}
break;
case 0x80:
{
//??
assert(dataSize == 0x05);
replySize = 4;
output.data[replyBase + 3] = 0x0D; //Command result?
}
break;
case 0x9F:
{
//??
assert(dataSize == 0x0D);
replySize = 4;
output.data[replyBase + 3] = 0x00; //Command result?
}
break;
case 0xA7:
{
//Init?
assert(dataSize == 0x0D);
replySize = 4;
output.data[replyBase + 3] = 0x00; //Command result?
}
break;
case 0xAC:
{
//Some key stuff (parity)? (game expects 8 bytes in payload)
assert(dataSize == 0x05);
replySize = 12;
output.data[replyBase + 3] = 0x00; //Command result?
output.data[replyBase + 4] = 0xAA;
output.data[replyBase + 5] = 0xAA;
output.data[replyBase + 6] = 0xAA;
output.data[replyBase + 7] = 0xAA;
output.data[replyBase + 8] = 0x55;
output.data[replyBase + 9] = 0x55;
output.data[replyBase + 10] = 0x55;
output.data[replyBase + 11] = 0x55;
}
break;
case 0xAF:
{
//More key stuff (checksum)? (game expects 16 bytes in payload)
assert(dataSize == 0x05);
replySize = 20;
output.data[replyBase + 3] = 0x00; //Command result?
}
break;
default:
assert(false);
break;
}
uint8 replySizePlusParity = replySize + 1;
assert(replySizePlusParity >= 5);
output.data[0] = channel;
output.data[1] = replySizePlusParity; //This needs to be at least 5
output.data[replyBase + 2] = replySizePlusParity - 5;
uint8 parity = 0;
for(int i = 1; i < replySize; i++)
{
parity ^= output.data[replyBase + i];
}
output.data[replyBase + replySize] = parity;
}

uint8 CSys147::ComputePacketChecksum(const MODULE_99_PACKET& packet)
{
uint8 checksum = 0;
Expand Down
1 change: 1 addition & 0 deletions Source/iop/namco_sys147/Iop_NamcoSys147.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace Iop
bool Invoke201(uint32, uint32*, uint32, uint32*, uint32, uint8*);
bool Invoke99(uint32, uint32*, uint32, uint32*, uint32, uint8*);

void ProcessIcCard(MODULE_99_PACKET&, const MODULE_99_PACKET&);
uint8 ComputePacketChecksum(const MODULE_99_PACKET&);

static constexpr int32 BACKUP_RAM_SIZE = 0x20000;
Expand Down

0 comments on commit 84e0f17

Please sign in to comment.