summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/machine
diff options
context:
space:
mode:
author Firehawke <Firehawke@users.noreply.github.com>2017-12-13 21:31:27 -0700
committer Firehawke <Firehawke@users.noreply.github.com>2017-12-13 21:31:27 -0700
commit9ece34eb218c5c1960468294c733fd00ac7fa696 (patch)
tree7160ed8d2cbe2127aaaef0a21f8736403b0f8a7c /src/mame/machine
parent54155441e9ba9941e85d80c4834a66376a11e791 (diff)
Revert "Revert "Merge branch 'master' of https://github.com/mamedev/mame""
This reverts commit 54155441e9ba9941e85d80c4834a66376a11e791.
Diffstat (limited to 'src/mame/machine')
-rw-r--r--src/mame/machine/315-5881_crypt.cpp6
-rw-r--r--src/mame/machine/apollo_dbg.cpp5
-rw-r--r--src/mame/machine/archimds.cpp2
-rw-r--r--src/mame/machine/atarifdc.cpp2
-rw-r--r--src/mame/machine/awboard.cpp4
-rw-r--r--src/mame/machine/bfm_bd1.cpp2
-rw-r--r--src/mame/machine/bfm_bda.cpp2
-rw-r--r--src/mame/machine/cps2crypt.cpp4
-rw-r--r--src/mame/machine/deco102.cpp2
-rw-r--r--src/mame/machine/deco146.cpp4
-rw-r--r--src/mame/machine/deco156.cpp8
-rw-r--r--src/mame/machine/deco222.cpp8
-rw-r--r--src/mame/machine/decocpu6.cpp4
-rw-r--r--src/mame/machine/decocpu7.cpp4
-rw-r--r--src/mame/machine/decocrpt.cpp2
-rw-r--r--src/mame/machine/epos.cpp2
-rw-r--r--src/mame/machine/fd1089.cpp28
-rw-r--r--src/mame/machine/fd1094.cpp32
-rw-r--r--src/mame/machine/gaelcrpt.cpp10
-rw-r--r--src/mame/machine/gb.cpp4
-rw-r--r--src/mame/machine/hp9845_printer.cpp971
-rw-r--r--src/mame/machine/hp9845_printer.h134
-rw-r--r--src/mame/machine/igs025.cpp4
-rw-r--r--src/mame/machine/igs036crypt.cpp425
-rw-r--r--src/mame/machine/igs036crypt.h19
-rw-r--r--src/mame/machine/jalcrpt.cpp20
-rw-r--r--src/mame/machine/jumpshot.cpp2
-rw-r--r--src/mame/machine/kaneko_calc3.cpp16
-rw-r--r--src/mame/machine/m24_z8000.cpp8
-rw-r--r--src/mame/machine/mac.cpp2
-rw-r--r--src/mame/machine/mbee.cpp8
-rw-r--r--src/mame/machine/mc8123.cpp78
-rw-r--r--src/mame/machine/megacd.cpp8
-rw-r--r--src/mame/machine/mexico86.cpp4
-rw-r--r--src/mame/machine/mpu4.cpp16
-rw-r--r--src/mame/machine/pacplus.cpp2
-rw-r--r--src/mame/machine/pgm2_memcard.cpp149
-rw-r--r--src/mame/machine/pgm2_memcard.h75
-rw-r--r--src/mame/machine/pgmprot_igs027a_type1.cpp12
-rw-r--r--src/mame/machine/pgmprot_igs027a_type3.cpp2
-rw-r--r--src/mame/machine/pgmprot_orlegend.cpp2
-rw-r--r--src/mame/machine/r2crypt.cpp4
-rw-r--r--src/mame/machine/scramble.cpp30
-rw-r--r--src/mame/machine/segacrp2_device.cpp4
-rw-r--r--src/mame/machine/segas32.cpp2
-rw-r--r--src/mame/machine/seibuspi.cpp4
-rw-r--r--src/mame/machine/subsino.cpp64
-rw-r--r--src/mame/machine/tatsumi.cpp35
-rw-r--r--src/mame/machine/ticket.cpp49
-rw-r--r--src/mame/machine/ticket.h13
-rw-r--r--src/mame/machine/trs80m2kb.cpp2
-rw-r--r--src/mame/machine/xevious.cpp2
52 files changed, 1704 insertions, 597 deletions
diff --git a/src/mame/machine/315-5881_crypt.cpp b/src/mame/machine/315-5881_crypt.cpp
index 275c5614442..2d3144a7134 100644
--- a/src/mame/machine/315-5881_crypt.cpp
+++ b/src/mame/machine/315-5881_crypt.cpp
@@ -617,7 +617,7 @@ uint16_t sega_315_5881_crypt_device::block_decrypt(uint32_t game_key, uint16_t s
// First Feistel Network
- aux = BITSWAP16(counter, 5, 12, 14, 13, 9, 3, 6, 4, 8, 1, 15, 11, 0, 7, 10, 2);
+ aux = bitswap<16>(counter, 5, 12, 14, 13, 9, 3, 6, 4, 8, 1, 15, 11, 0, 7, 10, 2);
// 1st round
B = aux >> 8;
@@ -647,7 +647,7 @@ uint16_t sega_315_5881_crypt_device::block_decrypt(uint32_t game_key, uint16_t s
// Second Feistel Network
- aux = BITSWAP16(data, 14, 3, 8, 12, 13, 7, 15, 4, 6, 2, 9, 5, 11, 0, 1, 10);
+ aux = bitswap<16>(data, 14, 3, 8, 12, 13, 7, 15, 4, 6, 2, 9, 5, 11, 0, 1, 10);
// 1st round
B = aux >> 8;
@@ -664,7 +664,7 @@ uint16_t sega_315_5881_crypt_device::block_decrypt(uint32_t game_key, uint16_t s
aux = (B << 8) | A;
- aux = BITSWAP16(aux, 15, 7, 6, 14, 13, 12, 5, 4, 3, 2, 11, 10, 9, 1, 0, 8);
+ aux = bitswap<16>(aux, 15, 7, 6, 14, 13, 12, 5, 4, 3, 2, 11, 10, 9, 1, 0, 8);
return aux;
}
diff --git a/src/mame/machine/apollo_dbg.cpp b/src/mame/machine/apollo_dbg.cpp
index 208a563b7c3..345788256f2 100644
--- a/src/mame/machine/apollo_dbg.cpp
+++ b/src/mame/machine/apollo_dbg.cpp
@@ -13,7 +13,9 @@
#include "emu.h"
#include "debug/debugbuf.h"
#include "includes/apollo.h"
-#include "cpu/m68000/m68kcpu.h"
+#include "cpu/m68000/m68000.h"
+
+#if 0
//------------------------------------------------------
// TRAP 0
@@ -1168,3 +1170,4 @@ int apollo_debug_instruction_hook(m68000_base_device *device, offs_t curpc)
}
return 0;
}
+#endif
diff --git a/src/mame/machine/archimds.cpp b/src/mame/machine/archimds.cpp
index 8868f485f1a..f6d2c73ae81 100644
--- a/src/mame/machine/archimds.cpp
+++ b/src/mame/machine/archimds.cpp
@@ -982,7 +982,7 @@ WRITE32_MEMBER(archimedes_state::archimedes_vidc_w)
for(i=0;i<0x100;i+=0x10)
{
b = ((val & 0x700) >> 8) | ((i & 0x80) >> 4);
- g = ((val & 0x030) >> 4) | ((i & 0x20) >> 3) | ((i & 0x40) >> 3);
+ g = ((val & 0x030) >> 4) | ((i & 0x60) >> 3);
r = ((val & 0x007) >> 0) | ((i & 0x10) >> 1);
m_palette->set_pen_color((reg >> 2) + 0x100 + i, pal4bit(r), pal4bit(g), pal4bit(b) );
diff --git a/src/mame/machine/atarifdc.cpp b/src/mame/machine/atarifdc.cpp
index 0603ebda199..207d9ad5ab1 100644
--- a/src/mame/machine/atarifdc.cpp
+++ b/src/mame/machine/atarifdc.cpp
@@ -111,7 +111,7 @@ static void _atari_load_proc(device_image_interface &image, bool is_created)
void atari_fdc_device::atari_load_proc(device_image_interface &image, bool is_created)
{
- int id = floppy_get_drive(image);
+ int id = floppy_get_drive(&image.device());
int size, i;
m_drv[id].image = std::make_unique<uint8_t[]>(MAXSIZE);
diff --git a/src/mame/machine/awboard.cpp b/src/mame/machine/awboard.cpp
index ddc49a3cfa0..e03f11d22c0 100644
--- a/src/mame/machine/awboard.cpp
+++ b/src/mame/machine/awboard.cpp
@@ -241,10 +241,10 @@ uint16_t aw_rom_board::decrypt(uint16_t cipherText, uint32_t address, const uint
const int* pbox = permutation_table[key>>18];
const sbox_set* ss = &sboxes_table[(key>>16)&3];
- aux = BITSWAP16(cipherText,
+ aux = bitswap<16>(cipherText,
pbox[15],pbox[14],pbox[13],pbox[12],pbox[11],pbox[10],pbox[9],pbox[8],
pbox[7],pbox[6],pbox[5],pbox[4],pbox[3],pbox[2],pbox[1],pbox[0]);
- aux = aux ^ BITSWAP16(address, 13,5,2, 14,10,9,4, 15,11,6,1, 12,8,7,3,0);
+ aux = aux ^ bitswap<16>(address, 13,5,2, 14,10,9,4, 15,11,6,1, 12,8,7,3,0);
b0 = aux&0x1f;
b1 = (aux>>5)&0xf;
diff --git a/src/mame/machine/bfm_bd1.cpp b/src/mame/machine/bfm_bd1.cpp
index b9abdaa0deb..10d18618fa0 100644
--- a/src/mame/machine/bfm_bd1.cpp
+++ b/src/mame/machine/bfm_bd1.cpp
@@ -164,7 +164,7 @@ void bfm_bd1_device::device_reset()
uint16_t bfm_bd1_device::set_display(uint16_t segin)
{
- return BITSWAP16(segin,8,12,11,7,6,4,10,3,14,15,0,13,9,5,1,2);
+ return bitswap<16>(segin,8,12,11,7,6,4,10,3,14,15,0,13,9,5,1,2);
}
void bfm_bd1_device::device_post_load()
diff --git a/src/mame/machine/bfm_bda.cpp b/src/mame/machine/bfm_bda.cpp
index 263db3a7a0c..6d2794b7dd1 100644
--- a/src/mame/machine/bfm_bda.cpp
+++ b/src/mame/machine/bfm_bda.cpp
@@ -146,7 +146,7 @@ void bfm_bda_device::device_reset()
uint16_t bfm_bda_device::set_display(uint16_t segin)
{
- return BITSWAP16(segin,8,12,11,7,6,4,10,3,14,15,0,13,9,5,1,2);
+ return bitswap<16>(segin,8,12,11,7,6,4,10,3,14,15,0,13,9,5,1,2);
}
void bfm_bda_device::device_post_load()
diff --git a/src/mame/machine/cps2crypt.cpp b/src/mame/machine/cps2crypt.cpp
index ceccdea6b5b..96d94a20f47 100644
--- a/src/mame/machine/cps2crypt.cpp
+++ b/src/mame/machine/cps2crypt.cpp
@@ -557,8 +557,8 @@ static uint16_t feistel(uint16_t val, const int *bitsA, const int *bitsB,
const struct optimised_sbox* boxes1, const struct optimised_sbox* boxes2, const struct optimised_sbox* boxes3, const struct optimised_sbox* boxes4,
uint32_t key1, uint32_t key2, uint32_t key3, uint32_t key4)
{
- uint8_t l = BITSWAP8(val, bitsB[7],bitsB[6],bitsB[5],bitsB[4],bitsB[3],bitsB[2],bitsB[1],bitsB[0]);
- uint8_t r = BITSWAP8(val, bitsA[7],bitsA[6],bitsA[5],bitsA[4],bitsA[3],bitsA[2],bitsA[1],bitsA[0]);
+ uint8_t l = bitswap<8>(val, bitsB[7],bitsB[6],bitsB[5],bitsB[4],bitsB[3],bitsB[2],bitsB[1],bitsB[0]);
+ uint8_t r = bitswap<8>(val, bitsA[7],bitsA[6],bitsA[5],bitsA[4],bitsA[3],bitsA[2],bitsA[1],bitsA[0]);
l ^= fn(r, boxes1, key1);
r ^= fn(l, boxes2, key2);
diff --git a/src/mame/machine/deco102.cpp b/src/mame/machine/deco102.cpp
index 210ee3f6afa..0c643c529aa 100644
--- a/src/mame/machine/deco102.cpp
+++ b/src/mame/machine/deco102.cpp
@@ -44,7 +44,7 @@ static uint16_t decrypt(uint16_t data, int address, int select_xor)
xorval = xors[j];
// decrypt
- return xorval ^ BITSWAP16(data,
+ return xorval ^ bitswap<16>(data,
bs[0],bs[1],bs[2],bs[3],bs[4],bs[5],bs[6],bs[7],
bs[8],bs[9],bs[10],bs[11],bs[12],bs[13],bs[14],bs[15]);
}
diff --git a/src/mame/machine/deco146.cpp b/src/mame/machine/deco146.cpp
index 05bc061ce3e..fd15795691a 100644
--- a/src/mame/machine/deco146.cpp
+++ b/src/mame/machine/deco146.cpp
@@ -1142,7 +1142,7 @@ inline uint16_t reorder(uint16_t input, uint8_t const *weights)
void deco_146_base_device::write_data(address_space &space, uint16_t address, uint16_t data, uint16_t mem_mask, uint8_t &csflags)
{
- address = BITSWAP16(address>>1, 15,14,13,12,11,10, m_external_addrswap[9],m_external_addrswap[8] ,m_external_addrswap[7],m_external_addrswap[6],m_external_addrswap[5],m_external_addrswap[4],m_external_addrswap[3],m_external_addrswap[2],m_external_addrswap[1],m_external_addrswap[0]) << 1;
+ address = bitswap<16>(address>>1, 15,14,13,12,11,10, m_external_addrswap[9],m_external_addrswap[8] ,m_external_addrswap[7],m_external_addrswap[6],m_external_addrswap[5],m_external_addrswap[4],m_external_addrswap[3],m_external_addrswap[2],m_external_addrswap[1],m_external_addrswap[0]) << 1;
csflags = 0;
int upper_addr_bits = (address & 0x7800) >> 11;
@@ -1268,7 +1268,7 @@ void deco_146_base_device::write_protport(address_space &space, uint16_t address
uint16_t deco_146_base_device::read_data(uint16_t address, uint16_t mem_mask, uint8_t &csflags)
{
- address = BITSWAP16(address>>1, 15,14,13,12,11,10, m_external_addrswap[9],m_external_addrswap[8] ,m_external_addrswap[7],m_external_addrswap[6],m_external_addrswap[5],m_external_addrswap[4],m_external_addrswap[3],m_external_addrswap[2],m_external_addrswap[1],m_external_addrswap[0]) << 1;
+ address = bitswap<16>(address>>1, 15,14,13,12,11,10, m_external_addrswap[9],m_external_addrswap[8] ,m_external_addrswap[7],m_external_addrswap[6],m_external_addrswap[5],m_external_addrswap[4],m_external_addrswap[3],m_external_addrswap[2],m_external_addrswap[1],m_external_addrswap[0]) << 1;
uint16_t retdata = 0;
csflags = 0;
diff --git a/src/mame/machine/deco156.cpp b/src/mame/machine/deco156.cpp
index 3258c55a66d..d763611d517 100644
--- a/src/mame/machine/deco156.cpp
+++ b/src/mame/machine/deco156.cpp
@@ -87,7 +87,7 @@ static void decrypt(uint32_t *src, uint32_t *dst, int length)
switch (a & 3)
{
case 0:
- dword = BITSWAP32( dword ^ 0xec63197a,
+ dword = bitswap<32>( dword ^ 0xec63197a,
1, 4, 7, 28, 22, 18, 20, 9,
16, 10, 30, 2, 31, 24, 19, 29,
6, 21, 23, 11, 12, 13, 5, 0,
@@ -95,7 +95,7 @@ static void decrypt(uint32_t *src, uint32_t *dst, int length)
break;
case 1:
- dword = BITSWAP32( dword ^ 0x58a5a55f,
+ dword = bitswap<32>( dword ^ 0x58a5a55f,
14, 23, 28, 29, 6, 24, 10, 1,
5, 16, 7, 2, 30, 8, 18, 3,
31, 22, 25, 20, 17, 0, 19, 27,
@@ -103,7 +103,7 @@ static void decrypt(uint32_t *src, uint32_t *dst, int length)
break;
case 2:
- dword = BITSWAP32( dword ^ 0xe3a65f16,
+ dword = bitswap<32>( dword ^ 0xe3a65f16,
19, 30, 21, 4, 2, 18, 15, 1,
12, 25, 8, 0, 24, 20, 17, 23,
22, 26, 28, 16, 9, 27, 6, 11,
@@ -111,7 +111,7 @@ static void decrypt(uint32_t *src, uint32_t *dst, int length)
break;
case 3:
- dword = BITSWAP32( dword ^ 0x28d93783,
+ dword = bitswap<32>( dword ^ 0x28d93783,
30, 6, 15, 0, 31, 18, 26, 22,
14, 23, 19, 17, 10, 8, 11, 20,
1, 28, 2, 4, 9, 24, 25, 27,
diff --git a/src/mame/machine/deco222.cpp b/src/mame/machine/deco222.cpp
index 5be4df0bb60..1371f8087b4 100644
--- a/src/mame/machine/deco222.cpp
+++ b/src/mame/machine/deco222.cpp
@@ -31,7 +31,7 @@ void deco_222_device::device_reset()
uint8_t deco_222_device::mi_decrypt::read_sync(uint16_t adr)
{
- return BITSWAP8(direct->read_byte(adr) ,7,5,6,4,3,2,1,0);
+ return bitswap<8>(direct->read_byte(adr) ,7,5,6,4,3,2,1,0);
}
util::disasm_interface *deco_222_device::create_disassembler()
@@ -46,7 +46,7 @@ u32 deco_222_device::disassembler::interface_flags() const
u8 deco_222_device::disassembler::decrypt8(u8 value, offs_t pc, bool opcode) const
{
- return opcode ? BITSWAP8(value,7,5,6,4,3,2,1,0) : value;
+ return opcode ? bitswap<8>(value,7,5,6,4,3,2,1,0) : value;
}
deco_c10707_device::deco_c10707_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
@@ -68,7 +68,7 @@ void deco_c10707_device::device_reset()
uint8_t deco_c10707_device::mi_decrypt::read_sync(uint16_t adr)
{
- return BITSWAP8(direct->read_byte(adr) ,7,5,6,4,3,2,1,0);
+ return bitswap<8>(direct->read_byte(adr) ,7,5,6,4,3,2,1,0);
}
util::disasm_interface *deco_c10707_device::create_disassembler()
@@ -83,5 +83,5 @@ u32 deco_c10707_device::disassembler::interface_flags() const
u8 deco_c10707_device::disassembler::decrypt8(u8 value, offs_t pc, bool opcode) const
{
- return opcode ? BITSWAP8(value,7,5,6,4,3,2,1,0) : value;
+ return opcode ? bitswap<8>(value,7,5,6,4,3,2,1,0) : value;
}
diff --git a/src/mame/machine/decocpu6.cpp b/src/mame/machine/decocpu6.cpp
index 9e068e73adb..f583887188f 100644
--- a/src/mame/machine/decocpu6.cpp
+++ b/src/mame/machine/decocpu6.cpp
@@ -31,7 +31,7 @@ void deco_cpu6_device::device_reset()
uint8_t deco_cpu6_device::mi_decrypt::read_sync(uint16_t adr)
{
if (adr&1)
- return BITSWAP8(direct->read_byte(adr),6,4,7,5,3,2,1,0);
+ return bitswap<8>(direct->read_byte(adr),6,4,7,5,3,2,1,0);
else
return direct->read_byte(adr);
}
@@ -48,5 +48,5 @@ u32 deco_cpu6_device::disassembler::interface_flags() const
u8 deco_cpu6_device::disassembler::decrypt8(u8 value, offs_t pc, bool opcode) const
{
- return opcode && (pc & 1) ? BITSWAP8(value,6,4,7,5,3,2,1,0) : value;
+ return opcode && (pc & 1) ? bitswap<8>(value,6,4,7,5,3,2,1,0) : value;
}
diff --git a/src/mame/machine/decocpu7.cpp b/src/mame/machine/decocpu7.cpp
index 50144063bb4..dd0031ff7b8 100644
--- a/src/mame/machine/decocpu7.cpp
+++ b/src/mame/machine/decocpu7.cpp
@@ -30,7 +30,7 @@ uint8_t deco_cpu7_device::mi_decrypt::read_sync(uint16_t adr)
if(had_written) {
had_written = false;
if((adr & 0x0104) == 0x0104)
- res = BITSWAP8(res, 6,5,3,4,2,7,1,0);
+ res = bitswap<8>(res, 6,5,3,4,2,7,1,0);
}
return res;
}
@@ -57,5 +57,5 @@ u32 deco_cpu7_device::disassembler::interface_flags() const
u8 deco_cpu7_device::disassembler::decrypt8(u8 value, offs_t pc, bool opcode) const
{
- return opcode && mintf->had_written && ((pc & 0x104) == 0x104) ? BITSWAP8(value,6,5,3,4,2,7,1,0) : value;
+ return opcode && mintf->had_written && ((pc & 0x104) == 0x104) ? bitswap<8>(value,6,5,3,4,2,7,1,0) : value;
}
diff --git a/src/mame/machine/decocrpt.cpp b/src/mame/machine/decocrpt.cpp
index dda584c2d76..ad5e212414b 100644
--- a/src/mame/machine/decocrpt.cpp
+++ b/src/mame/machine/decocrpt.cpp
@@ -622,7 +622,7 @@ static void deco_decrypt(running_machine &machine,const char *rgntag,const uint8
if (remap_only)
rom[i] = buffer[addr];
else
- rom[i] = BITSWAP16(buffer[addr] ^ xor_masks[xor_table[addr & 0x7ff]],
+ rom[i] = bitswap<16>(buffer[addr] ^ xor_masks[xor_table[addr & 0x7ff]],
swap_patterns[pat][0],
swap_patterns[pat][1],
swap_patterns[pat][2],
diff --git a/src/mame/machine/epos.cpp b/src/mame/machine/epos.cpp
index 3ead45d89be..da7f5f12326 100644
--- a/src/mame/machine/epos.cpp
+++ b/src/mame/machine/epos.cpp
@@ -36,7 +36,7 @@ static void epos_decrypt_rom(uint8_t *ROM, uint8_t invert, int offset, int *bs)
{
for (int mem = 0; mem < 0x4000; mem++ )
{
- ROM[mem + offset] = BITSWAP8(ROM[mem] ^ invert, bs[0], bs[1], bs[2], bs[3], bs[4], bs[5], bs[6], bs[7]);
+ ROM[mem + offset] = bitswap<8>(ROM[mem] ^ invert, bs[0], bs[1], bs[2], bs[3], bs[4], bs[5], bs[6], bs[7]);
}
}
diff --git a/src/mame/machine/fd1089.cpp b/src/mame/machine/fd1089.cpp
index e364581916c..15938db5773 100644
--- a/src/mame/machine/fd1089.cpp
+++ b/src/mame/machine/fd1089.cpp
@@ -290,10 +290,10 @@ uint8_t fd1089_base_device::rearrange_key(uint8_t table, bool opcode)
if (BIT(table,6))
table ^= (1<<7);
- table = BITSWAP8(table,1,0,6,4,3,5,2,7);
+ table = bitswap<8>(table,1,0,6,4,3,5,2,7);
if (BIT(table,6))
- table = BITSWAP8(table,7,6,2,4,5,3,1,0);
+ table = bitswap<8>(table,7,6,2,4,5,3,1,0);
}
else
{
@@ -307,10 +307,10 @@ uint8_t fd1089_base_device::rearrange_key(uint8_t table, bool opcode)
if (BIT(~table,7))
table ^= (1<<6);
- table = BITSWAP8(table,5,6,7,4,2,3,1,0);
+ table = bitswap<8>(table,5,6,7,4,2,3,1,0);
if (BIT(table,6))
- table = BITSWAP8(table,7,6,5,3,2,4,1,0);
+ table = bitswap<8>(table,7,6,5,3,2,4,1,0);
}
if (BIT(table,6))
@@ -342,7 +342,7 @@ uint8_t fd1089a_device::decode(uint8_t val, uint8_t key, bool opcode)
uint8_t table = rearrange_key(key, opcode);
const decrypt_parameters &p = s_addr_params[table >> 4];
- val = BITSWAP8(val, p.s7,p.s6,p.s5,p.s4,p.s3,p.s2,p.s1,p.s0) ^ p.xorval;
+ val = bitswap<8>(val, p.s7,p.s6,p.s5,p.s4,p.s3,p.s2,p.s1,p.s0) ^ p.xorval;
if (BIT(table,3)) val ^= 0x01;
if (BIT(table,0)) val ^= 0xb1;
@@ -369,20 +369,20 @@ uint8_t fd1089a_device::decode(uint8_t val, uint8_t key, bool opcode)
{
if (BIT(val,0)) val ^= 0xc0;
if (BIT(~val,6) ^ BIT(val,4))
- val = BITSWAP8(val, 7,6,5,4,1,0,2,3);
+ val = bitswap<8>(val, 7,6,5,4,1,0,2,3);
}
else
{
if (BIT(~val,6) ^ BIT(val,4))
- val = BITSWAP8(val, 7,6,5,4,0,1,3,2);
+ val = bitswap<8>(val, 7,6,5,4,0,1,3,2);
}
if (BIT(~val,6))
- val = BITSWAP8(val, 7,6,5,4,2,3,0,1);
+ val = bitswap<8>(val, 7,6,5,4,2,3,0,1);
const decrypt_parameters &q = s_data_params_a[family];
val ^= q.xorval;
- val = BITSWAP8(val, q.s7,q.s6,q.s5,q.s4,q.s3,q.s2,q.s1,q.s0);
+ val = bitswap<8>(val, q.s7,q.s6,q.s5,q.s4,q.s3,q.s2,q.s1,q.s0);
return val;
}
@@ -402,7 +402,7 @@ uint8_t fd1089b_device::decode(uint8_t val, uint8_t key, bool opcode)
uint8_t table = rearrange_key(key, opcode);
const decrypt_parameters &p = s_addr_params[table >> 4];
- val = BITSWAP8(val, p.s7,p.s6,p.s5,p.s4,p.s3,p.s2,p.s1,p.s0) ^ p.xorval;
+ val = bitswap<8>(val, p.s7,p.s6,p.s5,p.s4,p.s3,p.s2,p.s1,p.s0) ^ p.xorval;
if (BIT(table,3)) val ^= 0x01;
if (BIT(table,0)) val ^= 0xb1;
@@ -429,17 +429,17 @@ uint8_t fd1089b_device::decode(uint8_t val, uint8_t key, bool opcode)
if (BIT(table,2))
{
- val = BITSWAP8(val, 7,6,5,4,1,0,3,2);
+ val = bitswap<8>(val, 7,6,5,4,1,0,3,2);
if (BIT(table,0) ^ BIT(table,1))
- val = BITSWAP8(val, 7,6,5,4,0,1,3,2);
+ val = bitswap<8>(val, 7,6,5,4,0,1,3,2);
}
else
{
- val = BITSWAP8(val, 7,6,5,4,3,2,0,1);
+ val = bitswap<8>(val, 7,6,5,4,3,2,0,1);
if (BIT(table,0) ^ BIT(table,1))
- val = BITSWAP8(val, 7,6,5,4,1,0,2,3);
+ val = bitswap<8>(val, 7,6,5,4,1,0,2,3);
}
return val;
diff --git a/src/mame/machine/fd1094.cpp b/src/mame/machine/fd1094.cpp
index ed8dfe87617..20d33cec87a 100644
--- a/src/mame/machine/fd1094.cpp
+++ b/src/mame/machine/fd1094.cpp
@@ -815,7 +815,7 @@ uint16_t fd1094_device::decrypt_one(offs_t address, uint16_t val, const uint8_t
if (val & 0x8000) // block invariant: val & 0x8000 != 0
{
- val = BITSWAP16(val, 15, 9,10,13, 3,12, 0,14, 6, 5, 2,11, 8, 1, 4, 7);
+ val = bitswap<16>(val, 15, 9,10,13, 3,12, 0,14, 6, 5, 2,11, 8, 1, 4, 7);
if (!global_xor1) if (~val & 0x0800) val ^= 0x3002; // 1,12,13
if (true) if (~val & 0x0020) val ^= 0x0044; // 2,6
@@ -823,12 +823,12 @@ uint16_t fd1094_device::decrypt_one(offs_t address, uint16_t val, const uint8_t
if (!global_swap2) if (!key_0c) val ^= 0x0308; // 3,8,9
val ^= 0x6561;
- if (!key_2b) val = BITSWAP16(val,15,10,13,12,11,14,9,8,7,6,0,4,3,2,1,5); // 0-5, 10-14
+ if (!key_2b) val = bitswap<16>(val,15,10,13,12,11,14,9,8,7,6,0,4,3,2,1,5); // 0-5, 10-14
}
if (val & 0x4000) // block invariant: val & 0x4000 != 0
{
- val = BITSWAP16(val, 13,14, 7, 0, 8, 6, 4, 2, 1,15, 3,11,12,10, 5, 9);
+ val = bitswap<16>(val, 13,14, 7, 0, 8, 6, 4, 2, 1,15, 3,11,12,10, 5, 9);
if (!global_xor0) if (val & 0x0010) val ^= 0x0468; // 3,5,6,10
if (!key_3a) if (val & 0x0100) val ^= 0x0081; // 0,7
@@ -836,12 +836,12 @@ uint16_t fd1094_device::decrypt_one(offs_t address, uint16_t val, const uint8_t
if (!key_5b) if (!key_0b) val ^= 0x3012; // 1,4,12,13
val ^= 0x3523;
- if (!global_swap0b) val = BITSWAP16(val, 2,14,13,12, 9,10,11, 8, 7, 6, 5, 4, 3,15, 1, 0); // 2-15, 9-11
+ if (!global_swap0b) val = bitswap<16>(val, 2,14,13,12, 9,10,11, 8, 7, 6, 5, 4, 3,15, 1, 0); // 2-15, 9-11
}
if (val & 0x2000) // block invariant: val & 0x2000 != 0
{
- val = BITSWAP16(val, 10, 2,13, 7, 8, 0, 3,14, 6,15, 1,11, 9, 4, 5,12);
+ val = bitswap<16>(val, 10, 2,13, 7, 8, 0, 3,14, 6,15, 1,11, 9, 4, 5,12);
if (!key_4a) if (val & 0x0800) val ^= 0x010c; // 2,3,8
if (!key_1a) if (val & 0x0080) val ^= 0x1000; // 12
@@ -850,27 +850,27 @@ uint16_t fd1094_device::decrypt_one(offs_t address, uint16_t val, const uint8_t
if (!global_swap0a) if (!key_6b) val ^= 0xc000; // 14,15
val ^= 0x99a5;
- if (!key_5b) val = BITSWAP16(val,15,14,13,12,11, 1, 9, 8, 7,10, 5, 6, 3, 2, 4, 0); // 1,4,6,10
+ if (!key_5b) val = bitswap<16>(val,15,14,13,12,11, 1, 9, 8, 7,10, 5, 6, 3, 2, 4, 0); // 1,4,6,10
}
if (val & 0xe000) // block invariant: val & 0xe000 != 0
{
- val = BITSWAP16(val,15,13,14, 5, 6, 0, 9,10, 4,11, 1, 2,12, 3, 7, 8);
+ val = bitswap<16>(val,15,13,14, 5, 6, 0, 9,10, 4,11, 1, 2,12, 3, 7, 8);
val ^= 0x17ff;
- if (!global_swap4) val = BITSWAP16(val, 15,14,13, 6,11,10, 9, 5, 7,12, 8, 4, 3, 2, 1, 0); // 5-8, 6-12
- if (!global_swap3) val = BITSWAP16(val, 13,15,14,12,11,10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0); // 15-14-13
- if (!global_swap2) val = BITSWAP16(val, 15,14,13,12,11, 2, 9, 8,10, 6, 5, 4, 3, 0, 1, 7); // 10-2-0-7
- if (!key_3b) val = BITSWAP16(val, 15,14,13,12,11,10, 4, 8, 7, 6, 5, 9, 1, 2, 3, 0); // 9-4, 3-1
- if (!key_2a) val = BITSWAP16(val, 13,14,15,12,11,10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0); // 13-15
+ if (!global_swap4) val = bitswap<16>(val, 15,14,13, 6,11,10, 9, 5, 7,12, 8, 4, 3, 2, 1, 0); // 5-8, 6-12
+ if (!global_swap3) val = bitswap<16>(val, 13,15,14,12,11,10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0); // 15-14-13
+ if (!global_swap2) val = bitswap<16>(val, 15,14,13,12,11, 2, 9, 8,10, 6, 5, 4, 3, 0, 1, 7); // 10-2-0-7
+ if (!key_3b) val = bitswap<16>(val, 15,14,13,12,11,10, 4, 8, 7, 6, 5, 9, 1, 2, 3, 0); // 9-4, 3-1
+ if (!key_2a) val = bitswap<16>(val, 13,14,15,12,11,10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0); // 13-15
- if (!global_swap1) val = BITSWAP16(val, 15,14,13,12, 9, 8,11,10, 7, 6, 5, 4, 3, 2, 1, 0); // 11...8
- if (!key_5a) val = BITSWAP16(val, 15,14,13,12,11,10, 9, 8, 4, 5, 7, 6, 3, 2, 1, 0); // 7...4
- if (!global_swap0a) val = BITSWAP16(val, 15,14,13,12,11,10, 9, 8, 7, 6, 5, 4, 0, 3, 2, 1); // 3...0
+ if (!global_swap1) val = bitswap<16>(val, 15,14,13,12, 9, 8,11,10, 7, 6, 5, 4, 3, 2, 1, 0); // 11...8
+ if (!key_5a) val = bitswap<16>(val, 15,14,13,12,11,10, 9, 8, 4, 5, 7, 6, 3, 2, 1, 0); // 7...4
+ if (!global_swap0a) val = bitswap<16>(val, 15,14,13,12,11,10, 9, 8, 7, 6, 5, 4, 0, 3, 2, 1); // 3...0
}
- val = BITSWAP16(val, 12,15,14,13,11,10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);
+ val = bitswap<16>(val, 12,15,14,13,11,10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);
if ((val & 0xb080) == 0x8000) val ^= 0x4000;
if ((val & 0xf000) == 0xc000) val ^= 0x0080;
diff --git a/src/mame/machine/gaelcrpt.cpp b/src/mame/machine/gaelcrpt.cpp
index 2dbe0f1153f..32166390e02 100644
--- a/src/mame/machine/gaelcrpt.cpp
+++ b/src/mame/machine/gaelcrpt.cpp
@@ -20,10 +20,10 @@ static int decrypt(int const param1, int const param2, int const enc_prev_word,
switch (swap)
{
- case 0: res = BITSWAP16(enc_word, 1, 2, 0,14,12,15, 4, 8,13, 7, 3, 6,11, 5,10, 9); break;
- case 1: res = BITSWAP16(enc_word, 14,10, 4,15, 1, 6,12,11, 8, 0, 9,13, 7, 3, 5, 2); break;
- case 2: res = BITSWAP16(enc_word, 2,13,15, 1,12, 8,14, 4, 6, 0, 9, 5,10, 7, 3,11); break;
- case 3: res = BITSWAP16(enc_word, 3, 8, 1,13,14, 4,15, 0,10, 2, 7,12, 6,11, 9, 5); break;
+ case 0: res = bitswap<16>(enc_word, 1, 2, 0,14,12,15, 4, 8,13, 7, 3, 6,11, 5,10, 9); break;
+ case 1: res = bitswap<16>(enc_word, 14,10, 4,15, 1, 6,12,11, 8, 0, 9,13, 7, 3, 5, 2); break;
+ case 2: res = bitswap<16>(enc_word, 2,13,15, 1,12, 8,14, 4, 6, 0, 9, 5,10, 7, 3,11); break;
+ case 3: res = bitswap<16>(enc_word, 3, 8, 1,13,14, 4,15, 0,10, 2, 7,12, 6,11, 9, 5); break;
}
res ^= param2;
@@ -117,7 +117,7 @@ static int decrypt(int const param1, int const param2, int const enc_prev_word,
res ^= (param1 << 6) | (param1 << 11);
- return BITSWAP16(res, 2,6,0,11,14,12,7,10,5,4,8,3,9,1,13,15);
+ return bitswap<16>(res, 2,6,0,11,14,12,7,10,5,4,8,3,9,1,13,15);
}
diff --git a/src/mame/machine/gb.cpp b/src/mame/machine/gb.cpp
index 0cc70ba6a17..5c4ff891b7a 100644
--- a/src/mame/machine/gb.cpp
+++ b/src/mame/machine/gb.cpp
@@ -723,14 +723,14 @@ READ8_MEMBER(megaduck_state::megaduck_video_r)
data = m_ppu->video_r(space, offset);
if (offset)
return data;
- return BITSWAP8(data,7,0,5,4,6,3,2,1);
+ return bitswap<8>(data,7,0,5,4,6,3,2,1);
}
WRITE8_MEMBER(megaduck_state::megaduck_video_w)
{
if (!offset)
{
- data = BITSWAP8(data,7,3,5,4,2,1,0,6);
+ data = bitswap<8>(data,7,3,5,4,2,1,0,6);
}
if ((offset & 0x0C) && ((offset & 0x0C) ^ 0x0C))
{
diff --git a/src/mame/machine/hp9845_printer.cpp b/src/mame/machine/hp9845_printer.cpp
new file mode 100644
index 00000000000..3741b737552
--- /dev/null
+++ b/src/mame/machine/hp9845_printer.cpp
@@ -0,0 +1,971 @@
+// license:BSD-3-Clause
+// copyright-holders:F. Ulivi
+/*********************************************************************
+
+ hp9845_printer.cpp
+
+ HP9845 internal printer HLE
+
+ The internal printer of HP9845-series machines is a thermal
+ printer. It prints by heating the resistors in a fixed line
+ of 560 elements. A stepper motor advances the paper (and in some
+ cases backs it up).
+ A HP nanoprocessor controls the operation of the printer.
+ The NP runs firmware from a 2 kB ROM and it has 256 bytes of
+ RAM. A second 2 kB ROM acts as character generator.
+ Character cells are 7 pixels wide and 12 pixels high.
+ Shape of characters in the character generator is "compressed"
+ in a peculiar way (see patent) so that the 7x12 cell fits in 8
+ bytes. These 8 bytes are addressed according to a Gray code, not
+ a binary code, to speed up access.
+ Each step of the motor moves the paper by 1/154 of inch. Each
+ line in a normal sized character is 2 steps high. Lines of big
+ sized characters are 3 steps high. The horizontal size of
+ pixels is equal to 2 steps.
+ HLE is necessary because it's very difficult to dump ROMs (they're
+ non-standard HP parts and they're soldered on the PCB).
+ Content of char.gen. was reconstructed by looking at the shape
+ of each character on paper.
+ Thanks to Ansgar Kueckes for letting me run tests "remotely" on
+ his printer.
+
+ Output of printer:
+ - bitbanger 1: raw dump of all bytes from PPU to printer
+ - bitbanger 2: output of printer pixels. Each line has this form:
+ <line_no>:<pixels>, where line_no is the line number (counted in
+ motor steps, see above) and <pixels> is the 560-pixel line. Each
+ character of <pixels> is either a space (no dot) or '*'. This
+ stream can be post-processed to produce a bitmapped graphic.
+ Each '*' is to be translated to a 2x2 black square to preserve
+ the 1:1 aspect-ratio of pixels.
+
+ What's not implemented:
+ - A realistic simulation of printer speed
+ - Form Feed
+ - Handling of page length & top/bottom margins
+ - ESC & l <octal> [ST] commands (set vertical size of lines &
+ top margin of paper)
+
+ References:
+ - US Patent 4,180,854
+ - HP 09845-93000, sep 81, HP9845 BASIC programming (appendix A)
+
+*********************************************************************/
+
+#include "emu.h"
+#include "hp9845_printer.h"
+
+// Debugging
+#define VERBOSE 0
+#include "logmacro.h"
+
+// Bit manipulation
+namespace {
+ template<typename T> constexpr T BIT_MASK(unsigned n)
+ {
+ return (T)1U << n;
+ }
+
+ template<typename T> void BIT_CLR(T& w , unsigned n)
+ {
+ w &= ~BIT_MASK<T>(n);
+ }
+
+ template<typename T> void BIT_SET(T& w , unsigned n)
+ {
+ w |= BIT_MASK<T>(n);
+ }
+
+ template<typename T> void COPY_BIT(bool bit , T& w , unsigned n)
+ {
+ if (bit) {
+ BIT_SET(w , n);
+ } else {
+ BIT_CLR(w , n);
+ }
+ }
+}
+
+// Character constants
+constexpr uint8_t CH_BS = 0x08;
+constexpr uint8_t CH_TAB = 0x09;
+constexpr uint8_t CH_LF = 0x0a;
+constexpr uint8_t CH_CR = 0x0d;
+constexpr uint8_t CH_SH_OUT = 0x0e;
+constexpr uint8_t CH_SH_IN = 0x0f;
+constexpr uint8_t CH_ESC = 0x1b;
+
+// Bits in m_attrs
+constexpr unsigned ATTRS_NEW_BIT = 7; // Redefined character
+constexpr unsigned ATTRS_TAB_BIT = 6; // Tab position
+constexpr unsigned ATTRS_U_L_BIT = 5; // Underlined
+constexpr unsigned ATTRS_BIG_BIT = 4; // Big character
+constexpr uint8_t ATTRS_REDEF_NO_MASK = 0x0f; // Redefined character number
+constexpr uint8_t ATTRS_NEW_MASK = BIT_MASK<uint8_t>(ATTRS_NEW_BIT);
+constexpr uint8_t ATTRS_BIG_MASK = BIT_MASK<uint8_t>(ATTRS_BIG_BIT);
+constexpr uint8_t ATTRS_U_L_MASK = BIT_MASK<uint8_t>(ATTRS_U_L_BIT);
+
+// Various timing constants
+constexpr unsigned MAX_PIXELS_BURNED = 62; // Maximum number of pixels burned in parallel
+constexpr unsigned USEC_LT_16_PIXELS = 4960; // microseconds to burn < 16 pixels
+constexpr unsigned USEC_LT_32_PIXELS = 5984; // microseconds to burn < 32 pixels
+constexpr unsigned USEC_LT_48_PIXELS = 6464; // microseconds to burn < 48 pixels
+constexpr unsigned USEC_GE_48_PIXELS = 6976; // microseconds to burn >= 48 pixels
+constexpr unsigned USEC_1_STEP = 3456; // microseconds for 1 motor step
+
+// Device type definition
+DEFINE_DEVICE_TYPE(HP9845_PRINTER, hp9845_printer_device, "hp9845_prt", "HP9845 internal printer")
+
+hp9845_printer_device::hp9845_printer_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
+: device_t(mconfig , HP9845_PRINTER , tag , owner , clock),
+ m_irl_handler(*this),
+ m_flg_handler(*this),
+ m_sts_handler(*this),
+ m_prt_graph_out(*this , "prt_graphic"),
+ m_prt_alpha_out(*this , "prt_alpha"),
+ m_prt_chargen(*this , "prt_chargen")
+{
+}
+
+ROM_START(hp9845_printer)
+ ROM_REGION(0x800, "prt_chargen", 0)
+ ROM_LOAD("1818-2687.bin", 0, 0x800, CRC(cce64de8) SHA1(1dfabd32f4bdef85f88a514bd1978b80b25a6e80))
+ROM_END
+
+const tiny_rom_entry *hp9845_printer_device::device_rom_region() const
+{
+ return ROM_NAME(hp9845_printer);
+}
+
+MACHINE_CONFIG_MEMBER(hp9845_printer_device::device_add_mconfig)
+ MCFG_DEVICE_ADD("prt_alpha", BITBANGER, 0)
+ MCFG_DEVICE_ADD("prt_graphic", BITBANGER, 0)
+MACHINE_CONFIG_END
+
+void hp9845_printer_device::device_start()
+{
+ m_irl_handler.resolve_safe();
+ m_flg_handler.resolve_safe();
+ m_sts_handler.resolve_safe();
+
+ save_item(NAME(m_display_mode));
+ save_item(NAME(m_shifted));
+ save_item(NAME(m_current_u_l));
+ save_item(NAME(m_current_big));
+ save_item(NAME(m_ibf));
+ save_item(NAME(m_inten));
+ save_item(NAME(m_busy));
+ save_item(NAME(m_ib));
+ save_item(NAME(m_pos));
+ save_item(NAME(m_line));
+ save_item(NAME(m_attrs));
+ save_item(NAME(m_redef_count));
+ save_item(NAME(m_redef_idx));
+ save_item(NAME(m_redef_chars));
+ save_item(NAME(m_replace_count));
+ save_item(NAME(m_redef_buff));
+ save_item(NAME(m_next_replace));
+ save_item(NAME(m_rep_str_len));
+ save_item(NAME(m_rep_str_ptr));
+ save_item(NAME(m_octal_accum));
+ save_item(NAME(m_fsm_state));
+ save_item(NAME(m_cur_line));
+
+ m_timer = timer_alloc(0);
+}
+
+void hp9845_printer_device::device_reset()
+{
+ state_reset();
+ m_cur_line = 0;
+ m_inten = false;
+ m_ibf = false;
+ m_busy = false;
+ update_flg();
+ m_sts_handler(true);
+}
+
+void hp9845_printer_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
+{
+ m_busy = false;
+ update_fsm();
+ update_flg();
+}
+
+READ16_MEMBER(hp9845_printer_device::printer_r)
+{
+ uint16_t res = 0;
+
+ switch (offset) {
+ case 0:
+ case 1:
+ // Bit 7: Interrupt enabled
+ // Bit 5: 1
+ // Bit 1: Printer powered (1)
+ // Bit 0: Interrupt pending
+ if (m_inten) {
+ BIT_SET(res , 7);
+ }
+ BIT_SET(res , 5);
+ BIT_SET(res , 1);
+ if (m_inten && !m_ibf && !m_busy) {
+ BIT_SET(res , 0);
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ return res;
+}
+
+WRITE16_MEMBER(hp9845_printer_device::printer_w)
+{
+ switch (offset) {
+ case 0:
+ // New character
+ m_ib = (uint8_t)data;
+ m_ibf = true;
+ update_fsm();
+ update_flg();
+ break;
+
+ case 1:
+ // Control word
+ m_inten = BIT(data , 7);
+ update_flg();
+ break;
+
+ default:
+ break;
+ }
+}
+
+void hp9845_printer_device::state_reset()
+{
+ m_display_mode = false;
+ m_shifted = false;
+ m_current_u_l = false;
+ m_current_big = false;
+ memset(m_attrs , 0 , sizeof(m_attrs));
+ memset(m_redef_buff, 0, sizeof(m_redef_buff));
+ m_redef_count = 0;
+ m_replace_count = 0;
+ m_next_replace = REDEF_BUFF_LEN - 1;
+ m_rep_str_len = 0;
+ m_rep_str_ptr = 0;
+ start_new_line();
+ m_fsm_state = FSM_NORMAL_TEXT;
+}
+
+void hp9845_printer_device::insert_char(uint8_t ch)
+{
+ if (m_pos == 80) {
+ crlf();
+ }
+ COPY_BIT(m_current_big , m_attrs[ m_pos ] , ATTRS_BIG_BIT);
+ COPY_BIT(m_current_u_l , m_attrs[ m_pos ] , ATTRS_U_L_BIT);
+ if (ch == '_') {
+ BIT_SET(m_attrs[ m_pos ] , ATTRS_U_L_BIT);
+ } else {
+ m_line[ m_pos ] = ch;
+ // Check for redefined characters
+ unsigned redef_idx;
+ if (is_ch_redef(ch , redef_idx)) {
+ m_attrs[ m_pos ] = (m_attrs[ m_pos ] & ~ATTRS_REDEF_NO_MASK) | (uint8_t)redef_idx | ATTRS_NEW_MASK;
+ } else {
+ BIT_CLR(m_attrs[ m_pos ] , ATTRS_NEW_BIT);
+ }
+ }
+ m_pos++;
+}
+
+void hp9845_printer_device::start_new_line()
+{
+ m_pos = 0;
+ memset(m_line, ' ', sizeof(m_line));
+ for (auto& x : m_attrs) {
+ x &= ~(ATTRS_NEW_MASK | ATTRS_BIG_MASK | ATTRS_U_L_MASK);
+ }
+}
+
+uint8_t hp9845_printer_device::get_ch_matrix_line(const uint8_t *matrix_base , unsigned line_no , const uint8_t *seq)
+{
+ uint8_t res = 0;
+
+ switch (line_no) {
+ case 0:
+ {
+ uint8_t b0 = matrix_base[ seq[ 0 ] ];
+ if (BIT(b0 , 0)) {
+ res = b0 >> 1;
+ }
+ }
+ break;
+
+ case 1:
+ {
+ uint8_t b3 = matrix_base[ seq[ 3 ] ];
+ if (BIT(b3 , 0)) {
+ res = matrix_base[ seq[ 0 ] ] >> 1;
+ }
+ }
+ break;
+
+ case 2:
+ {
+ uint8_t b1 = matrix_base[ seq[ 1 ] ];
+ if (!BIT(b1 , 0)) {
+ res = b1 >> 1;
+ }
+ }
+ break;
+
+ case 3:
+ {
+ uint8_t b2 = matrix_base[ seq[ 2 ] ];
+ if (!BIT(b2 , 0)) {
+ res = b2 >> 1;
+ }
+ }
+ break;
+
+ case 4:
+ case 5:
+ case 6:
+ case 7:
+ case 8:
+ res = matrix_base[ seq[ line_no - 1 ] ] >> 1;
+ break;
+
+ case 9:
+ {
+ uint8_t b1 = matrix_base[ seq[ 1 ] ];
+ if (BIT(b1 , 0)) {
+ res = b1 >> 1;
+ } else {
+ uint8_t b5 = matrix_base[ seq[ 5 ] ];
+ if (BIT(b5 , 0)) {
+ res = matrix_base[ seq[ 0 ] ] >> 1;
+ }
+ }
+ }
+ break;
+
+ case 10:
+ {
+ uint8_t b2 = matrix_base[ seq[ 2 ] ];
+ if (BIT(b2 , 0)) {
+ res = b2 >> 1;
+ } else {
+ uint8_t b6 = matrix_base[ seq[ 6 ] ];
+ if (BIT(b6 , 0)) {
+ res = matrix_base[ seq[ 0 ] ] >> 1;
+ }
+ }
+ }
+ break;
+
+ case 11:
+ {
+ uint8_t b7 = matrix_base[ seq[ 7 ] ];
+ if (BIT(b7 , 0)) {
+ res = matrix_base[ seq[ 0 ] ] >> 1;
+ }
+ }
+ break;
+ }
+
+ return res;
+}
+
+unsigned hp9845_printer_device::print_560_pixels(unsigned line_no , const uint8_t *pixels)
+{
+ std::ostringstream buff;
+ buff << line_no;
+ buff << ':';
+ unsigned pixel_count = 0;
+ for (unsigned i = 0; i < 70; i++) {
+ uint8_t pop_count = pixels[ i ];
+ pop_count = (pop_count & 0x55) + ((pop_count >> 1) & 0x55);
+ pop_count = (pop_count & 0x33) + ((pop_count >> 2) & 0x33);
+ pop_count = (pop_count & 0x0f) + ((pop_count >> 4) & 0x0f);
+ pixel_count += pop_count;
+ for (uint8_t mask = 0x80; mask; mask >>= 1) {
+ buff << ((mask & pixels[ i ]) ? '*' : ' ');
+ }
+ }
+ if (pixel_count) {
+ buff << '\n';
+ std::string out{buff.str()};
+ for (auto c : out) {
+ m_prt_graph_out->output(c);
+ }
+ }
+ LOG("pc=%u\n" , pixel_count);
+ return pixel_count;
+}
+
+static const uint8_t linear_seq[] = { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 };
+static const uint8_t gray_seq[] = { 0 , 1 , 3 , 2 , 6 , 7 , 5 , 4 };
+
+uint8_t hp9845_printer_device::get_ch_pixels(uint8_t ch , uint8_t attrs , unsigned matrix_line) const
+{
+ uint8_t pixels;
+ bool new_ch = BIT(attrs , ATTRS_NEW_BIT);
+ if (new_ch) {
+ const uint8_t *matrix = &m_redef_buff[ (attrs & ATTRS_REDEF_NO_MASK) * 8 ];
+ pixels = get_ch_matrix_line(matrix, matrix_line, linear_seq);
+ } else {
+ const uint8_t *matrix = &m_prt_chargen[ ch * 8 ];
+ pixels = get_ch_matrix_line(matrix, matrix_line, gray_seq);
+ }
+ return pixels;
+}
+
+attotime hp9845_printer_device::burn_time(unsigned pixel_count)
+{
+ if (pixel_count == 0) {
+ return attotime::zero;
+ }
+ unsigned full_burns = pixel_count / MAX_PIXELS_BURNED;
+ unsigned rem_pixels = pixel_count - full_burns * MAX_PIXELS_BURNED;
+ unsigned usec = full_burns * USEC_GE_48_PIXELS;
+ if (rem_pixels < 16) {
+ usec += USEC_LT_16_PIXELS;
+ } else if (rem_pixels < 32) {
+ usec += USEC_LT_32_PIXELS;
+ } else if (rem_pixels < 48) {
+ usec += USEC_LT_48_PIXELS;
+ } else {
+ usec += USEC_GE_48_PIXELS;
+ }
+ return attotime::from_usec(usec);
+}
+
+void hp9845_printer_device::print_line()
+{
+ attotime print_time;
+ bool any_big = false;
+ // Normal-sized character range is [0..22], every other line
+ // Big-sized characters range is [-8..22], one line every 3
+ for (int line_off = -8; line_off < 23; line_off++) {
+ if ((line_off + int(m_cur_line)) < 0) {
+ continue;
+ }
+ bool norm_line = line_off >= 0 && line_off % 2 == 0;
+ bool big_line = (line_off + 8) % 3 == 0;
+
+ if (norm_line || big_line) {
+ uint8_t pixel_line[ 70 ];
+ memset(pixel_line, 0, sizeof(pixel_line));
+
+ unsigned pixel_line_idx = 0;
+ uint8_t pixel_line_mask = 0x80;
+
+ for (unsigned pos = 0; pos < m_pos; pos++) {
+ uint8_t ch = m_line[ pos ];
+ uint8_t attrs = m_attrs[ pos ];
+ uint8_t pixels = 0;
+
+ if (line_off == 22 && BIT(attrs , ATTRS_U_L_BIT)) {
+ // Underline
+ pixels = 0x7f;
+ } else if (BIT(attrs , ATTRS_BIG_BIT) && big_line) {
+ any_big = true;
+ unsigned matrix_line = (line_off + 8) / 3;
+ pixels = get_ch_pixels(ch, attrs, matrix_line);
+ } else if (!BIT(attrs , ATTRS_BIG_BIT) && norm_line) {
+ unsigned matrix_line = line_off / 2;
+ pixels = get_ch_pixels(ch, attrs, matrix_line);
+ }
+ for (uint8_t mask = 0x40; mask; mask >>= 1) {
+ if (pixels & mask) {
+ pixel_line[ pixel_line_idx ] |= pixel_line_mask;
+ }
+ pixel_line_mask >>= 1;
+ if (pixel_line_mask == 0) {
+ pixel_line_mask = 0x80;
+ pixel_line_idx++;
+ }
+ }
+ }
+ unsigned pixel_count = print_560_pixels(unsigned(line_off + int(m_cur_line)) , pixel_line);
+ print_time += burn_time(pixel_count);
+ }
+ }
+ m_cur_line += 24;
+ // Computing an accurate printing time is a lot more complex than this.
+ // This should be a reasonable estimate.
+ if (any_big) {
+ print_time += attotime::from_usec(USEC_1_STEP * 32);
+ } else {
+ print_time += attotime::from_usec(USEC_1_STEP * 24);
+ }
+ LOG("A time=%.6f\n" , print_time.as_double());
+ m_timer->adjust(print_time);
+ m_busy = true;
+}
+
+void hp9845_printer_device::print_graphic_line()
+{
+ unsigned pixel_count = print_560_pixels(m_cur_line , m_line);
+ attotime print_time{burn_time(pixel_count)};
+ print_time += attotime::from_usec(USEC_1_STEP * 2);
+ m_cur_line += 2;
+ LOG("G time=%.6f\n" , print_time.as_double());
+ m_timer->adjust(print_time);
+ m_busy = true;
+}
+
+void hp9845_printer_device::crlf()
+{
+ print_line();
+ start_new_line();
+}
+
+void hp9845_printer_device::set_tab()
+{
+ if (m_pos > 0) {
+ BIT_SET(m_attrs[ m_pos - 1 ] , ATTRS_TAB_BIT);
+ }
+}
+
+void hp9845_printer_device::clear_tabs()
+{
+ for (auto& x : m_attrs) {
+ BIT_CLR(x , ATTRS_TAB_BIT);
+ }
+}
+
+void hp9845_printer_device::move_to_next_tab()
+{
+ for (unsigned i = m_pos; i < 80; i++) {
+ if (BIT(m_attrs[ i ] , ATTRS_TAB_BIT)) {
+ m_pos = i + 1;
+ return;
+ }
+ }
+ crlf();
+}
+
+void hp9845_printer_device::update_flg()
+{
+ m_flg_handler(!m_ibf && !m_busy);
+ m_irl_handler(!m_ibf && !m_busy && m_inten);
+}
+
+bool hp9845_printer_device::is_ch_redef(uint8_t ch , unsigned& redef_number) const
+{
+ for (unsigned i = 0; i < m_redef_count; i++) {
+ if (m_redef_chars[ i ] == ch) {
+ redef_number = i;
+ return true;
+ }
+ }
+ return false;
+}
+
+uint8_t hp9845_printer_device::allocate_ch_redef(uint8_t& idx)
+{
+ if (m_redef_count >= REDEF_CH_COUNT) {
+ idx = REDEF_CH_COUNT - 1;
+ return true;
+ } else if (m_next_replace < 8) {
+ return false;
+ } else {
+ uint8_t max_idx = (m_next_replace - 8) / 8;
+ if (max_idx < m_redef_count) {
+ idx = max_idx;
+ } else {
+ idx = m_redef_count++;
+ }
+ return true;
+ }
+}
+
+bool hp9845_printer_device::is_ch_replaced(uint8_t ch , uint8_t& len , uint8_t& ptr) const
+{
+ uint8_t idx = REDEF_BUFF_LEN - 1;
+ for (unsigned i = 0; i < m_replace_count; i++) {
+ if (m_redef_buff[ idx-- ] == ch) {
+ len = m_redef_buff[ idx-- ];
+ ptr = idx;
+ return true;
+ } else {
+ idx -= (m_redef_buff[ idx ] + 1);
+ }
+ }
+ return false;
+}
+
+uint8_t hp9845_printer_device::free_redef_space() const
+{
+ return m_next_replace - m_redef_count * 8;
+}
+
+uint8_t hp9845_printer_device::apply_shifting(uint8_t ch) const
+{
+ if ((ch & 0x60) == 0 || !m_shifted) {
+ return ch;
+ } else {
+ return ch | 0x80;
+ }
+}
+
+bool hp9845_printer_device::parse_octal(uint8_t ch)
+{
+ if (ch >= '0' && ch <= '7') {
+ m_octal_accum = (m_octal_accum * 8) + (ch - '0');
+ return true;
+ } else {
+ return false;
+ }
+}
+
+bool hp9845_printer_device::parse_ch(uint8_t ch)
+{
+ bool consume = true;
+
+ switch (m_fsm_state) {
+ case FSM_NORMAL_TEXT:
+ if (m_display_mode) {
+ insert_char(apply_shifting(ch));
+ if (ch == CH_CR) {
+ crlf();
+ } else if (ch == CH_ESC) {
+ m_fsm_state = FSM_WAIT_ESC_Z;
+ }
+ } else {
+ switch (ch) {
+ case CH_BS:
+ if (m_pos > 0) {
+ m_pos--;
+ }
+ break;
+
+ case CH_TAB:
+ move_to_next_tab();
+ break;
+
+ case CH_LF:
+ {
+ auto save_pos = m_pos;
+ crlf();
+ m_pos = save_pos;
+ }
+ break;
+
+ case CH_CR:
+ m_fsm_state = FSM_AFTER_CR;
+ break;
+
+ case CH_SH_OUT:
+ m_shifted = true;
+ break;
+
+ case CH_SH_IN:
+ m_shifted = false;
+ break;
+
+ case CH_ESC:
+ m_fsm_state = FSM_AFTER_ESC;
+ break;
+
+ default:
+ if ((ch & 0xe4) == 0x80) {
+ m_current_u_l = false;
+ } else if ((ch & 0xe4) == 0x84) {
+ m_current_u_l = true;
+ } else if ((ch & 0x60) != 0) {
+ insert_char(apply_shifting(ch));
+ }
+ break;
+ }
+ }
+ break;
+
+ case FSM_AFTER_CR:
+ if (ch == CH_LF) {
+ // CR + LF sequence
+ crlf();
+ } else {
+ // CR + something not LF
+ auto save_cur_line = m_cur_line;
+ crlf();
+ m_cur_line = save_cur_line;
+ // Ch is pushed back for next iteration of FSM
+ consume = false;
+ }
+ m_fsm_state = FSM_NORMAL_TEXT;
+ break;
+
+ case FSM_AFTER_ESC:
+ m_fsm_state = FSM_NORMAL_TEXT;
+ switch (ch) {
+ case '1':
+ set_tab();
+ break;
+
+ case '3':
+ clear_tabs();
+ break;
+
+ case 'E':
+ LOG("State reset\n");
+ state_reset();
+ break;
+
+ case 'Y':
+ m_display_mode = true;
+ break;
+
+ case '&':
+ m_fsm_state = FSM_AFTER_ESC_AMP;
+ break;
+
+ case '?':
+ if (m_pos > 0) {
+ crlf();
+ }
+ m_pos = 0;
+ m_fsm_state = FSM_COLLECT_ESC_QMARK;
+ break;
+
+ default:
+ // Unknown ESC sequence
+ break;
+ }
+ break;
+
+ case FSM_AFTER_ESC_AMP:
+ switch (ch) {
+ case 'd':
+ m_fsm_state = FSM_AFTER_ESC_AMP_D;
+ break;
+
+ case 'k':
+ m_fsm_state = FSM_AFTER_ESC_AMP_K;
+ break;
+
+ case 'l':
+ m_fsm_state = FSM_AFTER_ESC_AMP_L;
+ m_octal_accum = 0;
+ break;
+
+ case 'n':
+ m_fsm_state = FSM_AFTER_ESC_AMP_N;
+ m_octal_accum = 0;
+ break;
+
+ case 'o':
+ m_fsm_state = FSM_AFTER_ESC_AMP_O;
+ m_octal_accum = 0;
+ break;
+
+ default:
+ // Unknown ESC & sequence
+ m_fsm_state = FSM_NORMAL_TEXT;
+ break;
+ }
+ break;
+
+ case FSM_COLLECT_ESC_QMARK:
+ m_line[ m_pos++ ] = ch;
+ if (m_pos == 70) {
+ print_graphic_line();
+ start_new_line();
+ m_fsm_state = FSM_NORMAL_TEXT;
+ }
+ break;
+
+ case FSM_AFTER_ESC_AMP_K:
+ switch (ch) {
+ case '0':
+ case '1':
+ m_octal_accum = ch != '0';
+ m_fsm_state = FSM_AFTER_ESC_AMP_K_01;
+ break;
+
+ default:
+ m_fsm_state = FSM_NORMAL_TEXT;
+ break;
+ }
+ break;
+
+ case FSM_AFTER_ESC_AMP_K_01:
+ if (ch == 'S') {
+ m_current_big = m_octal_accum;
+ }
+ m_fsm_state = FSM_NORMAL_TEXT;
+ break;
+
+ case FSM_AFTER_ESC_AMP_D:
+ switch (ch) {
+ case 'D':
+ case 'E':
+ case 'F':
+ case 'G':
+ case 'L':
+ case 'M':
+ case 'N':
+ case 'O':
+ m_current_u_l = true;
+ break;
+
+ case '@':
+ case 'A':
+ case 'B':
+ case 'C':
+ case 'H':
+ case 'I':
+ case 'J':
+ case 'K':
+ m_current_u_l = false;
+ break;
+
+ default:
+ break;
+ }
+ m_fsm_state = FSM_NORMAL_TEXT;
+ break;
+
+ case FSM_AFTER_ESC_AMP_N:
+ if (!parse_octal(ch)) {
+ if (ch == 'c') {
+ unsigned dummy;
+ if (is_ch_redef(m_octal_accum, dummy) || !allocate_ch_redef(m_redef_idx)) {
+ // Character redefined twice or space exhausted
+ m_redef_idx = 0xff;
+ }
+ LOG("Redef ch %02x @%u\n" , m_octal_accum , m_redef_idx);
+ if (m_redef_idx < REDEF_CH_COUNT) {
+ m_redef_chars[ m_redef_idx ] = m_octal_accum;
+ }
+ m_octal_accum = 0;
+ m_fsm_state = FSM_AFTER_ESC_AMP_N_C;
+ } else {
+ m_fsm_state = FSM_NORMAL_TEXT;
+ }
+ }
+ break;
+
+ case FSM_AFTER_ESC_AMP_O:
+ if (!parse_octal(ch)) {
+ if (ch == 'c') {
+ uint8_t dummy1;
+ uint8_t dummy2;
+ if (is_ch_replaced(m_octal_accum, dummy1, dummy2) || free_redef_space() < 2) {
+ // Character replaced twice or space exhausted
+ m_redef_idx = 0xff;
+ } else {
+ m_redef_idx = m_next_replace;
+ m_redef_buff[ m_redef_idx-- ] = m_octal_accum;
+ m_redef_buff[ m_redef_idx ] = 0;
+ m_next_replace -= 2;
+ m_replace_count++;
+ }
+ m_octal_accum = 0;
+ m_fsm_state = FSM_AFTER_ESC_AMP_O_C;
+ } else {
+ m_fsm_state = FSM_NORMAL_TEXT;
+ }
+ }
+ break;
+
+ case FSM_AFTER_ESC_AMP_O_C:
+ if (!parse_octal(ch)) {
+ if (ch == 'L') {
+ if (m_redef_idx < REDEF_BUFF_LEN) {
+ uint8_t max_len = std::min(m_octal_accum , free_redef_space());
+ m_next_replace -= max_len;
+ m_redef_buff[ m_redef_idx-- ] = max_len;
+ LOG("Repl ch %02x with str @%u, len=%u\n" , m_redef_buff[ m_redef_idx + 2 ] , m_redef_idx , max_len);
+ }
+ if (m_octal_accum) {
+ m_fsm_state = FSM_AFTER_ESC_AMP_O_C_L;
+ } else {
+ m_fsm_state = FSM_NORMAL_TEXT;
+ }
+ } else {
+ m_fsm_state = FSM_NORMAL_TEXT;
+ }
+ }
+ break;
+
+ case FSM_AFTER_ESC_AMP_O_C_L:
+ if (m_redef_idx < REDEF_BUFF_LEN && m_redef_idx >= m_next_replace) {
+ m_redef_buff[ m_redef_idx-- ] = ch;
+ }
+ if (--m_octal_accum == 0) {
+ m_fsm_state = FSM_NORMAL_TEXT;
+ }
+ break;
+
+ case FSM_AFTER_ESC_AMP_L:
+ if (!parse_octal(ch)) {
+ // TODO: ESC & l <octal> [ST]
+ m_fsm_state = FSM_NORMAL_TEXT;
+ }
+ break;
+
+ case FSM_AFTER_ESC_AMP_N_C:
+ if (!parse_octal(ch)) {
+ if (ch >= 'p' && ch <= 'w') {
+ if (m_redef_idx < REDEF_CH_COUNT) {
+ m_redef_buff[ m_redef_idx * 8 + ch - 'p' ] = m_octal_accum;
+ }
+ m_octal_accum = 0;
+ } else if (ch >= 'P' && ch <= 'W') {
+ if (m_redef_idx < REDEF_CH_COUNT) {
+ m_redef_buff[ m_redef_idx * 8 + ch - 'P' ] = m_octal_accum;
+ }
+ m_fsm_state = FSM_NORMAL_TEXT;
+ } else {
+ m_fsm_state = FSM_NORMAL_TEXT;
+ }
+ }
+ break;
+
+ case FSM_WAIT_ESC_Z:
+ insert_char(ch);
+ if (ch == 'Z') {
+ m_display_mode = false;
+ m_fsm_state = FSM_NORMAL_TEXT;
+ } else if (ch != CH_ESC) {
+ m_fsm_state = FSM_NORMAL_TEXT;
+ }
+ break;
+ }
+ return consume;
+}
+
+void hp9845_printer_device::update_fsm()
+{
+ while (!m_busy && m_ibf) {
+ bool consume = false;
+ if (m_rep_str_len != 0) {
+ consume = parse_ch(m_redef_buff[ m_rep_str_ptr ]);
+ } else if ((m_fsm_state == FSM_NORMAL_TEXT || m_fsm_state == FSM_AFTER_CR || m_fsm_state == FSM_COLLECT_ESC_QMARK) &&
+ is_ch_replaced(apply_shifting(m_ib), m_rep_str_len, m_rep_str_ptr)) {
+ LOG("Subst ch %02x with str @%u (len = %u)\n" , m_ib , m_rep_str_ptr , m_rep_str_len);
+ if (m_rep_str_len == 0) {
+ consume = true;
+ }
+ } else {
+ consume = parse_ch(m_ib);
+ }
+ if (consume) {
+ if (m_rep_str_len) {
+ m_rep_str_len--;
+ m_rep_str_ptr--;
+ }
+ if (m_rep_str_len == 0) {
+ m_prt_alpha_out->output(m_ib);
+ m_ibf = false;
+ update_flg();
+ }
+ }
+ }
+}
diff --git a/src/mame/machine/hp9845_printer.h b/src/mame/machine/hp9845_printer.h
new file mode 100644
index 00000000000..db88d87f2c7
--- /dev/null
+++ b/src/mame/machine/hp9845_printer.h
@@ -0,0 +1,134 @@
+// license:BSD-3-Clause
+// copyright-holders:F. Ulivi
+/*********************************************************************
+
+ hp9845_printer.h
+
+ HP9845 internal printer HLE
+
+*********************************************************************/
+
+#ifndef MAME_MACHINE_HP9845_PRINTER_H
+#define MAME_MACHINE_HP9845_PRINTER_H
+
+#pragma once
+
+#include "imagedev/bitbngr.h"
+
+#define MCFG_9845PRT_IRL_HANDLER(_devcb) \
+ devcb = &hp9845_printer_device::set_irl_handler(*device , DEVCB_##_devcb);
+
+#define MCFG_9845PRT_FLG_HANDLER(_devcb) \
+ devcb = &hp9845_printer_device::set_flg_handler(*device , DEVCB_##_devcb);
+
+#define MCFG_9845PRT_STS_HANDLER(_devcb) \
+ devcb = &hp9845_printer_device::set_sts_handler(*device , DEVCB_##_devcb);
+
+class hp9845_printer_device : public device_t
+{
+public:
+ // construction/destruction
+ hp9845_printer_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
+
+ // static configuration helpers
+ template <class Object> static devcb_base &set_irl_handler(device_t &device, Object &&cb) { return downcast<hp9845_printer_device &>(device).m_irl_handler.set_callback(std::forward<Object>(cb)); }
+ template <class Object> static devcb_base &set_flg_handler(device_t &device, Object &&cb) { return downcast<hp9845_printer_device &>(device).m_flg_handler.set_callback(std::forward<Object>(cb)); }
+ template <class Object> static devcb_base &set_sts_handler(device_t &device, Object &&cb) { return downcast<hp9845_printer_device &>(device).m_sts_handler.set_callback(std::forward<Object>(cb)); }
+
+ // device-level overrides
+ virtual const tiny_rom_entry *device_rom_region() const override;
+ virtual void device_add_mconfig(machine_config &config) override;
+ virtual void device_start() override;
+ virtual void device_reset() override;
+ virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override;
+
+ // PPU access
+ DECLARE_READ16_MEMBER(printer_r);
+ DECLARE_WRITE16_MEMBER(printer_w);
+
+private:
+ devcb_write_line m_irl_handler;
+ devcb_write_line m_flg_handler;
+ devcb_write_line m_sts_handler;
+
+ required_device<bitbanger_device> m_prt_graph_out;
+ required_device<bitbanger_device> m_prt_alpha_out;
+ required_region_ptr<uint8_t> m_prt_chargen;
+
+ emu_timer *m_timer;
+
+ // Size of various buffers
+ static constexpr unsigned REDEF_CH_COUNT = 9;
+ static constexpr unsigned REDEF_BUFF_LEN = 77;
+
+ // State
+ bool m_display_mode;
+ bool m_shifted;
+ bool m_current_u_l;
+ bool m_current_big;
+ bool m_ibf;
+ bool m_inten;
+ bool m_busy;
+ uint8_t m_ib;
+ uint8_t m_pos;
+ uint8_t m_line[ 80 ];
+ uint8_t m_attrs[ 80 ];
+ uint8_t m_redef_count;
+ uint8_t m_redef_idx;
+ uint8_t m_redef_chars[ REDEF_CH_COUNT ];
+ uint8_t m_replace_count;
+ uint8_t m_redef_buff[ REDEF_BUFF_LEN ];
+ uint8_t m_next_replace;
+ uint8_t m_rep_str_len;
+ uint8_t m_rep_str_ptr;
+ uint8_t m_octal_accum;
+ int m_fsm_state;
+ unsigned m_cur_line;
+
+ // FSM states
+ enum {
+ FSM_NORMAL_TEXT,
+ FSM_AFTER_CR,
+ FSM_AFTER_ESC,
+ FSM_AFTER_ESC_AMP,
+ FSM_COLLECT_ESC_QMARK,
+ FSM_AFTER_ESC_AMP_K,
+ FSM_AFTER_ESC_AMP_K_01,
+ FSM_AFTER_ESC_AMP_D,
+ FSM_AFTER_ESC_AMP_N,
+ FSM_AFTER_ESC_AMP_O,
+ FSM_AFTER_ESC_AMP_O_C,
+ FSM_AFTER_ESC_AMP_O_C_L,
+ FSM_AFTER_ESC_AMP_L,
+ FSM_AFTER_ESC_AMP_N_C,
+ FSM_WAIT_ESC_Z
+ };
+
+ void state_reset();
+ void insert_char(uint8_t ch);
+ void start_new_line();
+ static uint8_t get_ch_matrix_line(const uint8_t *matrix_base , unsigned line_no , const uint8_t *seq);
+ unsigned print_560_pixels(unsigned line_no , const uint8_t *pixels);
+ uint8_t get_ch_pixels(uint8_t ch , uint8_t attrs , unsigned matrix_line) const;
+ static attotime burn_time(unsigned pixel_count);
+ void print_line();
+ void print_graphic_line();
+ void crlf();
+ void set_tab();
+ void clear_tabs();
+ void move_to_next_tab();
+ void update_flg();
+ bool is_ch_redef(uint8_t ch , unsigned& redef_number) const;
+ uint8_t allocate_ch_redef(uint8_t& idx);
+ bool is_ch_replaced(uint8_t ch , uint8_t& len , uint8_t& ptr) const;
+ uint8_t free_redef_space() const;
+ uint8_t apply_shifting(uint8_t ch) const;
+ bool parse_octal(uint8_t ch);
+ bool parse_ch(uint8_t ch);
+ void update_fsm();
+};
+
+// device type definition
+DECLARE_DEVICE_TYPE(HP9845_PRINTER, hp9845_printer_device)
+
+#endif // MAME_MACHINE_HP9845_PRINTER_H
diff --git a/src/mame/machine/igs025.cpp b/src/mame/machine/igs025.cpp
index c1e1b3d83e9..81affda9c95 100644
--- a/src/mame/machine/igs025.cpp
+++ b/src/mame/machine/igs025.cpp
@@ -254,7 +254,7 @@ READ16_MEMBER(igs025_device::killbld_igs025_prot_r)
switch (m_kb_cmd)
{
case 0x00:
- return BITSWAP8((m_kb_swap + 1) & 0x7f, 0, 1, 2, 3, 4, 5, 6, 7); // drgw3
+ return bitswap<8>((m_kb_swap + 1) & 0x7f, 0, 1, 2, 3, 4, 5, 6, 7); // drgw3
case 0x01:
return m_kb_reg & 0x7f;
@@ -282,7 +282,7 @@ READ16_MEMBER(igs025_device::killbld_igs025_prot_r)
return 0x3f00 | ((m_kb_game_id >> 24) & 0xff);
default: // >= 5
- return 0x3f00 | BITSWAP8(m_kb_prot_hold, 5, 2, 9, 7, 10, 13, 12, 15);
+ return 0x3f00 | bitswap<8>(m_kb_prot_hold, 5, 2, 9, 7, 10, 13, 12, 15);
}
}
diff --git a/src/mame/machine/igs036crypt.cpp b/src/mame/machine/igs036crypt.cpp
index cc88b85273e..3d1255396b4 100644
--- a/src/mame/machine/igs036crypt.cpp
+++ b/src/mame/machine/igs036crypt.cpp
@@ -15,13 +15,13 @@ The scheme works on 16-bits words and is probably designed to depend on 24 bits
(word-) address; in what follows, we will refer to the 8 lowest ones simply as the
lowest bits of the address, and the other 16 as the highest bits the address.
-The address-based XOR is thought to be comprised of 16 one-bit XOR controlled
-by a certain combination of one or two of the highest address bits (but only
-15 of them are observed, probably due to the fact that no game uses more than
-2^22 of the 2^24 address space). Every one of the one-bit XORs affects a different bit
-of the word. The game key acts by masking on/off those XORs for every combination
-of the lowest address bits. Thus, a complete key can be described by 256 16-bits values.
-This use of the key is pretty similar to the one found in previous instantiations of
+The address-based XOR can be thought as 16 one-bit XORs against key bits
+controlled by certain combinations of up to three address bits. The game key is
+comprised of 256 8-bits values provided by the internal ARM; every 8-bit value
+in the key is used on those words whose address match the index modulus 256;
+in a given key byte, every bit affects two positions of the correponding 16-bits
+encrypted words.
+This use of the key is similar to the one found in previous instantiations of
IGS circuits.
What is new in the IGS036 is the use of an obfuscation working this way:
@@ -39,12 +39,11 @@ three by inverting (when active itself) the activation/deactivation patterns of
the other three.
5) The lowest bits of the address control a further rotation(independent
on the highest bits of the address).
-6) Besides, a global bitswap is present (which can be considered either part of the
-obfuscation or of the encryption, as is done in the interface between both).
+6) Finally, a global bitswap is applied.
All the associated boolean functions are clearly of low complexity, so it should
be expected that the hardware is calculating them that way rather than using
-lookup tables or otherwise. It must be stressed that this obfuscation is done
+lookup tables or otherwise. It should be stressed that this obfuscation is done
system-wide without dependence on the game keys.
On a different note, the unused tail of the ROMs are pattern-filled and, more interestingly,
@@ -56,12 +55,13 @@ driver 20-bytes value position in the ROM
orleg2o $763984-$763997
orleg2 $76C77C-$76C78F
kov3 $718040-$718053
+kof98umh $E50E60-$E50E73
TO-DO: complete the table with the 20-bytes values
*****************************************************************************/
-igs036_decryptor::igs036_decryptor(const uint16_t* game_key)
+igs036_decryptor::igs036_decryptor(const uint8_t* game_key)
: key(game_key)
{
}
@@ -84,14 +84,13 @@ uint16_t igs036_decryptor::decrypt(uint16_t cipherword, int word_address)const
// key-dependent manipulation
for (int i=0; i<16; ++i)
{
- if (BIT(key[word_address&0xff],i))
- {
- if (((word_address>>8)&triggers[i][0]) == triggers[i][1])
- aux ^= (1<<i);
- }
+ if ((word_address&triggers[i][0]) == triggers[i][1])
+ aux ^= BIT(key[word_address&0xff],i&7) << i;
+ else
+ aux ^= BIT(0x1a3a, i) << i;
}
-
- return aux^0x1a3a;
+
+ return aux;
}
uint16_t igs036_decryptor::deobfuscate(uint16_t cipherword, int word_address)const
@@ -99,7 +98,7 @@ uint16_t igs036_decryptor::deobfuscate(uint16_t cipherword, int word_address)con
// key-independent manipulation
int shift = rotation(word_address);
int aux = rol(cipherword, shift);
- aux = BITSWAP16(aux, 10,9,8,7,0,15,6,5, 14,13,4,3,12,11,2,1);
+ aux = bitswap<16>(aux, 10,9,8,7,0,15,6,5, 14,13,4,3,12,11,2,1);
return aux;
}
@@ -107,7 +106,7 @@ uint16_t igs036_decryptor::deobfuscate(uint16_t cipherword, int word_address)con
int igs036_decryptor::rotation(int address)const
{
const int group15[] = {15,11, 7, 5}; // 15 is a guess
- const int group14[] = {14, 9, 3, 2}; // 14 is a guess
+ const int group14[] = {14, 9, 3, 2};
const int group13[] = {13,10, 6, 1};
const int group12[] = {12, 8, 4, 0};
@@ -166,11 +165,11 @@ uint16_t igs036_decryptor::rol(uint16_t num, int shift)const
// the triggers describe under what conditions are every one of the 16 XORs activated
-const uint16_t igs036_decryptor::triggers[16][2] = {
- {0x0001, 0x0000}, {0x0008, 0x0008}, {0x0002, 0x0000}, {0x0004, 0x0004},
- {0x0100, 0x0000}, {0x0200, 0x0000}, {0x0400, 0x0000}, {0x0800, 0x0800},
- {0x1001, 0x0001}, {0x2002, 0x2000}, {0x4004, 0x4000}, {0x8008, 0x0000}, // (the one at index #10 is a guess; his effect is not observed in any game)
- {0x0010, 0x0010}, {0x0020, 0x0020}, {0x0040, 0x0000}, {0x0081, 0x0081}
+const uint32_t igs036_decryptor::triggers[16][2] = {
+ {0x000101, 0x000001}, {0x000802, 0x000800}, {0x000204, 0x000004}, {0x000408, 0x000408},
+ {0x010010, 0x000010}, {0x020020, 0x000020}, {0x040040, 0x000040}, {0x080080, 0x080080},
+ {0x100100, 0x000100}, {0x200200, 0x200000}, {0x400400, 0x400000}, {0x800801, 0x000001},
+ {0x001004, 0x001000}, {0x002010, 0x002000}, {0x004040, 0x000040}, {0x008100, 0x008100}
};
@@ -217,7 +216,7 @@ int (*igs036_decryptor::rot_enabling[16][4])(int) = {
{nor_34 , bit_7 , not_7 , cOne },
{bit_3 , not_3 , bit_3 , not_3 },
{cZero , cOne , cOne , cZero },
- {unknown, unknown, unknown, unknown},
+ {bit_4 , not_4 , bit_4 , not_4 },
{unknown, unknown, unknown, unknown},
};
@@ -233,294 +232,104 @@ int (*igs036_decryptor::rot_direction[4][8])(int) = {
// The keys below have been obtained by an automatic process
// exploiting the simple XOR scheme used by the system. Overall, the process,
// while simple, seems to be pretty robust, so few errors should be expected,
-// if any. The only exception is DDPDOJ (see below).
-
-const uint16_t orleg2_key[0x100] = {
- 0x8100, 0x9202, 0x3000, 0x1200, 0x0100, 0x0800, 0x2100, 0xab05,
- 0x130a, 0xba0a, 0x0308, 0x9200, 0x8306, 0xab0f, 0x200c, 0x0301,
- 0x9010, 0x1b13, 0x1310, 0x1b11, 0x8104, 0x0212, 0x8204, 0x8214,
- 0x8302, 0x1111, 0x8300, 0x1b19, 0x0110, 0x8202, 0x0310, 0x0301,
- 0x8322, 0xb202, 0xb200, 0x9121, 0x8222, 0x0a26, 0x2000, 0x0321,
- 0xb000, 0x0020, 0x9328, 0x3909, 0x230a, 0x8929, 0x8224, 0x2204,
- 0x0322, 0x9b33, 0x0300, 0x9311, 0x8120, 0x8810, 0x0330, 0x0004,
- 0x832a, 0x8a0a, 0x0100, 0x1131, 0x0138, 0x093d, 0x8128, 0x081c,
- 0xe342, 0x8101, 0xf140, 0x0000, 0x6144, 0x2004, 0x8204, 0x4044,
- 0xa302, 0xdb4b, 0x1000, 0xa200, 0xc044, 0xe044, 0x010c, 0x0204,
- 0x1212, 0xdb53, 0xd050, 0xcb41, 0x4150, 0xc347, 0x4340, 0x0101,
- 0x5252, 0xd959, 0x1310, 0xc040, 0xc252, 0xc959, 0x4340, 0x8919,
- 0x2202, 0x3800, 0xe340, 0x2101, 0x0326, 0x2307, 0x4360, 0x8321,
- 0x3000, 0xbb0b, 0x5068, 0xf848, 0x436a, 0xab0b, 0xa10c, 0xe240,
- 0xc140, 0xc363, 0x8300, 0x4961, 0x0004, 0xc860, 0x0324, 0x0000,
- 0xd070, 0x8101, 0xd070, 0x1331, 0x0104, 0x4a6e, 0x4348, 0x4a78,
- 0xa282, 0xb282, 0x0200, 0x2200, 0x8180, 0x8080, 0x8080, 0x0800,
- 0x1302, 0x9989, 0x2008, 0x2000, 0xa386, 0x0b0f, 0x828c, 0xa280,
- 0x9392, 0x9292, 0x1010, 0x8080, 0x0206, 0x8383, 0x8294, 0x0911,
- 0x8382, 0x0a0a, 0x9190, 0x1010, 0x0008, 0x0b0b, 0x8098, 0x8b9d,
- 0x1120, 0x0820, 0x2200, 0xa080, 0x81a4, 0xa286, 0xa380, 0xaa80,
- 0x0120, 0x1020, 0xb088, 0x1020, 0x2000, 0x0b2b, 0x2100, 0x2a0c,
- 0x9292, 0x98b0, 0x1330, 0x8880, 0x8396, 0x0b17, 0x8080, 0x0325,
- 0x0000, 0x99b9, 0x92b0, 0x82a0, 0x8184, 0x0020, 0x0330, 0x0818,
- 0xe1c0, 0xa981, 0xd1c0, 0xd0c0, 0x6140, 0x4242, 0xc2c4, 0x6345,
- 0xb088, 0x7141, 0x4040, 0xa181, 0x220e, 0xe0c4, 0x4144, 0x6a4c,
- 0xd0d0, 0x9a92, 0x1310, 0xd9d1, 0x8392, 0xc0c4, 0x8284, 0x8890,
- 0xc0c0, 0x8282, 0x8280, 0x9090, 0x4342, 0x0a0a, 0x4240, 0xc1d5,
- 0xb080, 0xb282, 0xc1e0, 0x90a0, 0xa084, 0x4b63, 0x81a0, 0xeac0,
- 0x7242, 0x5363, 0x7348, 0x0321, 0x022a, 0x6949, 0x4360, 0x8aa8,
- 0x8282, 0x0303, 0x8180, 0x1331, 0x83a2, 0x4b53, 0x4364, 0x83b1,
- 0x121a, 0x80a0, 0x1238, 0x0000, 0x82ba, 0x0030, 0xc0c0, 0x4264,
-};
-
-const uint16_t m312cn_key[0x100] = {
- 0x1102, 0x1103, 0x1000, 0xb101, 0x2100, 0x2802, 0xa000, 0x0901,
- 0x000a, 0x8101, 0xa000, 0x2909, 0x000e, 0x2004, 0x210c, 0x2909,
- 0x8000, 0x0903, 0x0100, 0x8901, 0x0100, 0x8814, 0x8110, 0x0810,
- 0x0002, 0x9010, 0x9110, 0x8000, 0x000a, 0x0115, 0x0108, 0x8919,
- 0xb000, 0x8022, 0x2000, 0xa000, 0x0024, 0xa101, 0x0020, 0x0121,
- 0x0020, 0xb80a, 0x0128, 0x9828, 0x802e, 0x882a, 0x8020, 0xa90d,
- 0x9130, 0x8802, 0x8000, 0x9111, 0x0102, 0x0935, 0x8110, 0x0830,
- 0x002a, 0x1919, 0x9130, 0x8808, 0x0110, 0x0030, 0x811c, 0x8919,
- 0x1000, 0x6141, 0x0000, 0xd941, 0x0104, 0x0006, 0x4140, 0xa804,
- 0x810a, 0x890b, 0x8100, 0xb000, 0x8008, 0xc040, 0x2004, 0x6040,
- 0x5150, 0x4943, 0x1010, 0xd151, 0x4040, 0x8111, 0x4044, 0x4945,
- 0x9012, 0xd959, 0x9118, 0x0000, 0x8116, 0x494b, 0x801c, 0x0010,
- 0xd162, 0x0121, 0x3000, 0x4060, 0x0124, 0x8826, 0xa100, 0xc064,
- 0xa000, 0xe040, 0xb100, 0x7040, 0xe040, 0x2006, 0x2004, 0x694d,
- 0x1032, 0x0901, 0x4160, 0xc961, 0x4174, 0x8022, 0x8120, 0x4850,
- 0x1110, 0x8121, 0x1110, 0x9838, 0xc156, 0x4171, 0x0020, 0x883c,
- 0xb082, 0xa183, 0x9080, 0x1101, 0x2104, 0x0103, 0xa080, 0xa181,
- 0x300a, 0x2000, 0x9180, 0x1000, 0x808e, 0x8187, 0x0100, 0x8185,
- 0x9190, 0x9090, 0x8080, 0x0901, 0x0002, 0x0002, 0x0014, 0x8884,
- 0x9198, 0x9193, 0x9190, 0x8888, 0x0006, 0x8888, 0x8180, 0x090d,
- 0x1020, 0x3101, 0x1020, 0x1820, 0x0024, 0x2907, 0xa080, 0xa181,
- 0xb082, 0x0828, 0x0128, 0x80a0, 0x210a, 0x290d, 0x0128, 0x2000,
- 0x9190, 0x88a0, 0x0100, 0x8880, 0x80a6, 0x0820, 0x0000, 0x81a1,
- 0x80aa, 0x989a, 0x90b0, 0x1010, 0x80a0, 0x8181, 0x8094, 0x0024,
- 0x5142, 0x3101, 0x8080, 0xa880, 0x4046, 0xe8c2, 0x0000, 0x6145,
- 0x714a, 0x280a, 0x5040, 0x0909, 0x614a, 0x4145, 0x2004, 0xa88c,
- 0x4040, 0x1812, 0xd0d0, 0x9191, 0x4140, 0x8195, 0x8180, 0x4155,
- 0x4140, 0x191b, 0x0000, 0x8181, 0xc0dc, 0x091b, 0x0118, 0x0111,
- 0x5060, 0x1123, 0xe0c0, 0x7840, 0x80a0, 0x4963, 0x2000, 0xc8e4,
- 0x80aa, 0x3000, 0xe0c0, 0x1121, 0x6046, 0xa88a, 0x4164, 0x0929,
- 0x9092, 0x4961, 0xc0c0, 0x8181, 0x4074, 0x88a4, 0x0110, 0x0810,
- 0xc0e2, 0xc0c0, 0x0028, 0x9191, 0x80b2, 0x0020, 0x4040, 0x80b0,
-};
-
-const uint16_t cjddzsp_key[0x100] = {
- 0x0142, 0x3903, 0xb0c0, 0x0040, 0x8006, 0xa145, 0x2004, 0x0141,
- 0x21c0, 0xa1c1, 0x0048, 0x8141, 0x8182, 0x884a, 0x2184, 0x0040,
- 0x8102, 0x98d2, 0x8180, 0x8941, 0x80d2, 0x0151, 0x01c0, 0x8901,
- 0x1090, 0x98d8, 0x9010, 0x0808, 0x0148, 0x095f, 0x804c, 0x090d,
- 0x9122, 0xa9c3, 0xa180, 0xb101, 0x00e4, 0x2000, 0x81e4, 0x8921,
- 0x2188, 0x89a9, 0x0128, 0x9020, 0x2042, 0xa002, 0x016c, 0x8121,
- 0x01e2, 0x9991, 0x8040, 0x9810, 0x0190, 0x0925, 0x01a4, 0x88c4,
- 0x0148, 0x9193, 0x91d8, 0x19d9, 0x801a, 0x8919, 0x8120, 0x81c1,
- 0x20c2, 0xf0c2, 0xd100, 0x28c0, 0xe0c4, 0xe880, 0xa080, 0x6985,
- 0xe100, 0x9042, 0xa1c8, 0x18c8, 0x6146, 0x80c2, 0x604c, 0x09cd,
- 0x8180, 0x4002, 0x0000, 0x4880, 0x4100, 0x00c2, 0x8040, 0xc8d4,
- 0x5152, 0x5113, 0xd1d8, 0x1090, 0xc19a, 0x4191, 0x80d8, 0xc0c0,
- 0xc0e0, 0x6901, 0xd060, 0x00a0, 0x0062, 0x81a3, 0x6004, 0xe1c1,
- 0x6042, 0x496b, 0x40e0, 0x78c8, 0xe188, 0xe0c4, 0x40a8, 0x81a5,
- 0x1070, 0x9913, 0x91d0, 0x0080, 0x4172, 0x48f6, 0x8120, 0x8961,
- 0x51b8, 0xc060, 0x9058, 0xd939, 0x41d2, 0xc9ff, 0x8188, 0xc80c,
- 0x81c2, 0x1802, 0xb040, 0x2840, 0x2006, 0x80c2, 0x8184, 0xa1c1,
- 0x10c8, 0x30c2, 0x3040, 0x91c1, 0x810c, 0xa1c1, 0x2180, 0x81c1,
- 0x0100, 0x18d0, 0x1190, 0x80c0, 0x8046, 0x0941, 0x8154, 0x0111,
- 0x0080, 0x8042, 0x1118, 0x0101, 0x004a, 0x89db, 0x0040, 0x8185,
- 0x91a2, 0xb143, 0x11a0, 0x2000, 0x01e6, 0x0824, 0x21c4, 0xa181,
- 0x2180, 0xb002, 0x90a0, 0xb181, 0xa1c4, 0x0020, 0xa0c0, 0x2105,
- 0x01c2, 0x0183, 0x0040, 0x0000, 0x8132, 0x8185, 0x01b4, 0x8975,
- 0x91f2, 0x8022, 0x9058, 0x18d8, 0x0128, 0x889e, 0x808c, 0x00f4,
- 0x11c0, 0xe840, 0x1140, 0x6981, 0x41c4, 0x00c6, 0x60c4, 0x6884,
- 0xa0c8, 0x3143, 0x7180, 0x00c0, 0xa188, 0xc909, 0x4140, 0xa84c,
- 0x51d2, 0x0842, 0x8080, 0x9151, 0x81c0, 0x4084, 0x0144, 0x8915,
- 0x111a, 0x4103, 0x8000, 0x48c8, 0x01de, 0x00c0, 0xc004, 0xc044,
- 0xb100, 0xf983, 0x5060, 0x61c1, 0xe180, 0x2880, 0xe080, 0x8925,
- 0x90aa, 0xf8ca, 0xe148, 0x3989, 0x6080, 0x8024, 0x6184, 0x61c5,
- 0xc0a0, 0x0020, 0x5190, 0x9111, 0x8180, 0x01b3, 0xc0e4, 0xc191,
- 0x4082, 0xd9d9, 0x5110, 0x4000, 0xc164, 0x41c7, 0xc050, 0xc9bd,
-};
-
-const uint16_t cjdh2_key[0x100] = {
- 0x1180, 0x2983, 0x8080, 0x3981, 0x2182, 0x2181, 0x2100, 0x2901,
- 0x2182, 0x198b, 0xa008, 0x8181, 0x0106, 0xa000, 0x018c, 0x880c,
- 0x1110, 0x8101, 0x1190, 0x9890, 0x8090, 0x0812, 0x8014, 0x0111,
- 0x909a, 0x8808, 0x8000, 0x0101, 0x811a, 0x8000, 0x8088, 0x8195,
- 0x9120, 0x9123, 0x90a0, 0x1020, 0x00a0, 0x0125, 0x8120, 0xa985,
- 0x90aa, 0x2808, 0xa180, 0x1828, 0x81a4, 0xa808, 0xa080, 0x00a4,
- 0x9032, 0x0820, 0x1110, 0x8101, 0x8034, 0x8103, 0x8100, 0x01a1,
- 0x01a2, 0x8002, 0x81a8, 0x1818, 0x0092, 0x8127, 0x8184, 0x8888,
- 0xb102, 0xa802, 0x7140, 0xb000, 0x8102, 0x8000, 0x41c4, 0x0181,
- 0xc140, 0x390b, 0x40c0, 0x1909, 0xe1c2, 0x68ca, 0x2104, 0xa181,
- 0x1092, 0x59d1, 0xd050, 0x9111, 0x0014, 0x48c6, 0x41d4, 0x8185,
- 0x414a, 0xd1d3, 0x50d0, 0x51d1, 0x0184, 0x48da, 0x8104, 0x4848,
- 0x3182, 0x18a2, 0xf140, 0x68c0, 0x4066, 0x49e1, 0xc0e0, 0xa101,
- 0x4060, 0x2888, 0x0020, 0x78c8, 0x6146, 0xa888, 0x8028, 0xc064,
- 0x41c0, 0xd8d2, 0xd1f0, 0x9991, 0x41c0, 0x49c3, 0x00a4, 0x4870,
- 0x5152, 0xd1f3, 0x1038, 0x59f9, 0x8128, 0x0999, 0x4178, 0x8105,
- 0x9100, 0x0183, 0xa000, 0x8000, 0xa002, 0x8000, 0x0100, 0x8084,
- 0x3182, 0x1989, 0x1008, 0x1181, 0xa08a, 0xa88a, 0x8100, 0x0000,
- 0x0100, 0x1111, 0x0080, 0x8000, 0x0082, 0x8892, 0x8194, 0x8195,
- 0x8002, 0x9193, 0x0108, 0x1111, 0x8198, 0x8094, 0x0080, 0x0080,
- 0x80a2, 0xb181, 0xb000, 0x81a1, 0xa106, 0xa084, 0x2000, 0x00a0,
- 0x9120, 0xb181, 0xb108, 0x1020, 0x00a4, 0x0828, 0x8024, 0x01a5,
- 0x0000, 0x0101, 0x0120, 0x1131, 0x81a0, 0x89a3, 0x0010, 0x01b1,
- 0x802a, 0x9191, 0x8008, 0x0909, 0x811a, 0x091b, 0x8010, 0x8014,
- 0xb180, 0x8981, 0x6140, 0xd8c0, 0x6144, 0x8983, 0xc144, 0x0080,
- 0x210a, 0xb888, 0x61c0, 0x8989, 0xa10c, 0x68ca, 0x808c, 0xc044,
- 0x41c0, 0x0082, 0x4140, 0x4840, 0xc0d4, 0x41c1, 0x41d4, 0x0080,
- 0x1110, 0x8002, 0x41c0, 0xc040, 0x8008, 0x088e, 0x011c, 0x8898,
- 0x60c2, 0xd961, 0x1020, 0xc860, 0xe1c2, 0x48e0, 0x40e0, 0x4965,
- 0xf1c8, 0x388a, 0x80a0, 0xf040, 0xe0cc, 0x08a8, 0x2000, 0x81a5,
- 0xc140, 0x0080, 0x1090, 0x40c0, 0xc142, 0x40e2, 0x8124, 0xc1d1,
- 0x517a, 0x41e3, 0xd0d8, 0x49c9, 0xc1e6, 0x891d, 0x4044, 0x0125,
+// if any. The exceptions are DDPDOJ & KOF98UMH (see below).
+
+const uint8_t m312cn_key[0x100] = {
+ 0x01, 0x09, 0x02, 0xab, 0x23, 0x20, 0xa2, 0x03, 0x10, 0x9b, 0xba, 0x33, 0x04, 0x2e, 0x27, 0x23,
+ 0x92, 0x11, 0x13, 0x93, 0x13, 0x86, 0x83, 0x02, 0x18, 0x8a, 0x8b, 0x9a, 0x10, 0x0f, 0x13, 0x83,
+ 0xa2, 0x98, 0x32, 0xba, 0x06, 0xab, 0x02, 0x0b, 0x1a, 0xa0, 0x13, 0x82, 0x84, 0x80, 0x8a, 0xa7,
+ 0x83, 0xb0, 0xb2, 0xab, 0x31, 0x07, 0xa3, 0x02, 0x10, 0x23, 0x8b, 0xb2, 0x2b, 0x0a, 0xa7, 0xa3,
+ 0x02, 0x7b, 0x12, 0xc3, 0x07, 0x0c, 0x43, 0xa6, 0x91, 0x91, 0x9b, 0xaa, 0x82, 0xca, 0x2e, 0x6a,
+ 0x43, 0x51, 0x02, 0xcb, 0x52, 0x8b, 0x56, 0x57, 0x88, 0xc3, 0x83, 0x1a, 0x8d, 0x51, 0x86, 0x0a,
+ 0xc1, 0x1b, 0x22, 0x5a, 0x07, 0x84, 0xa3, 0xce, 0xba, 0xfa, 0xab, 0x6a, 0xea, 0x2c, 0x2e, 0x67,
+ 0x00, 0x33, 0x53, 0xd3, 0x47, 0x98, 0x93, 0x62, 0x2b, 0x9b, 0x2b, 0x82, 0xed, 0x4b, 0x1a, 0x86,
+ 0xa0, 0xb9, 0x82, 0x0b, 0x27, 0x09, 0xa2, 0xab, 0x20, 0x3a, 0x8b, 0x0a, 0x84, 0x8d, 0x0b, 0x8f,
+ 0x83, 0x8a, 0x92, 0x13, 0x10, 0x18, 0x06, 0x96, 0x83, 0x89, 0x8b, 0x92, 0x1c, 0x92, 0x9b, 0x17,
+ 0x02, 0x2b, 0x02, 0x02, 0x06, 0x25, 0xa2, 0xab, 0xa8, 0x12, 0x13, 0x9a, 0x21, 0x27, 0x03, 0x2a,
+ 0xa3, 0x92, 0x33, 0xb2, 0x94, 0x12, 0x32, 0x9b, 0x90, 0xa0, 0x8a, 0x2a, 0x9a, 0xbb, 0xae, 0x1e,
+ 0x41, 0x2b, 0x92, 0xb2, 0x44, 0xe0, 0x02, 0x6f, 0x61, 0x30, 0x4a, 0x13, 0x61, 0x4f, 0x2e, 0xa6,
+ 0x52, 0x00, 0xc2, 0x8b, 0x53, 0x8f, 0x93, 0x4f, 0x5b, 0x01, 0x1a, 0x9b, 0xc6, 0x01, 0x03, 0x0b,
+ 0x42, 0x09, 0xf2, 0x62, 0x82, 0x41, 0x22, 0xc6, 0x90, 0x2a, 0xfa, 0x0b, 0x6c, 0xa0, 0x4f, 0x03,
+ 0xa0, 0x53, 0xf2, 0xbb, 0x46, 0x96, 0x23, 0x22, 0xd8, 0xfa, 0x12, 0xab, 0x88, 0x1a, 0x7a, 0x8a,
};
-const uint16_t kov3_key[0x100] = {
- 0x9100, 0x0202, 0x0200, 0xb101, 0x2306, 0x8004, 0x0104, 0x2b01,
- 0x8100, 0x3a0a, 0xa108, 0x2b09, 0x8206, 0x2b0f, 0xa004, 0x2b09,
- 0x9110, 0x0b03, 0x8200, 0x1b11, 0x8306, 0x0010, 0x8304, 0x0814,
- 0x9018, 0x0909, 0x1318, 0x8b09, 0x800c, 0x8a0e, 0x0310, 0x0a1c,
- 0x2202, 0x0020, 0x0220, 0x8b21, 0x0120, 0x0222, 0xa100, 0x8a20,
- 0x1322, 0xbb0b, 0x2000, 0xba08, 0x0326, 0x0929, 0xa00c, 0x2105,
- 0x8100, 0x8800, 0x0300, 0x0800, 0x8104, 0x8222, 0x0230, 0x0220,
- 0x8028, 0x0b2b, 0x9010, 0x1230, 0x8316, 0x8b1f, 0x0018, 0x0004,
- 0xc140, 0x3800, 0x5340, 0x8200, 0xe040, 0x2105, 0x8004, 0x4b41,
- 0xd148, 0x6343, 0xb100, 0xdb49, 0xe24a, 0x8105, 0xc248, 0x4b4d,
- 0x1010, 0x0101, 0x0300, 0xd850, 0x8010, 0x8206, 0x0000, 0x0115,
- 0xd050, 0x9010, 0xc340, 0x1818, 0x0004, 0x484c, 0x8110, 0xc949,
- 0xe242, 0x0323, 0x1020, 0x5060, 0x8024, 0x0925, 0xa104, 0x2204,
- 0xf24a, 0x2303, 0x0120, 0xe040, 0xa202, 0xa909, 0x230c, 0xaa0c,
- 0x5252, 0x5070, 0x5270, 0x1210, 0x0306, 0xc155, 0x0314, 0x8224,
- 0x0008, 0xc848, 0x8208, 0x1111, 0x0222, 0x090d, 0x424c, 0x881c,
- 0x1100, 0xb880, 0x1000, 0x1901, 0x0104, 0xa884, 0x8084, 0x0b01,
- 0x3202, 0x9181, 0x9388, 0xa181, 0xa084, 0x280c, 0x818c, 0xaa8c,
- 0x8180, 0x0303, 0x9090, 0x9b91, 0x0302, 0x0a16, 0x8384, 0x0004,
- 0x8088, 0x8b8b, 0x1318, 0x1311, 0x8198, 0x0a1a, 0x8284, 0x0b1d,
- 0x3302, 0x0921, 0xa380, 0x0321, 0x82a6, 0x0020, 0x81a0, 0xa884,
- 0x93a2, 0x9bab, 0x2108, 0xb181, 0xa28a, 0x88a8, 0xa288, 0x2204,
- 0x1312, 0x88a0, 0x0220, 0x9191, 0x80b4, 0x80a0, 0x82a0, 0x8395,
- 0x83aa, 0x1a1a, 0x93b8, 0x9391, 0x819c, 0x8aaa, 0x0300, 0x0220,
- 0x5342, 0x9981, 0x0100, 0x3000, 0xa084, 0xc3c3, 0xc3c0, 0x6345,
- 0x2302, 0x9888, 0x6148, 0x7040, 0x624a, 0x8383, 0xe0c0, 0xab8d,
- 0xc3c2, 0xc0c0, 0xd2d0, 0x0b01, 0x4150, 0x4955, 0x4244, 0xc0c0,
- 0x8282, 0x1b1b, 0x8180, 0xc8c8, 0x0306, 0x8387, 0x0318, 0xc2c0,
- 0x1120, 0x90a0, 0x5260, 0xd8e0, 0x2306, 0xa383, 0x6044, 0x88a4,
- 0x6342, 0x6040, 0x1020, 0x3b09, 0x200c, 0xa387, 0x81a4, 0x082c,
- 0x0222, 0x1333, 0xd2d0, 0x0301, 0x0030, 0xc0c4, 0x4174, 0x4a74,
- 0x1010, 0x4b6b, 0x1318, 0x5371, 0x023e, 0x0327, 0x0314, 0xc3d5,
+const uint8_t cjddzsp_key[0x100] = {
+ 0x11, 0x21, 0xa2, 0x1a, 0x84, 0xaf, 0x26, 0x0b, 0x3b, 0xbb, 0x12, 0x9b, 0x89, 0x80, 0x2f, 0x0a,
+ 0x91, 0x80, 0x93, 0x93, 0x80, 0x0b, 0x13, 0x93, 0x0a, 0x82, 0x8a, 0x12, 0x13, 0x05, 0x96, 0x17,
+ 0x81, 0xb1, 0xb3, 0xab, 0x06, 0x2a, 0x87, 0x83, 0x33, 0x93, 0x13, 0x8a, 0x28, 0xa8, 0x07, 0x8b,
+ 0x11, 0xa3, 0xb2, 0xa2, 0x23, 0x17, 0x17, 0xb6, 0x33, 0xa9, 0xa3, 0x23, 0xa0, 0xa3, 0x9b, 0xbb,
+ 0x70, 0xe8, 0x83, 0x72, 0xe6, 0xa2, 0xa2, 0x27, 0xbb, 0xc8, 0xf3, 0x42, 0x6d, 0xc8, 0x66, 0x47,
+ 0x93, 0x18, 0x12, 0x12, 0x13, 0x58, 0xd2, 0xc6, 0x49, 0x09, 0xc3, 0x0a, 0x81, 0x0b, 0xc2, 0xda,
+ 0xd2, 0x33, 0xc2, 0x1a, 0x40, 0x89, 0x26, 0xeb, 0x78, 0x51, 0x5a, 0x62, 0xa3, 0xee, 0x02, 0x8f,
+ 0x42, 0xa1, 0xe3, 0x3a, 0x41, 0x44, 0x93, 0xd3, 0x03, 0xda, 0xe2, 0x83, 0x69, 0xc5, 0xb3, 0xb6,
+ 0x91, 0x00, 0xa2, 0x32, 0x24, 0x88, 0x87, 0xab, 0x02, 0x28, 0x2a, 0x8b, 0x87, 0xab, 0x2b, 0x8b,
+ 0x13, 0x02, 0x03, 0x9a, 0x94, 0x13, 0x87, 0x0b, 0x1a, 0x98, 0x03, 0x1b, 0x10, 0x81, 0x1a, 0x9f,
+ 0x81, 0xa9, 0x03, 0x3a, 0x05, 0x06, 0x27, 0xab, 0x3b, 0xa8, 0x8a, 0xab, 0xaf, 0x0a, 0xaa, 0x2f,
+ 0x31, 0x39, 0x32, 0x3a, 0x81, 0xbf, 0x07, 0x87, 0x89, 0x98, 0xa2, 0x22, 0x13, 0xa4, 0xb6, 0x0e,
+ 0x43, 0xf2, 0x43, 0x33, 0x47, 0x4c, 0x66, 0x26, 0xf2, 0x69, 0x2b, 0x5a, 0xa3, 0x83, 0x4b, 0xe6,
+ 0x41, 0x50, 0x92, 0xcb, 0xd3, 0x1e, 0x57, 0x87, 0x01, 0x19, 0x9a, 0x52, 0x45, 0x5a, 0x9e, 0xde,
+ 0xa3, 0xa1, 0x42, 0x7b, 0xa3, 0x22, 0xa2, 0x87, 0x80, 0xe0, 0xf3, 0x23, 0x2a, 0x8e, 0x2f, 0x6f,
+ 0x92, 0x1a, 0x23, 0xab, 0xb3, 0x09, 0xd6, 0xab, 0x38, 0xe3, 0x2b, 0x3a, 0xdf, 0x7d, 0xea, 0x87,
};
-const uint16_t kov2_key[0x100] = {
- 0x1000, 0x3101, 0x9300, 0x0101, 0xa100, 0x8804, 0x8100, 0x2000,
- 0x0100, 0x1101, 0xb208, 0xa101, 0x8100, 0x0b0f, 0x200c, 0x0305,
- 0x0000, 0x9b13, 0x8000, 0x9911, 0x0302, 0x8804, 0x8200, 0x8a10,
- 0x830a, 0x0a0a, 0x8008, 0x9b19, 0x0110, 0x0808, 0x820c, 0x0204,
- 0x2202, 0x8121, 0x3200, 0xb101, 0x8120, 0xa206, 0x0120, 0x0325,
- 0xb108, 0x3000, 0xb300, 0x1b29, 0xa20a, 0x8828, 0x2300, 0xa200,
- 0x9030, 0x0101, 0x9230, 0x1230, 0x0014, 0x0216, 0x0114, 0x8a24,
- 0x0108, 0x1919, 0x9110, 0x1b39, 0x8336, 0x8b2b, 0x830c, 0x8105,
- 0x4242, 0xb000, 0xe040, 0x1901, 0xe144, 0x4246, 0x6340, 0xc945,
- 0xe24a, 0x6949, 0xe148, 0x3a08, 0xe14c, 0x6a4a, 0x434c, 0xab09,
- 0x0302, 0x0800, 0xd250, 0x4b41, 0xc050, 0xca56, 0x0304, 0xcb45,
- 0xc342, 0x9a1a, 0x0208, 0xda58, 0x020a, 0xc95d, 0xc158, 0xc250,
- 0x2100, 0x4161, 0xa000, 0x8921, 0xc366, 0x2307, 0xe344, 0xeb41,
- 0x832a, 0x5969, 0xb208, 0x9321, 0x4160, 0x0b2f, 0x0020, 0x4a6c,
- 0x4160, 0x9830, 0x4060, 0x9010, 0x0216, 0x8303, 0x0020, 0x4161,
- 0x0222, 0x0a2a, 0xc260, 0xc060, 0x4078, 0x4357, 0xc370, 0xca68,
- 0x3000, 0xa282, 0x2100, 0x0a00, 0x2206, 0xaa82, 0x8284, 0x2901,
- 0x320a, 0x0303, 0x9388, 0x9381, 0x0000, 0x0000, 0x220c, 0x0808,
- 0x9190, 0x1010, 0x8280, 0x0b01, 0x8286, 0x0216, 0x0314, 0x8294,
- 0x828a, 0x0101, 0x8180, 0x9898, 0x8386, 0x8181, 0x0204, 0x0305,
- 0x3100, 0x2800, 0x1020, 0x80a0, 0x80a4, 0x0b27, 0xa384, 0x2804,
- 0x3202, 0x3101, 0x2300, 0x82a0, 0xa084, 0xa084, 0x2000, 0xa080,
- 0x1110, 0x99b1, 0x1330, 0x82a0, 0x83b2, 0x0337, 0x8094, 0x8880,
- 0x83a2, 0x1b3b, 0x8188, 0x1b39, 0x013c, 0x0333, 0x82b0, 0x0838,
- 0x9180, 0xeac2, 0x2000, 0x1301, 0xc0c0, 0x6246, 0x2300, 0xab81,
- 0x828a, 0xa989, 0x2308, 0x4b49, 0xe3c6, 0xa185, 0x434c, 0xcbcd,
- 0x1010, 0xcbc3, 0xc1c0, 0xdad0, 0x0306, 0xc2d6, 0x4050, 0xcac4,
- 0x1118, 0x4343, 0x0300, 0x8989, 0x8080, 0x8094, 0x020c, 0x0a1c,
- 0x5060, 0x1222, 0xe2c0, 0x92a0, 0xe2c2, 0x6b47, 0xa180, 0x4264,
- 0xf0c8, 0xf8c8, 0xa388, 0xab89, 0x220a, 0x0929, 0xc2e0, 0x4b69,
- 0xc1c0, 0x9ab2, 0x81a0, 0x5a70, 0x4164, 0x4353, 0x8390, 0x4161,
- 0xd0d0, 0x8383, 0x4260, 0xd1f1, 0x023e, 0x4a5e, 0x0230, 0xcbcd,
+const uint8_t cjdh2_key[0x100] = {
+ 0x03, 0x31, 0x92, 0x23, 0x21, 0x2b, 0x23, 0x23, 0x39, 0x01, 0xb2, 0x9b, 0x0d, 0xaa, 0x07, 0x86,
+ 0x03, 0x9b, 0x03, 0x82, 0x82, 0x00, 0x86, 0x0b, 0x80, 0x92, 0x9a, 0x1b, 0x81, 0x9a, 0x92, 0x8f,
+ 0x83, 0x89, 0x82, 0x0a, 0x02, 0x0f, 0x83, 0xa7, 0x80, 0x32, 0xbb, 0x02, 0x8f, 0xa2, 0xaa, 0x0e,
+ 0x80, 0x12, 0x23, 0xbb, 0x86, 0xb9, 0xb3, 0x1b, 0x19, 0xb8, 0x93, 0x22, 0x28, 0x9d, 0xbf, 0xb2,
+ 0xa1, 0xb0, 0x63, 0xaa, 0x81, 0x8a, 0x47, 0x0b, 0xdb, 0x21, 0x5a, 0x03, 0xe9, 0x60, 0x2f, 0xab,
+ 0x00, 0x43, 0xc2, 0x8b, 0x06, 0x54, 0x47, 0x9f, 0x51, 0xc9, 0x4a, 0x4b, 0x1f, 0x40, 0x9f, 0x52,
+ 0x21, 0x00, 0xe3, 0x72, 0x44, 0x43, 0xc2, 0xab, 0x5a, 0x32, 0x1a, 0x62, 0x6d, 0xa2, 0x82, 0xce,
+ 0x73, 0xe0, 0xc3, 0xa3, 0x73, 0x71, 0x16, 0x42, 0x69, 0xc9, 0x02, 0x43, 0x93, 0x23, 0x43, 0xbf,
+ 0x83, 0x19, 0xb2, 0x9a, 0xa0, 0x8a, 0x03, 0x8e, 0x29, 0x03, 0x02, 0x0b, 0xa0, 0xa0, 0x8b, 0x0a,
+ 0x13, 0x0b, 0x12, 0x9a, 0x10, 0x80, 0x87, 0x8f, 0x98, 0x89, 0x13, 0x0b, 0x83, 0x8e, 0x1a, 0x1a,
+ 0x90, 0xab, 0xa2, 0x9b, 0xa5, 0xae, 0x22, 0x0a, 0x8b, 0xab, 0xa3, 0x0a, 0x0e, 0x02, 0x8e, 0x0f,
+ 0x32, 0x3b, 0x13, 0x0b, 0x93, 0x91, 0x22, 0x0b, 0x90, 0xab, 0xb2, 0x33, 0xa1, 0x21, 0xaa, 0xae,
+ 0xa3, 0x93, 0x73, 0xc2, 0x67, 0x81, 0xc7, 0x0a, 0x31, 0xa2, 0x7b, 0x93, 0xa7, 0x60, 0x86, 0xce,
+ 0x53, 0x18, 0x53, 0x52, 0xc6, 0x5b, 0x47, 0x1a, 0x0b, 0x98, 0x5b, 0xda, 0x92, 0x14, 0x07, 0x82,
+ 0x70, 0xc3, 0x02, 0xd2, 0xe1, 0x42, 0x42, 0x47, 0xe3, 0x20, 0x9a, 0xea, 0xe6, 0x02, 0x2a, 0x8f,
+ 0xf3, 0x3a, 0x22, 0x7a, 0xf1, 0x58, 0x97, 0xeb, 0x41, 0x59, 0xe2, 0x73, 0xdd, 0xa7, 0x7e, 0x1f,
};
-// DDPDOJ caused lots of problems to the automatic recovery process,
-// so it have needed a good amount of manual examination. It is much
-// more probable for this key to still contain errors than for the
-// other ones.
-
-const uint16_t ddpdoj_key[0x100] = {
- 0xb102, 0x8802, 0x0000, 0x9101, 0x2004, 0xa105, 0x0000, 0x8905,
- 0x8102, 0x2000, 0x3000, 0x3808, 0x210e, 0xa006, 0x800c, 0xa004,
- 0x9110, 0x9911, 0x9010, 0x8800, 0x8006, 0x0901, 0x8114, 0x0115,
- 0x1118, 0x1012, 0x0108, 0x8101, 0x000e, 0x8115, 0x0014, 0x0115,
- 0x1020, 0x0921, 0xb100, 0xb000, 0x8126, 0x2907, 0x0020, 0xa901,
- 0x1128, 0x2000, 0x2000, 0x0929, 0x2100, 0x0123, 0x8028, 0x8929,
- 0x1110, 0x8802, 0x1010, 0x9810, 0x8106, 0x0000, 0x8110, 0x8020,
- 0x9018, 0x1030, 0x1118, 0x9939, 0x8004, 0x081c, 0x8124, 0x093d,
-
- 0x1102, 0xe141, 0xa000, 0x1901, 0x8102, 0x8901, 0xa004, 0x6141,
- 0xe040, 0xa103, 0xf048, 0xc949, 0x8000, 0x090f, 0xe044, 0x880c,
- 0xd152, 0xc840, 0x9110, 0xc941, 0x0000, 0x0117, 0x4044, 0xc054,
- 0x1010, 0x181a, 0x8000, 0x5959, 0x0002, 0x485c, 0x0114, 0xc151,
- 0x5060, 0xc862, 0x1020, 0x7040, 0xc062, 0x6042, 0x8024, 0x2101,
- 0xc162, 0x596b, 0xe140, 0x9020, 0xc162, 0x694d, 0x2104, 0xa90d,
- 0x1032, 0xd872, 0x5170, 0x1010, 0x4156, 0xc951, 0x4044, 0x4961,
- 0x9030, 0xd85a, 0x8020, 0x1939, 0x011e, 0x0012, 0x8000, 0xc151,
-
- 0x3102, 0x9880, 0xa080, 0xb181, 0xa182, 0x8084, 0x0000, 0xa981,
- 0x1102, 0x2000, 0x8180, 0x1808, 0x8180, 0x290d, 0xa084, 0x8084,
- 0x9092, 0x8981, 0x0100, 0x0901, 0x0004, 0x8884, 0x8094, 0x8991,
- 0x0100, 0x989a, 0x1110, 0x0909, 0x8192, 0x889e, 0x0000, 0x898d,
- 0xb080, 0x1022, 0xb080, 0x3000, 0x2106, 0x2101, 0x80a4, 0x89a1,
- 0x81a2, 0x1022, 0xb088, 0x3101, 0x2002, 0x2107, 0x81a8, 0x0024,
- 0x8080, 0x9991, 0x0120, 0x0020, 0x8090, 0x0101, 0x8084, 0x0911,
- 0x8082, 0x99b9, 0x9190, 0x1010, 0x81b6, 0x89ab, 0x81ac, 0x8989,
-
- 0xf1c0, 0x3901, 0xa080, 0x7141, 0x0104, 0xa985, 0xe0c4, 0x2800,
- 0x310a, 0x280a, 0x7040, 0x1101, 0x210e, 0xe8ca, 0x6040, 0x694d,
- 0x9090, 0x8082, 0x8180, 0xd8d0, 0xc1d2, 0x8197, 0x0114, 0x8181,
- 0xd0d8, 0xc8c8, 0x0108, 0xc1c1, 0xc1c2, 0x0113, 0x819c, 0xc9cd,
- 0x91a0, 0x1121, 0xf0c0, 0x4161, 0xe0c6, 0x2006, 0x4060, 0xa880,
- 0x5068, 0x7040, 0x2100, 0x3808, 0x210e, 0x81a3, 0x416c, 0x0121,
- 0xd1d0, 0x9193, 0xc1e0, 0xc9c1, 0x0014, 0x0830, 0x4050, 0x4961,
- 0x103a, 0xc9e9, 0x1118, 0x1111, 0x404e, 0x8898, 0x0024, 0x0020,
+const uint8_t kov3_key[0x100] = {
+ 0x83, 0x18, 0x10, 0xab, 0x25, 0x8e, 0x07, 0x21, 0x9b, 0x20, 0xb3, 0x31, 0x8c, 0x25, 0xae, 0x21,
+ 0x83, 0x11, 0x90, 0x01, 0x95, 0x0a, 0x95, 0x06, 0x82, 0x13, 0x01, 0x91, 0x96, 0x94, 0x09, 0x04,
+ 0x30, 0x1a, 0x10, 0x91, 0x03, 0x08, 0xa3, 0x80, 0x09, 0xa1, 0x3a, 0xa0, 0x0d, 0x03, 0xa6, 0x2f,
+ 0xb3, 0xb2, 0x31, 0x32, 0xb7, 0x98, 0x00, 0x18, 0x92, 0x11, 0xaa, 0x08, 0xad, 0xa5, 0x22, 0x3e,
+ 0xd3, 0x22, 0x41, 0x98, 0xe2, 0x2f, 0x86, 0x41, 0xc3, 0x79, 0xab, 0xc1, 0xe0, 0x8f, 0xc0, 0x45,
+ 0x02, 0x1b, 0x11, 0xc2, 0x82, 0x9c, 0x12, 0x0f, 0xca, 0x8a, 0xd9, 0x02, 0x1e, 0x56, 0x8b, 0xd3,
+ 0xf0, 0x19, 0x02, 0x4a, 0x86, 0x07, 0xa7, 0x2c, 0xe0, 0x39, 0x1b, 0xfa, 0xa8, 0xa3, 0x25, 0xa4,
+ 0x60, 0x4a, 0x40, 0x28, 0x35, 0xef, 0x25, 0x9c, 0x32, 0xf2, 0xb0, 0x2b, 0x18, 0x37, 0x74, 0xa6,
+ 0x03, 0xa2, 0x02, 0x03, 0x07, 0xa6, 0x86, 0x01, 0x28, 0x8b, 0x81, 0xbb, 0xae, 0x26, 0x87, 0xa4,
+ 0x93, 0x19, 0x82, 0x81, 0x11, 0x04, 0x95, 0x1e, 0x92, 0x91, 0x01, 0x09, 0x83, 0x00, 0x9c, 0x05,
+ 0x21, 0x13, 0xb1, 0x19, 0x84, 0x0a, 0x83, 0xa6, 0x89, 0x81, 0x33, 0xab, 0xa0, 0x82, 0xa0, 0x2c,
+ 0x21, 0x92, 0x10, 0xab, 0x86, 0x9a, 0x90, 0xad, 0x91, 0x20, 0x81, 0xa9, 0xa7, 0x90, 0x39, 0x18,
+ 0x41, 0x83, 0x13, 0x2a, 0xa6, 0xc9, 0xc1, 0x6d, 0x39, 0x82, 0x73, 0x6a, 0x60, 0x89, 0xea, 0xa5,
+ 0xd1, 0xda, 0xc0, 0x11, 0x43, 0x47, 0x54, 0xda, 0x98, 0x01, 0x9b, 0xd2, 0x1d, 0x9d, 0x01, 0xd8,
+ 0x03, 0x8a, 0x40, 0xc2, 0x25, 0xa9, 0x66, 0x86, 0x79, 0x7a, 0x0a, 0x21, 0x26, 0xad, 0x8f, 0x06,
+ 0x10, 0x09, 0xe0, 0x39, 0x02, 0xfe, 0x47, 0x44, 0x2a, 0x51, 0x21, 0x49, 0x04, 0x1d, 0x2d, 0xed,
};
-// WRONG
-
-const uint16_t kof98umh_key[0x100] = {
- 0x9202, 0x0000, 0x0220, 0x3b01, 0x2004, 0x00a0, 0x0000, 0x0905,
- 0x830a, 0x8000, 0x8228, 0xa20a, 0x8206, 0x0000, 0x0020, 0x8808,
- 0x9212, 0x0800, 0x0000, 0x0301, 0x0020, 0x0a02, 0x0000, 0x0105,
- 0x020a, 0x0000, 0x0000, 0x1111, 0x021a, 0x0121, 0x0000, 0x8111,
- 0x8020, 0x0802, 0xb120, 0xb901, 0x8326, 0x0800, 0x0000, 0xa101,
- 0x922a, 0x0000, 0x1200, 0x9022, 0x0128, 0x0800, 0x0020, 0xaa0c,
- 0x0202, 0x0800, 0x8000, 0x1b31, 0x8024, 0x8804, 0x0000, 0x8111,
- 0x8120, 0x8000, 0x0080, 0x9030, 0x032e, 0x083c, 0x0000, 0x893d,
- 0xe342, 0x0800, 0x0120, 0x7b41, 0xa000, 0x00a0, 0x0000, 0x4141,
- 0x130a, 0x0000, 0x8320, 0xdb49, 0x010c, 0x0000, 0x0020, 0xc84c,
- 0x0202, 0x0000, 0x0000, 0x1911, 0x0014, 0x0b13, 0x0000, 0x8a10,
- 0x434a, 0x0020, 0x0000, 0x5250, 0xc050, 0x0034, 0x0000, 0xc355,
- 0x7242, 0x0002, 0x9000, 0xcb61, 0x8120, 0x0020, 0x0000, 0x0921,
- 0x4068, 0x0000, 0x6068, 0x922a, 0xc36e, 0x0020, 0x0020, 0x280c,
- 0x0322, 0x0800, 0x8020, 0x9810, 0xc060, 0x4b73, 0x0000, 0x4870,
- 0xd050, 0x0020, 0x0000, 0x1b39, 0xc26e, 0x0121, 0x0000, 0x4375,
- 0x2202, 0x0000, 0x0120, 0xb0a0, 0x2202, 0x2020, 0x2000, 0x8280,
- 0x838a, 0x0080, 0x81a0, 0xb082, 0x2004, 0x0000, 0x0020, 0xa385,
- 0x8080, 0x0080, 0x0000, 0x9191, 0x80a0, 0x0004, 0x0000, 0x8280,
- 0x9098, 0x0020, 0x0080, 0x0808, 0x030e, 0x0337, 0x0000, 0x8290,
- 0xb382, 0x0002, 0x0000, 0x1220, 0x2004, 0x0000, 0x0080, 0x2301,
- 0x81a8, 0x0000, 0x0228, 0x1121, 0x230a, 0x2000, 0x0000, 0x80a0,
- 0x1232, 0x0020, 0x0020, 0x9b91, 0x0114, 0x8185, 0x0080, 0x0010,
- 0x82aa, 0x0000, 0x0080, 0x98b8, 0x0226, 0x0a2e, 0x0000, 0x80b4,
- 0x1100, 0x0000, 0xa1a0, 0xf2e0, 0x6144, 0x0020, 0x0000, 0x4145,
- 0x1108, 0x0000, 0xb280, 0x9a8a, 0xa084, 0x0000, 0x0020, 0x4044,
- 0x9190, 0x0000, 0x0000, 0x0a00, 0x4266, 0x0814, 0x0080, 0x8b91,
- 0x434a, 0x00a0, 0x0080, 0x0808, 0x4352, 0x83a3, 0x0000, 0xc3c5,
- 0x3302, 0x0002, 0xd1c0, 0xf3c1, 0xa080, 0x00a0, 0x0000, 0x0b25,
- 0x0128, 0x0000, 0xb288, 0x3b09, 0x200c, 0x2000, 0x0020, 0xeac8,
- 0xd1f0, 0x0000, 0x0020, 0x83a1, 0xc3f2, 0xc8d0, 0x0000, 0x8b91,
- 0x5272, 0x0080, 0x0000, 0x0b29, 0x4376, 0x0828, 0x0000, 0x8ab8,
+// DDPDOJ caused lots of problems to the automatic recovery
+// process, so needed a good amount of manual examination.
+// It is much more probable for this key to still contain errors
+// than for the other ones.
+
+const uint8_t ddpdoj_key[0x100] = {
+ 0xa1, 0x90, 0x12, 0x8b, 0x26, 0xaf, 0x02, 0x87, 0x99, 0x3a, 0x2a, 0x22, 0x25, 0xac, 0x86, 0xae,
+ 0x83, 0x83, 0x82, 0x92, 0x94, 0x13, 0x87, 0x0f, 0x03, 0x08, 0x13, 0x9b, 0x14, 0x8f, 0x0e, 0x0f,
+ 0x02, 0x13, 0xa3, 0xaa, 0x85, 0x25, 0x02, 0xa3, 0x03, 0x3a, 0x3a, 0x13, 0x2b, 0x09, 0x82, 0x83,
+ 0x23, 0xb0, 0x22, 0xa2, 0xb5, 0x3a, 0xa3, 0x9a, 0xa2, 0x0a, 0x23, 0x83, 0xbe, 0x26, 0x9f, 0x07,
+ 0x01, 0xfb, 0xb2, 0x03, 0x81, 0x83, 0xa6, 0x6b, 0xfa, 0xb9, 0xe2, 0xd3, 0x8a, 0x05, 0xee, 0x86,
+ 0xc1, 0xd2, 0x83, 0xd3, 0x12, 0x0d, 0x56, 0xce, 0x0a, 0x00, 0x9a, 0x43, 0x18, 0x46, 0x0f, 0xcb,
+ 0x42, 0xd0, 0x02, 0x6a, 0xc0, 0x68, 0x86, 0x2b, 0xd9, 0x41, 0xfb, 0x8a, 0xc9, 0x67, 0x2f, 0xa7,
+ 0x00, 0xc0, 0x43, 0x2a, 0x65, 0xe3, 0x76, 0x53, 0x8a, 0xe0, 0x9a, 0x03, 0x25, 0x28, 0xba, 0xeb,
+ 0x21, 0x82, 0xb2, 0xab, 0xa1, 0x8e, 0x02, 0xa3, 0x09, 0x3a, 0x9b, 0x02, 0x8b, 0x27, 0xae, 0x8e,
+ 0x80, 0x93, 0x13, 0x13, 0x16, 0x96, 0x86, 0x83, 0x1b, 0x80, 0x0b, 0x13, 0x89, 0x84, 0x1a, 0x97,
+ 0xa2, 0x08, 0xa2, 0x2a, 0x25, 0x2b, 0x86, 0x83, 0x99, 0x08, 0xa2, 0x2b, 0x28, 0x2d, 0x83, 0x0e,
+ 0xb2, 0xa3, 0x13, 0x1a, 0xa2, 0x3b, 0xb6, 0x23, 0xb8, 0x83, 0xab, 0x2a, 0x8d, 0x91, 0x97, 0xb3,
+ 0xe3, 0x23, 0xb2, 0x6b, 0x07, 0xa7, 0xe6, 0x22, 0x21, 0x30, 0x6a, 0x0b, 0x25, 0xe0, 0x6a, 0x67,
+ 0x82, 0x98, 0x93, 0xc2, 0xc1, 0x8d, 0x07, 0x9b, 0xc2, 0xd2, 0x13, 0xdb, 0xd9, 0x09, 0x87, 0xd7,
+ 0x83, 0x0b, 0xe2, 0x5b, 0xe4, 0x2c, 0x42, 0xa2, 0x42, 0x6a, 0x3b, 0x22, 0x25, 0x89, 0x47, 0x0b,
+ 0xe3, 0xa9, 0xd3, 0xf3, 0x26, 0x02, 0x62, 0x53, 0x00, 0xd3, 0x23, 0x2b, 0x74, 0xa2, 0x1e, 0x1a,
};
diff --git a/src/mame/machine/igs036crypt.h b/src/mame/machine/igs036crypt.h
index 903cc558f1a..69386dd2c22 100644
--- a/src/mame/machine/igs036crypt.h
+++ b/src/mame/machine/igs036crypt.h
@@ -7,17 +7,17 @@
class igs036_decryptor
{
public:
- igs036_decryptor(const uint16_t* game_key);
+ igs036_decryptor(const uint8_t* game_key);
void decrypter_rom(memory_region* region);
uint16_t decrypt(uint16_t cipherword, int word_address)const;
uint16_t deobfuscate(uint16_t cipherword, int word_address)const;
private:
- const uint16_t* key;
+ const uint8_t* key;
static int (*rot_enabling[16][4])(int);
static int (*rot_direction[4][8])(int);
- static const uint16_t triggers[16][2];
+ static const uint32_t triggers[16][2];
int rotation(int address)const;
uint16_t rol(uint16_t num, int shift)const;
@@ -25,13 +25,10 @@ private:
int rot_group(int address, const int* group)const;
};
-extern const uint16_t orleg2_key[0x100];
-extern const uint16_t m312cn_key[0x100];
-extern const uint16_t cjddzsp_key[0x100];
-extern const uint16_t cjdh2_key[0x100];
-extern const uint16_t kov3_key[0x100];
-extern const uint16_t kov2_key[0x100];
-extern const uint16_t ddpdoj_key[0x100];
-extern const uint16_t kof98umh_key[0x100];
+extern const uint8_t m312cn_key[0x100];
+extern const uint8_t cjddzsp_key[0x100];
+extern const uint8_t cjdh2_key[0x100];
+extern const uint8_t kov3_key[0x100];
+extern const uint8_t ddpdoj_key[0x100];
#endif
diff --git a/src/mame/machine/jalcrpt.cpp b/src/mame/machine/jalcrpt.cpp
index 45c92d90ce4..9db6afabee1 100644
--- a/src/mame/machine/jalcrpt.cpp
+++ b/src/mame/machine/jalcrpt.cpp
@@ -19,9 +19,9 @@ void phantasm_rom_decode(running_machine &machine, const char *region)
// [0] def0 189a bc56 7234
// [1] fdb9 7531 eca8 6420
// [2] 0123 4567 ba98 fedc
-#define BITSWAP_0 BITSWAP16(x,0xd,0xe,0xf,0x0,0x1,0x8,0x9,0xa,0xb,0xc,0x5,0x6,0x7,0x2,0x3,0x4)
-#define BITSWAP_1 BITSWAP16(x,0xf,0xd,0xb,0x9,0x7,0x5,0x3,0x1,0xe,0xc,0xa,0x8,0x6,0x4,0x2,0x0)
-#define BITSWAP_2 BITSWAP16(x,0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0xb,0xa,0x9,0x8,0xf,0xe,0xd,0xc)
+#define BITSWAP_0 bitswap<16>(x,0xd,0xe,0xf,0x0,0x1,0x8,0x9,0xa,0xb,0xc,0x5,0x6,0x7,0x2,0x3,0x4)
+#define BITSWAP_1 bitswap<16>(x,0xf,0xd,0xb,0x9,0x7,0x5,0x3,0x1,0xe,0xc,0xa,0x8,0x6,0x4,0x2,0x0)
+#define BITSWAP_2 bitswap<16>(x,0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0xb,0xa,0x9,0x8,0xf,0xe,0xd,0xc)
if (i < 0x08000/2) { if ( (i | (0x248/2)) != i ) {y = BITSWAP_0;} else {y = BITSWAP_1;} }
else if (i < 0x10000/2) { y = BITSWAP_2; }
@@ -54,9 +54,9 @@ void astyanax_rom_decode(running_machine &machine, const char *region)
// [1] fdb9 7531 8ace 0246
// [2] 4567 0123 ba98 fedc
-#define BITSWAP_0 BITSWAP16(x,0xd,0xe,0xf,0x0,0xa,0x9,0x8,0x1,0x6,0x5,0xc,0xb,0x7,0x2,0x3,0x4)
-#define BITSWAP_1 BITSWAP16(x,0xf,0xd,0xb,0x9,0x7,0x5,0x3,0x1,0x8,0xa,0xc,0xe,0x0,0x2,0x4,0x6)
-#define BITSWAP_2 BITSWAP16(x,0x4,0x5,0x6,0x7,0x0,0x1,0x2,0x3,0xb,0xa,0x9,0x8,0xf,0xe,0xd,0xc)
+#define BITSWAP_0 bitswap<16>(x,0xd,0xe,0xf,0x0,0xa,0x9,0x8,0x1,0x6,0x5,0xc,0xb,0x7,0x2,0x3,0x4)
+#define BITSWAP_1 bitswap<16>(x,0xf,0xd,0xb,0x9,0x7,0x5,0x3,0x1,0x8,0xa,0xc,0xe,0x0,0x2,0x4,0x6)
+#define BITSWAP_2 bitswap<16>(x,0x4,0x5,0x6,0x7,0x0,0x1,0x2,0x3,0xb,0xa,0x9,0x8,0xf,0xe,0xd,0xc)
if (i < 0x08000/2) { if ( (i | (0x248/2)) != i ) {y = BITSWAP_0;} else {y = BITSWAP_1;} }
else if (i < 0x10000/2) { y = BITSWAP_2; }
@@ -86,10 +86,10 @@ void rodland_rom_decode(running_machine &machine, const char *region)
// [0] d0a9 6ebf 5c72 3814 [1] 4567 0123 ba98 fedc
// [2] fdb9 ce07 5318 a246 [3] 4512 ed3b a967 08fc
-#define BITSWAP_0 BITSWAP16(x,0xd,0x0,0xa,0x9,0x6,0xe,0xb,0xf,0x5,0xc,0x7,0x2,0x3,0x8,0x1,0x4);
-#define BITSWAP_1 BITSWAP16(x,0x4,0x5,0x6,0x7,0x0,0x1,0x2,0x3,0xb,0xa,0x9,0x8,0xf,0xe,0xd,0xc);
-#define BITSWAP_2 BITSWAP16(x,0xf,0xd,0xb,0x9,0xc,0xe,0x0,0x7,0x5,0x3,0x1,0x8,0xa,0x2,0x4,0x6);
-#define BITSWAP_3 BITSWAP16(x,0x4,0x5,0x1,0x2,0xe,0xd,0x3,0xb,0xa,0x9,0x6,0x7,0x0,0x8,0xf,0xc);
+#define BITSWAP_0 bitswap<16>(x,0xd,0x0,0xa,0x9,0x6,0xe,0xb,0xf,0x5,0xc,0x7,0x2,0x3,0x8,0x1,0x4);
+#define BITSWAP_1 bitswap<16>(x,0x4,0x5,0x6,0x7,0x0,0x1,0x2,0x3,0xb,0xa,0x9,0x8,0xf,0xe,0xd,0xc);
+#define BITSWAP_2 bitswap<16>(x,0xf,0xd,0xb,0x9,0xc,0xe,0x0,0x7,0x5,0x3,0x1,0x8,0xa,0x2,0x4,0x6);
+#define BITSWAP_3 bitswap<16>(x,0x4,0x5,0x1,0x2,0xe,0xd,0x3,0xb,0xa,0x9,0x6,0x7,0x0,0x8,0xf,0xc);
if (i < 0x08000/2) { if ( (i | (0x248/2)) != i ) {y = BITSWAP_0;} else {y = BITSWAP_1;} }
else if (i < 0x10000/2) { if ( (i | (0x248/2)) != i ) {y = BITSWAP_2;} else {y = BITSWAP_3;} }
diff --git a/src/mame/machine/jumpshot.cpp b/src/mame/machine/jumpshot.cpp
index 5cf9cb711a4..ef569cf041d 100644
--- a/src/mame/machine/jumpshot.cpp
+++ b/src/mame/machine/jumpshot.cpp
@@ -37,7 +37,7 @@ uint8_t pacman_state::jumpshot_decrypt(int addr, uint8_t e)
method ^= 1;
tbl = swap_xor_table[method];
- return BITSWAP8(e,tbl[0],tbl[1],tbl[2],tbl[3],tbl[4],tbl[5],tbl[6],tbl[7]) ^ tbl[8];
+ return bitswap<8>(e,tbl[0],tbl[1],tbl[2],tbl[3],tbl[4],tbl[5],tbl[6],tbl[7]) ^ tbl[8];
}
diff --git a/src/mame/machine/kaneko_calc3.cpp b/src/mame/machine/kaneko_calc3.cpp
index 13ab946a72b..78aa0702d9a 100644
--- a/src/mame/machine/kaneko_calc3.cpp
+++ b/src/mame/machine/kaneko_calc3.cpp
@@ -1224,14 +1224,14 @@ uint8_t kaneko_calc3_device::shift_bits(uint8_t dat, int bits)
{
bits &=0x7;
- if (bits==0) return BITSWAP8(dat, 7,6,5,4,3,2,1,0);
- if (bits==1) return BITSWAP8(dat, 6,5,4,3,2,1,0,7);
- if (bits==2) return BITSWAP8(dat, 5,4,3,2,1,0,7,6);
- if (bits==3) return BITSWAP8(dat, 4,3,2,1,0,7,6,5);
- if (bits==4) return BITSWAP8(dat, 3,2,1,0,7,6,5,4);
- if (bits==5) return BITSWAP8(dat, 2,1,0,7,6,5,4,3);
- if (bits==6) return BITSWAP8(dat, 1,0,7,6,5,4,3,2);
- if (bits==7) return BITSWAP8(dat, 0,7,6,5,4,3,2,1);
+ if (bits==0) return bitswap<8>(dat, 7,6,5,4,3,2,1,0);
+ if (bits==1) return bitswap<8>(dat, 6,5,4,3,2,1,0,7);
+ if (bits==2) return bitswap<8>(dat, 5,4,3,2,1,0,7,6);
+ if (bits==3) return bitswap<8>(dat, 4,3,2,1,0,7,6,5);
+ if (bits==4) return bitswap<8>(dat, 3,2,1,0,7,6,5,4);
+ if (bits==5) return bitswap<8>(dat, 2,1,0,7,6,5,4,3);
+ if (bits==6) return bitswap<8>(dat, 1,0,7,6,5,4,3,2);
+ if (bits==7) return bitswap<8>(dat, 0,7,6,5,4,3,2,1);
return dat;
}
diff --git a/src/mame/machine/m24_z8000.cpp b/src/mame/machine/m24_z8000.cpp
index 4d253afb1e2..50a38b480ed 100644
--- a/src/mame/machine/m24_z8000.cpp
+++ b/src/mame/machine/m24_z8000.cpp
@@ -101,7 +101,7 @@ READ16_MEMBER(m24_z8000_device::pmem_r)
return 0;
offset = (offset & 0x3fff) | (hostseg << 14);
if((hostseg >= 40) && (hostseg <= 47))
- offset = (offset & 0xf0000) | BITSWAP16(offset,15,7,6,14,13,12,11,10,9,8,5,4,3,2,1,0); // move A6/A7 so CGA framebuffer appears linear
+ offset = (offset & 0xf0000) | bitswap<16>(offset,15,7,6,14,13,12,11,10,9,8,5,4,3,2,1,0); // move A6/A7 so CGA framebuffer appears linear
ret = m_maincpu->space(AS_PROGRAM).read_word(offset, (mem_mask << 8) | (mem_mask >> 8));
return (ret << 8) | (ret >> 8);
}
@@ -116,7 +116,7 @@ WRITE16_MEMBER(m24_z8000_device::pmem_w)
return;
offset = (offset & 0x3fff) | (hostseg << 14);
if((hostseg >= 40) && (hostseg <= 47))
- offset = (offset & 0xf0000) | BITSWAP16(offset,15,7,6,14,13,12,11,10,9,8,5,4,3,2,1,0);
+ offset = (offset & 0xf0000) | bitswap<16>(offset,15,7,6,14,13,12,11,10,9,8,5,4,3,2,1,0);
m_maincpu->space(AS_PROGRAM).write_word(offset, data, (mem_mask << 8) | (mem_mask >> 8));
}
@@ -136,7 +136,7 @@ READ16_MEMBER(m24_z8000_device::dmem_r)
return 0;
offset = (offset & 0x3fff) | (hostseg << 14);
if((hostseg >= 40) && (hostseg <= 47))
- offset = (offset & 0xf0000) | BITSWAP16(offset,15,7,6,14,13,12,11,10,9,8,5,4,3,2,1,0);
+ offset = (offset & 0xf0000) | bitswap<16>(offset,15,7,6,14,13,12,11,10,9,8,5,4,3,2,1,0);
ret = m_maincpu->space(AS_PROGRAM).read_word(offset, (mem_mask << 8) | (mem_mask >> 8));
return (ret << 8) | (ret >> 8);
}
@@ -151,7 +151,7 @@ WRITE16_MEMBER(m24_z8000_device::dmem_w)
return;
offset = (offset & 0x3fff) | (hostseg << 14);
if((hostseg >= 40) && (hostseg <= 47))
- offset = (offset & 0xf0000) | BITSWAP16(offset,15,7,6,14,13,12,11,10,9,8,5,4,3,2,1,0);
+ offset = (offset & 0xf0000) | bitswap<16>(offset,15,7,6,14,13,12,11,10,9,8,5,4,3,2,1,0);
m_maincpu->space(AS_PROGRAM).write_word(offset, data, (mem_mask << 8) | (mem_mask >> 8));
}
diff --git a/src/mame/machine/mac.cpp b/src/mame/machine/mac.cpp
index 57a9bed5901..ea1f5f3f1c2 100644
--- a/src/mame/machine/mac.cpp
+++ b/src/mame/machine/mac.cpp
@@ -127,7 +127,7 @@ void mac_fdc_set_enable_lines(device_t *device, int enable_mask)
{
mac_state *mac = device->machine().driver_data<mac_state>();
- if (mac->m_model != MODEL_MAC_SE)
+ if (mac->m_model != mac_state::MODEL_MAC_SE)
{
sony_set_enable_lines(device, enable_mask);
}
diff --git a/src/mame/machine/mbee.cpp b/src/mame/machine/mbee.cpp
index 0fd17f6c88e..2a9335c0780 100644
--- a/src/mame/machine/mbee.cpp
+++ b/src/mame/machine/mbee.cpp
@@ -279,7 +279,7 @@ void mbee_state::setup_banks(uint8_t data, bool first_time, uint8_t b_mask)
data &= 0x3f; // (bits 0-5 are referred to as S0-S5)
address_space &mem = m_maincpu->space(AS_PROGRAM);
uint8_t *prom = memregion("pals")->base();
- uint8_t b_data = BITSWAP8(data, 7,5,3,2,4,6,1,0) & 0x3b; // arrange data bits to S0,S1,-,S4,S2,S3
+ uint8_t b_data = bitswap<8>(data, 7,5,3,2,4,6,1,0) & 0x3b; // arrange data bits to S0,S1,-,S4,S2,S3
uint8_t b_bank, b_byte, b_byte_t, b_addr, p_bank = 1;
uint16_t b_vid;
char banktag[10];
@@ -291,11 +291,11 @@ void mbee_state::setup_banks(uint8_t data, bool first_time, uint8_t b_mask)
for (b_bank = 0; b_bank < 16; b_bank++)
{
b_vid = b_bank << 12;
- b_addr = BITSWAP8(b_bank, 7,4,5,3,1,2,6,0) & 0x1f; // arrange address bits to A12,-,A14,A13,A15
+ b_addr = bitswap<8>(b_bank, 7,4,5,3,1,2,6,0) & 0x1f; // arrange address bits to A12,-,A14,A13,A15
// Calculate read-bank
b_byte_t = prom[b_addr | (b_data << 8) | 0x82]; // read-bank (RDS and MREQ are low, RFSH is high)
- b_byte = BITSWAP8(b_byte_t, 7,5,0,3,6,2,1,4); // rearrange so that bits 0-2 are rambank, bit 3 = rom select, bit 4 = video select, others not used
+ b_byte = bitswap<8>(b_byte_t, 7,5,0,3,6,2,1,4); // rearrange so that bits 0-2 are rambank, bit 3 = rom select, bit 4 = video select, others not used
if (first_time || (b_byte != m_bank_array[p_bank]))
{
@@ -327,7 +327,7 @@ void mbee_state::setup_banks(uint8_t data, bool first_time, uint8_t b_mask)
// Calculate write-bank
b_byte_t = prom[b_addr | (b_data << 8) | 0xc0]; // write-bank (XWR and MREQ are low, RFSH is high)
- b_byte = BITSWAP8(b_byte_t, 7,5,0,3,6,2,1,4); // rearrange so that bits 0-2 are rambank, bit 3 = rom select, bit 4 = video select, others not used
+ b_byte = bitswap<8>(b_byte_t, 7,5,0,3,6,2,1,4); // rearrange so that bits 0-2 are rambank, bit 3 = rom select, bit 4 = video select, others not used
if (first_time || (b_byte != m_bank_array[p_bank]))
{
diff --git a/src/mame/machine/mc8123.cpp b/src/mame/machine/mc8123.cpp
index 8a4ff955299..bb446f89992 100644
--- a/src/mame/machine/mc8123.cpp
+++ b/src/mame/machine/mc8123.cpp
@@ -102,10 +102,10 @@ template <typename T, typename... U> constexpr u8 BITS(T b, U... c) { return (u8
u8 mc8123_device::decrypt_type0(u8 val, u8 param, unsigned swap)
{
- if (swap == 0) val = BITSWAP8(val,7,5,3,1,2,0,6,4);
- if (swap == 1) val = BITSWAP8(val,5,3,7,2,1,0,4,6);
- if (swap == 2) val = BITSWAP8(val,0,3,4,6,7,1,5,2);
- if (swap == 3) val = BITSWAP8(val,0,7,3,2,6,4,1,5);
+ if (swap == 0) val = bitswap<8>(val,7,5,3,1,2,0,6,4);
+ if (swap == 1) val = bitswap<8>(val,5,3,7,2,1,0,4,6);
+ if (swap == 2) val = bitswap<8>(val,0,3,4,6,7,1,5,2);
+ if (swap == 3) val = bitswap<8>(val,0,7,3,2,6,4,1,5);
if (BIT(param,3) && BIT(val,7))
val ^= BITS(5,3,0);
@@ -126,7 +126,7 @@ u8 mc8123_device::decrypt_type0(u8 val, u8 param, unsigned swap)
if (BIT(param,1)) val ^= BITS(7,6);
if (BIT(param,0)) val ^= BITS(5,0);
- if (BIT(param,0)) val = BITSWAP8(val,7,6,5,1,4,3,2,0);
+ if (BIT(param,0)) val = bitswap<8>(val,7,6,5,1,4,3,2,0);
return val;
}
@@ -134,12 +134,12 @@ u8 mc8123_device::decrypt_type0(u8 val, u8 param, unsigned swap)
u8 mc8123_device::decrypt_type1a(u8 val, u8 param, unsigned swap)
{
- if (swap == 0) val = BITSWAP8(val,4,2,6,5,3,7,1,0);
- if (swap == 1) val = BITSWAP8(val,6,0,5,4,3,2,1,7);
- if (swap == 2) val = BITSWAP8(val,2,3,6,1,4,0,7,5);
- if (swap == 3) val = BITSWAP8(val,6,5,1,3,2,7,0,4);
+ if (swap == 0) val = bitswap<8>(val,4,2,6,5,3,7,1,0);
+ if (swap == 1) val = bitswap<8>(val,6,0,5,4,3,2,1,7);
+ if (swap == 2) val = bitswap<8>(val,2,3,6,1,4,0,7,5);
+ if (swap == 3) val = bitswap<8>(val,6,5,1,3,2,7,0,4);
- if (BIT(param,2)) val = BITSWAP8(val,7,6,1,5,3,2,4,0);
+ if (BIT(param,2)) val = bitswap<8>(val,7,6,1,5,3,2,4,0);
if (BIT(val,1)) val ^= BITS(0);
if (BIT(val,6)) val ^= BITS(3);
@@ -155,17 +155,17 @@ u8 mc8123_device::decrypt_type1a(u8 val, u8 param, unsigned swap)
if (BIT(param,3)) val ^= BITS(7,2);
if (BIT(param,1)) val ^= BITS(6,3);
- if (BIT(param,0)) val = BITSWAP8(val,7,6,1,4,3,2,5,0);
+ if (BIT(param,0)) val = bitswap<8>(val,7,6,1,4,3,2,5,0);
return val;
}
u8 mc8123_device::decrypt_type1b(u8 val, u8 param, unsigned swap)
{
- if (swap == 0) val = BITSWAP8(val,1,0,3,2,5,6,4,7);
- if (swap == 1) val = BITSWAP8(val,2,0,5,1,7,4,6,3);
- if (swap == 2) val = BITSWAP8(val,6,4,7,2,0,5,1,3);
- if (swap == 3) val = BITSWAP8(val,7,1,3,6,0,2,5,4);
+ if (swap == 0) val = bitswap<8>(val,1,0,3,2,5,6,4,7);
+ if (swap == 1) val = bitswap<8>(val,2,0,5,1,7,4,6,3);
+ if (swap == 2) val = bitswap<8>(val,6,4,7,2,0,5,1,3);
+ if (swap == 3) val = bitswap<8>(val,7,1,3,6,0,2,5,4);
if (BIT(val,2) && BIT(val,0))
val ^= BITS(7,4);
@@ -190,13 +190,13 @@ u8 mc8123_device::decrypt_type1b(u8 val, u8 param, unsigned swap)
u8 mc8123_device::decrypt_type2a(u8 val, u8 param, unsigned swap)
{
- if (swap == 0) val = BITSWAP8(val,0,1,4,3,5,6,2,7);
- if (swap == 1) val = BITSWAP8(val,6,3,0,5,7,4,1,2);
- if (swap == 2) val = BITSWAP8(val,1,6,4,5,0,3,7,2);
- if (swap == 3) val = BITSWAP8(val,4,6,7,5,2,3,1,0);
+ if (swap == 0) val = bitswap<8>(val,0,1,4,3,5,6,2,7);
+ if (swap == 1) val = bitswap<8>(val,6,3,0,5,7,4,1,2);
+ if (swap == 2) val = bitswap<8>(val,1,6,4,5,0,3,7,2);
+ if (swap == 3) val = bitswap<8>(val,4,6,7,5,2,3,1,0);
if (BIT(val,3) || (BIT(param,1) && BIT(val,2)))
- val = BITSWAP8(val,6,0,7,4,3,2,1,5);
+ val = bitswap<8>(val,6,0,7,4,3,2,1,5);
if (BIT(val,5)) val ^= BITS(7);
if (BIT(val,6)) val ^= BITS(5);
@@ -211,13 +211,13 @@ u8 mc8123_device::decrypt_type2a(u8 val, u8 param, unsigned swap)
if (BIT(param,3))
{
if (BIT(param,0))
- val = BITSWAP8(val,7,6,5,3,4,1,2,0);
+ val = bitswap<8>(val,7,6,5,3,4,1,2,0);
else
- val = BITSWAP8(val,7,6,5,1,2,4,3,0);
+ val = bitswap<8>(val,7,6,5,1,2,4,3,0);
}
else if (BIT(param,0))
{
- val = BITSWAP8(val,7,6,5,2,1,3,4,0);
+ val = bitswap<8>(val,7,6,5,2,1,3,4,0);
}
return val;
@@ -228,10 +228,10 @@ u8 mc8123_device::decrypt_type2b(u8 val, u8 param, unsigned swap)
// only 0x20 possible encryptions for this method - all others have 0x40
// this happens because BIT(param,2) cancels the other three
- if (swap == 0) val = BITSWAP8(val,1,3,4,6,5,7,0,2);
- if (swap == 1) val = BITSWAP8(val,0,1,5,4,7,3,2,6);
- if (swap == 2) val = BITSWAP8(val,3,5,4,1,6,2,0,7);
- if (swap == 3) val = BITSWAP8(val,5,2,3,0,4,7,6,1);
+ if (swap == 0) val = bitswap<8>(val,1,3,4,6,5,7,0,2);
+ if (swap == 1) val = bitswap<8>(val,0,1,5,4,7,3,2,6);
+ if (swap == 2) val = bitswap<8>(val,3,5,4,1,6,2,0,7);
+ if (swap == 3) val = bitswap<8>(val,5,2,3,0,4,7,6,1);
if (BIT(val,7) && BIT(val,3))
val ^= BITS(6,4,0);
@@ -263,22 +263,22 @@ u8 mc8123_device::decrypt_type2b(u8 val, u8 param, unsigned swap)
u8 mc8123_device::decrypt_type3a(u8 val, u8 param, unsigned swap)
{
- if (swap == 0) val = BITSWAP8(val,5,3,1,7,0,2,6,4);
- if (swap == 1) val = BITSWAP8(val,3,1,2,5,4,7,0,6);
- if (swap == 2) val = BITSWAP8(val,5,6,1,2,7,0,4,3);
- if (swap == 3) val = BITSWAP8(val,5,6,7,0,4,2,1,3);
+ if (swap == 0) val = bitswap<8>(val,5,3,1,7,0,2,6,4);
+ if (swap == 1) val = bitswap<8>(val,3,1,2,5,4,7,0,6);
+ if (swap == 2) val = bitswap<8>(val,5,6,1,2,7,0,4,3);
+ if (swap == 3) val = bitswap<8>(val,5,6,7,0,4,2,1,3);
if (BIT(val,2)) val ^= BITS(7,5,4);
if (BIT(val,3)) val ^= BITS(0);
- if (BIT(param,0)) val = BITSWAP8(val,7,2,5,4,3,1,0,6);
+ if (BIT(param,0)) val = bitswap<8>(val,7,2,5,4,3,1,0,6);
if (BIT(val,1)) val ^= BITS(6,0);
if (BIT(val,3)) val ^= BITS(4,2,1);
if (BIT(param,3)) val ^= BITS(4,3);
- if (BIT(val,3)) val = BITSWAP8(val,5,6,7,4,3,2,1,0);
+ if (BIT(val,3)) val = bitswap<8>(val,5,6,7,4,3,2,1,0);
if (BIT(val,5)) val ^= BITS(2,1);
@@ -293,14 +293,14 @@ u8 mc8123_device::decrypt_type3a(u8 val, u8 param, unsigned swap)
u8 mc8123_device::decrypt_type3b(u8 val, u8 param, unsigned swap)
{
- if (swap == 0) val = BITSWAP8(val,3,7,5,4,0,6,2,1);
- if (swap == 1) val = BITSWAP8(val,7,5,4,6,1,2,0,3);
- if (swap == 2) val = BITSWAP8(val,7,4,3,0,5,1,6,2);
- if (swap == 3) val = BITSWAP8(val,2,6,4,1,3,7,0,5);
+ if (swap == 0) val = bitswap<8>(val,3,7,5,4,0,6,2,1);
+ if (swap == 1) val = bitswap<8>(val,7,5,4,6,1,2,0,3);
+ if (swap == 2) val = bitswap<8>(val,7,4,3,0,5,1,6,2);
+ if (swap == 3) val = bitswap<8>(val,2,6,4,1,3,7,0,5);
if (BIT(val,2)) val ^= BITS(7);
- if (BIT(val,7)) val = BITSWAP8(val,7,6,3,4,5,2,1,0);
+ if (BIT(val,7)) val = bitswap<8>(val,7,6,3,4,5,2,1,0);
if (BIT(param,3)) val ^= BITS(7);
@@ -315,7 +315,7 @@ u8 mc8123_device::decrypt_type3b(u8 val, u8 param, unsigned swap)
if (BIT(param,3)) val ^= BITS(7);
if (BIT(param,2)) val ^= BITS(0);
- if (BIT(param,3)) val = BITSWAP8(val,4,6,3,2,5,0,1,7);
+ if (BIT(param,3)) val = bitswap<8>(val,4,6,3,2,5,0,1,7);
if (BIT(val,4)) val ^= BITS(1);
if (BIT(val,5)) val ^= BITS(4);
diff --git a/src/mame/machine/megacd.cpp b/src/mame/machine/megacd.cpp
index 10a0ebd6860..ce33cc71a3d 100644
--- a/src/mame/machine/megacd.cpp
+++ b/src/mame/machine/megacd.cpp
@@ -842,13 +842,13 @@ READ16_MEMBER( sega_segacd_device::segacd_main_dataram_part1_r )
// used by Heart of the Alien
if(offset<0x30000/2) /* 0x20000 - 0x2ffff */ // 512x256 bitmap. tiles
- offset = BITSWAP24(offset,23,22,21,20,19,18,17,16,15,8,7,6,5,4,3,2,1,14,13,12,11,10,9,0);
+ offset = bitswap<24>(offset,23,22,21,20,19,18,17,16,15,8,7,6,5,4,3,2,1,14,13,12,11,10,9,0);
else if(offset<0x38000/2) /* 0x30000 - 0x37fff */ // 512x128 bitmap. tiles
- offset = BITSWAP24(offset,23,22,21,20,19,18,17,16,15,14,7,6,5,4,3,2,1,13,12,11,10,9,8,0);
+ offset = bitswap<24>(offset,23,22,21,20,19,18,17,16,15,14,7,6,5,4,3,2,1,13,12,11,10,9,8,0);
else if(offset<0x3c000/2) /* 0x38000 - 0x3bfff */ // 512x64 bitmap. tiles
- offset = BITSWAP24(offset,23,22,21,20,19,18,17,16,15,14,13,6,5,4,3,2,1,12,11,10,9,8,7,0);
+ offset = bitswap<24>(offset,23,22,21,20,19,18,17,16,15,14,13,6,5,4,3,2,1,12,11,10,9,8,7,0);
else /* 0x3c000 - 0x3dfff and 0x3e000 - 0x3ffff */ // 512x32 bitmap (x2) -> tiles
- offset = BITSWAP24(offset,23,22,21,20,19,18,17,16,15,14,13,12,5,4,3,2,1,11,10,9,8,7,6,0);
+ offset = bitswap<24>(offset,23,22,21,20,19,18,17,16,15,14,13,12,5,4,3,2,1,11,10,9,8,7,6,0);
offset &=0xffff;
// HOTA cares about this
diff --git a/src/mame/machine/mexico86.cpp b/src/mame/machine/mexico86.cpp
index e473811aae6..cdbccf080a8 100644
--- a/src/mame/machine/mexico86.cpp
+++ b/src/mame/machine/mexico86.cpp
@@ -106,8 +106,8 @@ void mexico86_state::mcu_simulate( )
m_protection_ram[0x04] = 0x3c | (coin_in_read ^ 3); // coin inputs
- m_protection_ram[0x02] = BITSWAP8(ioport("IN1")->read(), 7,6,5,4,2,3,1,0); // player 1
- m_protection_ram[0x03] = BITSWAP8(ioport("IN2")->read(), 7,6,5,4,2,3,1,0); // player 2
+ m_protection_ram[0x02] = bitswap<8>(ioport("IN1")->read(), 7,6,5,4,2,3,1,0); // player 1
+ m_protection_ram[0x03] = bitswap<8>(ioport("IN2")->read(), 7,6,5,4,2,3,1,0); // player 2
if (m_protection_ram[0x19] == 0xaa) // player 2 active
m_protection_ram[0x1b] = m_protection_ram[0x03];
diff --git a/src/mame/machine/mpu4.cpp b/src/mame/machine/mpu4.cpp
index d6718c4b4c3..e972a5b2649 100644
--- a/src/mame/machine/mpu4.cpp
+++ b/src/mame/machine/mpu4.cpp
@@ -2567,13 +2567,13 @@ static void descramble_crystal( uint8_t* region, int start, int end, uint8_t ext
switch (i & 0x58)
{
case 0x00: // same as 0x08
- case 0x08: x = BITSWAP8( x^0xca , 3,2,1,0,7,4,6,5 ); break;
- case 0x10: x = BITSWAP8( x^0x30 , 3,0,4,6,1,5,7,2 ); break;
- case 0x18: x = BITSWAP8( x^0x89 , 4,1,2,5,7,0,6,3 ); break;
- case 0x40: x = BITSWAP8( x^0x14 , 6,1,4,3,2,5,0,7 ); break;
- case 0x48: x = BITSWAP8( x^0x40 , 1,0,3,2,5,4,7,6 ); break;
- case 0x50: x = BITSWAP8( x^0xcb , 3,2,1,0,7,6,5,4 ); break;
- case 0x58: x = BITSWAP8( x^0xc0 , 2,3,6,0,5,1,7,4 ); break;
+ case 0x08: x = bitswap<8>( x^0xca , 3,2,1,0,7,4,6,5 ); break;
+ case 0x10: x = bitswap<8>( x^0x30 , 3,0,4,6,1,5,7,2 ); break;
+ case 0x18: x = bitswap<8>( x^0x89 , 4,1,2,5,7,0,6,3 ); break;
+ case 0x40: x = bitswap<8>( x^0x14 , 6,1,4,3,2,5,0,7 ); break;
+ case 0x48: x = bitswap<8>( x^0x40 , 1,0,3,2,5,4,7,6 ); break;
+ case 0x50: x = bitswap<8>( x^0xcb , 3,2,1,0,7,6,5,4 ); break;
+ case 0x58: x = bitswap<8>( x^0xc0 , 2,3,6,0,5,1,7,4 ); break;
}
region[i] = x ^ extra_xor;
}
@@ -3087,7 +3087,7 @@ MACHINE_CONFIG_START( mpu4base )
MCFG_MACHINE_START_OVERRIDE(mpu4_state,mod2 )
MCFG_MACHINE_RESET_OVERRIDE(mpu4_state,mpu4)
- MCFG_CPU_ADD("maincpu", M6809, MPU4_MASTER_CLOCK/4)
+ MCFG_CPU_ADD("maincpu", MC6809, MPU4_MASTER_CLOCK) // MC68B09P
MCFG_CPU_PROGRAM_MAP(mpu4_memmap)
MCFG_FRAGMENT_ADD(mpu4_common)
diff --git a/src/mame/machine/pacplus.cpp b/src/mame/machine/pacplus.cpp
index 981ab9af96c..67e09c92552 100644
--- a/src/mame/machine/pacplus.cpp
+++ b/src/mame/machine/pacplus.cpp
@@ -37,7 +37,7 @@ uint8_t pacman_state::pacplus_decrypt(int addr, uint8_t e)
method ^= 1;
tbl = swap_xor_table[method];
- return BITSWAP8(e,tbl[0],tbl[1],tbl[2],tbl[3],tbl[4],tbl[5],tbl[6],tbl[7]) ^ tbl[8];
+ return bitswap<8>(e,tbl[0],tbl[1],tbl[2],tbl[3],tbl[4],tbl[5],tbl[6],tbl[7]) ^ tbl[8];
}
diff --git a/src/mame/machine/pgm2_memcard.cpp b/src/mame/machine/pgm2_memcard.cpp
new file mode 100644
index 00000000000..e8fee19f474
--- /dev/null
+++ b/src/mame/machine/pgm2_memcard.cpp
@@ -0,0 +1,149 @@
+// license:BSD-3-Clause
+// copyright-holders:David Haywood, Miodrag Milanovic
+/*********************************************************************
+
+ pgm2_memcard.cpp
+
+ PGM2 Memory card functions.
+ Presumable Siemens SLE 4442 or compatible.
+
+*********************************************************************/
+
+#include "emu.h"
+#include "emuopts.h"
+
+#include "pgm2_memcard.h"
+
+
+// device type definition
+DEFINE_DEVICE_TYPE(PGM2_MEMCARD, pgm2_memcard_device, "pgm2_memcard", "PGM2 Memory Card")
+
+//-------------------------------------------------
+// pgm2_memcard_device - constructor
+//-------------------------------------------------
+
+pgm2_memcard_device::pgm2_memcard_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
+ : device_t(mconfig, PGM2_MEMCARD, tag, owner, clock)
+ , device_image_interface(mconfig, *this)
+{
+}
+
+
+//-------------------------------------------------
+// device_start - device-specific startup
+//-------------------------------------------------
+
+void pgm2_memcard_device::device_start()
+{
+ save_item(NAME(m_memcard_data));
+}
+
+/*-------------------------------------------------
+ memcard_insert - insert an existing memory card
+ with the given index
+-------------------------------------------------*/
+
+image_init_result pgm2_memcard_device::call_load()
+{
+ authenticated = false;
+ if(length() != 0x108)
+ return image_init_result::FAIL;
+
+ fseek(0, SEEK_SET);
+ size_t ret = fread(m_memcard_data, 0x100);
+ if(ret != 0x100)
+ return image_init_result::FAIL;
+ ret = fread(m_protection_data, 4);
+ if (ret != 4)
+ return image_init_result::FAIL;
+ ret = fread(m_security_data, 4);
+ if (ret != 4)
+ return image_init_result::FAIL;
+
+ return image_init_result::PASS;
+}
+
+void pgm2_memcard_device::call_unload()
+{
+ authenticated = false;
+ fseek(0, SEEK_SET);
+ fwrite(m_memcard_data, 0x100);
+ fwrite(m_protection_data, 4);
+ fwrite(m_security_data, 4);
+}
+
+image_init_result pgm2_memcard_device::call_create(int format_type, util::option_resolution *format_options)
+{
+ authenticated = false;
+ // cards must contain valid defaults for each game / region or they don't work?
+ memory_region *rgn = memregion("^default_card");
+
+ if (!rgn)
+ return image_init_result::FAIL;
+
+ memcpy(m_memcard_data, rgn->base(), 0x100);
+ memcpy(m_protection_data, rgn->base() + 0x100, 4);
+ memcpy(m_security_data, rgn->base() + 0x104, 4);
+
+ size_t ret = fwrite(rgn->base(), 0x108);
+ if(ret != 0x108)
+ return image_init_result::FAIL;
+
+ return image_init_result::PASS;
+}
+
+void pgm2_memcard_device::auth(uint8_t p1, uint8_t p2, uint8_t p3)
+{
+ if (m_security_data[0] & 7)
+ {
+ if (m_security_data[1] == p1 && m_security_data[2] == p2 && m_security_data[3] == p3) {
+ authenticated = true;
+ m_security_data[0] = 7;
+ }
+ else {
+ authenticated = false;
+ m_security_data[0] >>= 1; // hacky
+ if (m_security_data[0] & 7)
+ popmessage("Wrong IC Card password !!!\n");
+ else
+ popmessage("Wrong IC Card password, card was locked!!!\n");
+ }
+ }
+}
+
+READ8_MEMBER(pgm2_memcard_device::read)
+{
+ return m_memcard_data[offset];
+}
+
+WRITE8_MEMBER(pgm2_memcard_device::write)
+{
+ if (authenticated && (offset >= 0x20 || (m_protection_data[offset>>3] & (1 <<(offset & 7)))))
+ {
+ m_memcard_data[offset] = data;
+ }
+}
+
+READ8_MEMBER(pgm2_memcard_device::read_prot)
+{
+ return m_protection_data[offset];
+}
+
+WRITE8_MEMBER(pgm2_memcard_device::write_prot)
+{
+ if (authenticated)
+ m_protection_data[offset] &= data;
+}
+
+READ8_MEMBER(pgm2_memcard_device::read_sec)
+{
+ if (!authenticated)
+ return 0xff; // guess
+ return m_security_data[offset];
+}
+
+WRITE8_MEMBER(pgm2_memcard_device::write_sec)
+{
+ if (authenticated)
+ m_security_data[offset] = data;
+}
diff --git a/src/mame/machine/pgm2_memcard.h b/src/mame/machine/pgm2_memcard.h
new file mode 100644
index 00000000000..175abe2d4fb
--- /dev/null
+++ b/src/mame/machine/pgm2_memcard.h
@@ -0,0 +1,75 @@
+// license:BSD-3-Clause
+// copyright-holders:David Haywood, Miodrag Milanovic
+/*********************************************************************
+
+ pgm2_memcard.h
+
+ PGM2 Memory card functions.
+ (based on ng_memcard.h)
+
+*********************************************************************/
+#ifndef MAME_MACHINE_PGM2_MEMCARD_H
+#define MAME_MACHINE_PGM2_MEMCARD_H
+
+#pragma once
+
+
+//**************************************************************************
+// INTERFACE CONFIGURATION MACROS
+//**************************************************************************
+
+#define MCFG_PGM2_MEMCARD_ADD(_tag) \
+ MCFG_DEVICE_ADD(_tag, PGM2_MEMCARD, 0)
+
+/***************************************************************************
+ FUNCTION PROTOTYPES
+***************************************************************************/
+
+// ======================> pgm2_memcard_device
+
+class pgm2_memcard_device : public device_t,
+ public device_image_interface
+{
+public:
+ // construction/destruction
+ pgm2_memcard_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
+
+ virtual iodevice_t image_type() const override { return IO_MEMCARD; }
+
+ virtual bool is_readable() const override { return true; }
+ virtual bool is_writeable() const override { return true; }
+ virtual bool is_creatable() const override { return true; }
+ virtual bool must_be_loaded() const override { return false; }
+ virtual bool is_reset_on_load() const override { return false; }
+ virtual const char *file_extensions() const override { return "pg2,bin,mem"; }
+
+ virtual image_init_result call_load() override;
+ virtual void call_unload() override;
+ virtual image_init_result call_create(int format_type, util::option_resolution *format_options) override;
+
+ // device-level overrides
+ virtual void device_start() override;
+
+ DECLARE_READ8_MEMBER(read);
+ DECLARE_WRITE8_MEMBER(write);
+ DECLARE_READ8_MEMBER(read_prot);
+ DECLARE_WRITE8_MEMBER(write_prot);
+ DECLARE_READ8_MEMBER(read_sec);
+ DECLARE_WRITE8_MEMBER(write_sec);
+ void auth(uint8_t p1, uint8_t p2, uint8_t p3);
+
+ /* returns the index of the current memory card, or -1 if none */
+ int present() { return is_loaded() ? 0 : -1; }
+private:
+ uint8_t m_memcard_data[0x100];
+ uint8_t m_protection_data[4];
+ uint8_t m_security_data[4];
+ bool authenticated;
+};
+
+
+// device type definition
+DECLARE_DEVICE_TYPE(PGM2_MEMCARD, pgm2_memcard_device)
+
+
+#endif // MAME_MACHINE_PGM2_MEMCARD_H
diff --git a/src/mame/machine/pgmprot_igs027a_type1.cpp b/src/mame/machine/pgmprot_igs027a_type1.cpp
index adfa59a023f..943b3108474 100644
--- a/src/mame/machine/pgmprot_igs027a_type1.cpp
+++ b/src/mame/machine/pgmprot_igs027a_type1.cpp
@@ -375,9 +375,9 @@ void pgm_arm_type1_state::pgm_decode_kovlsqh2_tiles()
for (i = 0; i < 0x800000 / 2; i++)
{
- j = BITSWAP24(i, 23, 22, 9, 8, 21, 18, 0, 1, 2, 3, 16, 15, 14, 13, 12, 11, 10, 19, 20, 17, 7, 6, 5, 4);
+ j = bitswap<24>(i, 23, 22, 9, 8, 21, 18, 0, 1, 2, 3, 16, 15, 14, 13, 12, 11, 10, 19, 20, 17, 7, 6, 5, 4);
- dst[j] = BITSWAP16(src[i], 1, 14, 8, 7, 0, 15, 6, 9, 13, 2, 5, 10, 12, 3, 4, 11);
+ dst[j] = bitswap<16>(src[i], 1, 14, 8, 7, 0, 15, 6, 9, 13, 2, 5, 10, 12, 3, 4, 11);
}
memcpy( src, &dst[0], 0x800000 );
@@ -390,7 +390,7 @@ void pgm_arm_type1_state::pgm_decode_kovlsqh2_sprites( uint8_t *src )
for (i = 0; i < 0x800000; i++)
{
- j = BITSWAP24(i, 23, 10, 9, 22, 19, 18, 20, 21, 17, 16, 15, 14, 13, 12, 11, 8, 7, 6, 5, 4, 3, 2, 1, 0);
+ j = bitswap<24>(i, 23, 10, 9, 22, 19, 18, 20, 21, 17, 16, 15, 14, 13, 12, 11, 8, 7, 6, 5, 4, 3, 2, 1, 0);
dst[j] = src[i];
}
@@ -418,9 +418,9 @@ void pgm_arm_type1_state::pgm_decode_kovqhsgs_program()
for (i = 0; i < 0x400000 / 2; i++)
{
- int j = BITSWAP24(i, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 6, 7, 5, 4, 3, 2, 1, 0);
+ int j = bitswap<24>(i, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 6, 7, 5, 4, 3, 2, 1, 0);
- dst[j] = BITSWAP16(src[i], 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 4, 5, 3, 2, 1, 0);
+ dst[j] = bitswap<16>(src[i], 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 4, 5, 3, 2, 1, 0);
}
memcpy( src, &dst[0], 0x400000 );
@@ -434,7 +434,7 @@ void pgm_arm_type1_state::pgm_decode_kovqhsgs2_program()
for (i = 0; i < 0x400000 / 2; i++)
{
- int j = BITSWAP24(i, 23, 22, 21, 20, 19, 16, 15, 14, 13, 12, 11, 10, 9, 8, 0, 1, 2, 3, 4, 5, 6, 18, 17, 7);
+ int j = bitswap<24>(i, 23, 22, 21, 20, 19, 16, 15, 14, 13, 12, 11, 10, 9, 8, 0, 1, 2, 3, 4, 5, 6, 18, 17, 7);
dst[j] = src[i];
}
diff --git a/src/mame/machine/pgmprot_igs027a_type3.cpp b/src/mame/machine/pgmprot_igs027a_type3.cpp
index 5dd50881dfb..2a7860b8c8b 100644
--- a/src/mame/machine/pgmprot_igs027a_type3.cpp
+++ b/src/mame/machine/pgmprot_igs027a_type3.cpp
@@ -727,7 +727,7 @@ DRIVER_INIT_MEMBER(pgm_arm_type3_state,dmnfrnt)
}
//
-// int j = BITSWAP24(i, 23, 20, 17, 16, 19, 18, 15, 14, 13, 12, 11, 10, 9, 22, 21, 6, 7, 6, 5, 4, 3, 2, 1, 0);
+// int j = bitswap<24>(i, 23, 20, 17, 16, 19, 18, 15, 14, 13, 12, 11, 10, 9, 22, 21, 6, 7, 6, 5, 4, 3, 2, 1, 0);
// buffer[i] = src[j]
// todo, collapse these to an address swap
diff --git a/src/mame/machine/pgmprot_orlegend.cpp b/src/mame/machine/pgmprot_orlegend.cpp
index 9f6d6aa5aff..6961d24a093 100644
--- a/src/mame/machine/pgmprot_orlegend.cpp
+++ b/src/mame/machine/pgmprot_orlegend.cpp
@@ -61,7 +61,7 @@ READ16_MEMBER(pgm_asic3_state::pgm_asic3_r)
return (m_asic3_latch[2] & 0x7f) | ((ioport("Region")->read() << 6) & 0x80);
case 0x03:
- return BITSWAP8(m_asic3_hold, 5,2,9,7,10,13,12,15);
+ return bitswap<8>(m_asic3_hold, 5,2,9,7,10,13,12,15);
// case $157674, expected return $157686
case 0x20: return 0x49; // "IGS"
diff --git a/src/mame/machine/r2crypt.cpp b/src/mame/machine/r2crypt.cpp
index 3101c690f8c..ad297181bc8 100644
--- a/src/mame/machine/r2crypt.cpp
+++ b/src/mame/machine/r2crypt.cpp
@@ -212,10 +212,10 @@ static uint16_t gm(int i4)
static uint32_t core_decrypt(uint32_t ciphertext, int i1, int i2, int i3, int i4,
const uint8_t *rotate, const uint8_t *x5, const uint16_t *x11, uint32_t preXor, uint32_t carryMask, uint32_t postXor)
{
- uint32_t v1 = BITSWAP32(yrot(ciphertext, rotate[i1]), 25,28,15,19, 6,0,3,24, 11,1,2,30, 16,7,22,17, 31,14,23,9, 27,18,4,10, 13,20,5,12, 8,29,26,21);
+ uint32_t v1 = bitswap<32>(yrot(ciphertext, rotate[i1]), 25,28,15,19, 6,0,3,24, 11,1,2,30, 16,7,22,17, 31,14,23,9, 27,18,4,10, 13,20,5,12, 8,29,26,21);
uint16_t x1Low = (x5[i2]<<11) ^ x11[i3] ^ gm(i4);
- uint32_t x1 = x1Low | (BITSWAP16(x1Low, 0,8,1,9, 2,10,3,11, 4,12,5,13, 6,14,7,15)<<16);
+ uint32_t x1 = x1Low | (bitswap<16>(x1Low, 0,8,1,9, 2,10,3,11, 4,12,5,13, 6,14,7,15)<<16);
return partial_carry_sum32(v1, x1^preXor, carryMask) ^ postXor;
}
diff --git a/src/mame/machine/scramble.cpp b/src/mame/machine/scramble.cpp
index 2a6f978276b..0684f07a64d 100644
--- a/src/mame/machine/scramble.cpp
+++ b/src/mame/machine/scramble.cpp
@@ -183,12 +183,12 @@ DRIVER_INIT_MEMBER(scramble_state,frogger)
/* the first ROM of the second CPU has data lines D0 and D1 swapped. Decode it. */
ROM = memregion("audiocpu")->base();
for (A = 0;A < 0x0800;A++)
- ROM[A] = BITSWAP8(ROM[A],7,6,5,4,3,2,0,1);
+ ROM[A] = bitswap<8>(ROM[A],7,6,5,4,3,2,0,1);
/* likewise, the 2nd gfx ROM has data lines D0 and D1 swapped. Decode it. */
ROM = memregion("gfx1")->base();
for (A = 0x0800;A < 0x1000;A++)
- ROM[A] = BITSWAP8(ROM[A],7,6,5,4,3,2,0,1);
+ ROM[A] = bitswap<8>(ROM[A],7,6,5,4,3,2,0,1);
}
DRIVER_INIT_MEMBER(scramble_state,froggers)
@@ -199,7 +199,7 @@ DRIVER_INIT_MEMBER(scramble_state,froggers)
/* the first ROM of the second CPU has data lines D0 and D1 swapped. Decode it. */
ROM = memregion("audiocpu")->base();
for (A = 0;A < 0x0800;A++)
- ROM[A] = BITSWAP8(ROM[A],7,6,5,4,3,2,0,1);
+ ROM[A] = bitswap<8>(ROM[A],7,6,5,4,3,2,0,1);
}
#endif
@@ -223,7 +223,7 @@ DRIVER_INIT_MEMBER(scramble_state,devilfsh)
for (j = 0; j < 16; j++)
{
- offs_t newval = BITSWAP8(j,7,6,5,4,2,0,3,1);
+ offs_t newval = bitswap<8>(j,7,6,5,4,2,0,3,1);
swapbuffer[j] = RAM[i + newval];
}
@@ -502,7 +502,7 @@ DRIVER_INIT_MEMBER(scramble_state,hustler)
for (A = 0;A < 0x0800;A++)
- rom[A] = BITSWAP8(rom[A],7,6,5,4,3,2,0,1);
+ rom[A] = bitswap<8>(rom[A],7,6,5,4,3,2,0,1);
}
}
@@ -514,7 +514,7 @@ DRIVER_INIT_MEMBER(scramble_state,hustlerd)
for (A = 0;A < 0x0800;A++)
- rom[A] = BITSWAP8(rom[A],7,6,5,4,3,2,0,1);
+ rom[A] = bitswap<8>(rom[A],7,6,5,4,3,2,0,1);
}
DRIVER_INIT_MEMBER(scramble_state,billiard)
@@ -545,7 +545,7 @@ DRIVER_INIT_MEMBER(scramble_state,billiard)
rom[A] ^= xormask;
- rom[A] = BITSWAP8(rom[A],6,1,2,5,4,3,0,7);
+ rom[A] = bitswap<8>(rom[A],6,1,2,5,4,3,0,7);
}
/* the first ROM of the second CPU has data lines D0 and D1 swapped. Decode it. */
@@ -554,7 +554,7 @@ DRIVER_INIT_MEMBER(scramble_state,billiard)
for (A = 0;A < 0x0800;A++)
- rom[A] = BITSWAP8(rom[A],7,6,5,4,3,2,0,1);
+ rom[A] = bitswap<8>(rom[A],7,6,5,4,3,2,0,1);
}
}
@@ -580,7 +580,7 @@ DRIVER_INIT_MEMBER(scramble_state,ad2083)
for (i=0; i<len; i++)
{
c = ROM[i] ^ 0x35;
- c = BITSWAP8(c, 6,2,5,1,7,3,4,0); /* also swapped inside of the bigger module */
+ c = bitswap<8>(c, 6,2,5,1,7,3,4,0); /* also swapped inside of the bigger module */
ROM[i] = c;
}
}
@@ -650,24 +650,24 @@ DRIVER_INIT_MEMBER(scramble_state,harem)
for (int i = 0; i < size; i++)
{
uint8_t x = ROM[i];
- opcodes[size * 0 + i] = BITSWAP8(x, 7,0,5,2,3,4,1,6);
- data [size * 0 + i] = BITSWAP8(x, 7,6,5,0,3,4,1,2);
+ opcodes[size * 0 + i] = bitswap<8>(x, 7,0,5,2,3,4,1,6);
+ data [size * 0 + i] = bitswap<8>(x, 7,6,5,0,3,4,1,2);
}
// decryption 09
for (int i = 0; i < size; i++)
{
uint8_t x = ROM[i];
- opcodes[size * 1 + i] = BITSWAP8(x, 7,0,5,6,3,2,1,4);
- data [size * 1 + i] = BITSWAP8(x, 7,4,5,0,3,6,1,2);
+ opcodes[size * 1 + i] = bitswap<8>(x, 7,0,5,6,3,2,1,4);
+ data [size * 1 + i] = bitswap<8>(x, 7,4,5,0,3,6,1,2);
}
// decryption 0a
for (int i = 0; i < size; i++)
{
uint8_t x = ROM[i];
- opcodes[size * 2 + i] = BITSWAP8(x, 7,2,5,6,3,0,1,4);
- data [size * 2 + i] = BITSWAP8(x, 7,2,5,4,3,0,1,6);
+ opcodes[size * 2 + i] = bitswap<8>(x, 7,2,5,6,3,0,1,4);
+ data [size * 2 + i] = bitswap<8>(x, 7,2,5,4,3,0,1,6);
}
membank("rombank")->set_base (m_harem_decrypted_data.get());
diff --git a/src/mame/machine/segacrp2_device.cpp b/src/mame/machine/segacrp2_device.cpp
index 2ac88287eeb..38cebe5815c 100644
--- a/src/mame/machine/segacrp2_device.cpp
+++ b/src/mame/machine/segacrp2_device.cpp
@@ -76,11 +76,11 @@ static void decode(uint8_t *rom, uint8_t *decrypted,
/* decode the opcodes */
tbl = swaptable[swap_table[2*row]];
- decrypted[A] = BITSWAP8(src,7,tbl[0],5,tbl[1],3,tbl[2],1,tbl[3]) ^ xor_table[2*row];
+ decrypted[A] = bitswap<8>(src,7,tbl[0],5,tbl[1],3,tbl[2],1,tbl[3]) ^ xor_table[2*row];
/* decode the data */
tbl = swaptable[swap_table[2*row+1]];
- rom[A] = BITSWAP8(src,7,tbl[0],5,tbl[1],3,tbl[2],1,tbl[3]) ^ xor_table[2*row+1];
+ rom[A] = bitswap<8>(src,7,tbl[0],5,tbl[1],3,tbl[2],1,tbl[3]) ^ xor_table[2*row+1];
}
}
diff --git a/src/mame/machine/segas32.cpp b/src/mame/machine/segas32.cpp
index debf07501dd..2424a498d00 100644
--- a/src/mame/machine/segas32.cpp
+++ b/src/mame/machine/segas32.cpp
@@ -46,7 +46,7 @@ void segas32_v25_state::decrypt_protrom()
// unscramble the address lines
for(i = 0; i < 0x10000; i++)
- rom[i] = temp[BITSWAP16(i, 14, 11, 15, 12, 13, 4, 3, 7, 5, 10, 2, 8, 9, 6, 1, 0)];
+ rom[i] = temp[bitswap<16>(i, 14, 11, 15, 12, 13, 4, 3, 7, 5, 10, 2, 8, 9, 6, 1, 0)];
}
diff --git a/src/mame/machine/seibuspi.cpp b/src/mame/machine/seibuspi.cpp
index 316e73384ae..d27ff9a39c1 100644
--- a/src/mame/machine/seibuspi.cpp
+++ b/src/mame/machine/seibuspi.cpp
@@ -171,7 +171,7 @@ void seibuspi_sprite_decrypt(uint8_t *src, int rom_size)
/* first of all, permutate 16 of the 48 bits */
bs = spi_bitswap[key_table[addr & 0xff]&0xf];
- y3 = BITSWAP16(y3, bs[0],bs[1],bs[2],bs[3],bs[4],bs[5],bs[6],bs[7],
+ y3 = bitswap<16>(y3, bs[0],bs[1],bs[2],bs[3],bs[4],bs[5],bs[6],bs[7],
bs[8],bs[9],bs[10],bs[11],bs[12],bs[13],bs[14],bs[15]);
@@ -350,7 +350,7 @@ void seibuspi_rise10_sprite_decrypt(uint8_t *rom, int size)
uint32_t plane54,plane3210;
plane54 = rom[0*size+2*i] + (rom[0*size+2*i+1] << 8);
- plane3210 = BITSWAP32(
+ plane3210 = bitswap<32>(
rom[2*size+2*i] + (rom[2*size+2*i+1] << 8) + (rom[1*size+2*i] << 16) + (rom[1*size+2*i+1] << 24),
23,13,24,4,16,12,25,30,
3,5,29,17,14,22,2,11,
diff --git a/src/mame/machine/subsino.cpp b/src/mame/machine/subsino.cpp
index 06cf7901e95..507616ca7c1 100644
--- a/src/mame/machine/subsino.cpp
+++ b/src/mame/machine/subsino.cpp
@@ -20,50 +20,50 @@ extern const uint8_t victor21_xors[8] = { 0x44, 0xbb, 0x66, 0x44, 0xaa, 0x55, 0x
void crsbingo_bitswaps(uint8_t *decrypt, int i)
{
- if ((i&7) == 0) decrypt[i] = BITSWAP8(decrypt[i], 7,2,5,4,3,6,1,0 );
- if ((i&7) == 1) decrypt[i] = BITSWAP8(decrypt[i], 7,2,1,0,3,6,5,4 );
- if ((i&7) == 2) decrypt[i] = BITSWAP8(decrypt[i], 3,2,5,0,7,6,1,4 );
- if ((i&7) == 3) decrypt[i] = BITSWAP8(decrypt[i], 7,2,5,0,3,6,1,4 );
- if ((i&7) == 4) decrypt[i] = BITSWAP8(decrypt[i], 7,6,5,0,3,2,1,4 );
- if ((i&7) == 5) decrypt[i] = BITSWAP8(decrypt[i], 7,2,1,4,3,6,5,0 );
- if ((i&7) == 6) decrypt[i] = BITSWAP8(decrypt[i], 7,2,1,0,3,6,5,4 );
- if ((i&7) == 7) decrypt[i] = BITSWAP8(decrypt[i], 3,2,1,0,7,6,5,4 );
+ if ((i&7) == 0) decrypt[i] = bitswap<8>(decrypt[i], 7,2,5,4,3,6,1,0 );
+ if ((i&7) == 1) decrypt[i] = bitswap<8>(decrypt[i], 7,2,1,0,3,6,5,4 );
+ if ((i&7) == 2) decrypt[i] = bitswap<8>(decrypt[i], 3,2,5,0,7,6,1,4 );
+ if ((i&7) == 3) decrypt[i] = bitswap<8>(decrypt[i], 7,2,5,0,3,6,1,4 );
+ if ((i&7) == 4) decrypt[i] = bitswap<8>(decrypt[i], 7,6,5,0,3,2,1,4 );
+ if ((i&7) == 5) decrypt[i] = bitswap<8>(decrypt[i], 7,2,1,4,3,6,5,0 );
+ if ((i&7) == 6) decrypt[i] = bitswap<8>(decrypt[i], 7,2,1,0,3,6,5,4 );
+ if ((i&7) == 7) decrypt[i] = bitswap<8>(decrypt[i], 3,2,1,0,7,6,5,4 );
}
void sharkpy_bitswaps(uint8_t *decrypt, int i)
{
- if ((i&7) == 0) decrypt[i] = BITSWAP8(decrypt[i], 3,2,1,0,7,6,5,4 );
- if ((i&7) == 1) decrypt[i] = BITSWAP8(decrypt[i], 7,2,5,4,3,6,1,0 );
- if ((i&7) == 2) decrypt[i] = BITSWAP8(decrypt[i], 7,2,1,4,3,6,5,0 );
- if ((i&7) == 3) decrypt[i] = BITSWAP8(decrypt[i], 3,6,1,0,7,2,5,4 );
- if ((i&7) == 4) decrypt[i] = BITSWAP8(decrypt[i], 7,2,5,4,3,6,1,0 );
- if ((i&7) == 5) decrypt[i] = BITSWAP8(decrypt[i], 3,2,5,4,7,6,1,0 );
- if ((i&7) == 6) decrypt[i] = BITSWAP8(decrypt[i], 7,6,1,4,3,2,5,0 );
- if ((i&7) == 7) decrypt[i] = BITSWAP8(decrypt[i], 3,6,1,4,7,2,5,0 );
+ if ((i&7) == 0) decrypt[i] = bitswap<8>(decrypt[i], 3,2,1,0,7,6,5,4 );
+ if ((i&7) == 1) decrypt[i] = bitswap<8>(decrypt[i], 7,2,5,4,3,6,1,0 );
+ if ((i&7) == 2) decrypt[i] = bitswap<8>(decrypt[i], 7,2,1,4,3,6,5,0 );
+ if ((i&7) == 3) decrypt[i] = bitswap<8>(decrypt[i], 3,6,1,0,7,2,5,4 );
+ if ((i&7) == 4) decrypt[i] = bitswap<8>(decrypt[i], 7,2,5,4,3,6,1,0 );
+ if ((i&7) == 5) decrypt[i] = bitswap<8>(decrypt[i], 3,2,5,4,7,6,1,0 );
+ if ((i&7) == 6) decrypt[i] = bitswap<8>(decrypt[i], 7,6,1,4,3,2,5,0 );
+ if ((i&7) == 7) decrypt[i] = bitswap<8>(decrypt[i], 3,6,1,4,7,2,5,0 );
}
void victor5_bitswaps(uint8_t *decrypt, int i)
{
- if ((i&7) == 0) decrypt[i] = BITSWAP8(decrypt[i], 7,2,5,4,3,6,1,0 );
- if ((i&7) == 1) decrypt[i] = BITSWAP8(decrypt[i], 7,6,5,0,3,2,1,4 );
- if ((i&7) == 2) decrypt[i] = BITSWAP8(decrypt[i], 7,2,1,0,3,6,5,4 );
- if ((i&7) == 3) decrypt[i] = BITSWAP8(decrypt[i], 7,2,1,0,3,6,5,4 );
- if ((i&7) == 4) decrypt[i] = BITSWAP8(decrypt[i], 3,2,1,0,7,6,5,4 );
- if ((i&7) == 5) decrypt[i] = BITSWAP8(decrypt[i], 7,6,5,0,3,2,1,4 );
- if ((i&7) == 6) decrypt[i] = BITSWAP8(decrypt[i], 3,6,1,0,7,2,5,4 );
- if ((i&7) == 7) decrypt[i] = BITSWAP8(decrypt[i], 7,2,1,4,3,6,5,0 );
+ if ((i&7) == 0) decrypt[i] = bitswap<8>(decrypt[i], 7,2,5,4,3,6,1,0 );
+ if ((i&7) == 1) decrypt[i] = bitswap<8>(decrypt[i], 7,6,5,0,3,2,1,4 );
+ if ((i&7) == 2) decrypt[i] = bitswap<8>(decrypt[i], 7,2,1,0,3,6,5,4 );
+ if ((i&7) == 3) decrypt[i] = bitswap<8>(decrypt[i], 7,2,1,0,3,6,5,4 );
+ if ((i&7) == 4) decrypt[i] = bitswap<8>(decrypt[i], 3,2,1,0,7,6,5,4 );
+ if ((i&7) == 5) decrypt[i] = bitswap<8>(decrypt[i], 7,6,5,0,3,2,1,4 );
+ if ((i&7) == 6) decrypt[i] = bitswap<8>(decrypt[i], 3,6,1,0,7,2,5,4 );
+ if ((i&7) == 7) decrypt[i] = bitswap<8>(decrypt[i], 7,2,1,4,3,6,5,0 );
}
void victor21_bitswaps(uint8_t *decrypt, int i)
{
- if ((i&7) == 0) decrypt[i] = BITSWAP8(decrypt[i], 7,2,1,0,3,6,5,4 );
- if ((i&7) == 1) decrypt[i] = BITSWAP8(decrypt[i], 3,6,1,4,7,2,5,0 );
- if ((i&7) == 2) decrypt[i] = BITSWAP8(decrypt[i], 3,2,1,4,7,6,5,0 );
- if ((i&7) == 3) decrypt[i] = BITSWAP8(decrypt[i], 7,2,5,4,3,6,1,0 );
- if ((i&7) == 4) decrypt[i] = BITSWAP8(decrypt[i], 7,2,5,4,3,6,1,0 );
- if ((i&7) == 5) decrypt[i] = BITSWAP8(decrypt[i], 3,6,5,0,7,2,1,4 );
- if ((i&7) == 6) decrypt[i] = BITSWAP8(decrypt[i], 7,6,5,4,3,2,1,0 );
- if ((i&7) == 7) decrypt[i] = BITSWAP8(decrypt[i], 3,2,1,4,7,6,5,0 );
+ if ((i&7) == 0) decrypt[i] = bitswap<8>(decrypt[i], 7,2,1,0,3,6,5,4 );
+ if ((i&7) == 1) decrypt[i] = bitswap<8>(decrypt[i], 3,6,1,4,7,2,5,0 );
+ if ((i&7) == 2) decrypt[i] = bitswap<8>(decrypt[i], 3,2,1,4,7,6,5,0 );
+ if ((i&7) == 3) decrypt[i] = bitswap<8>(decrypt[i], 7,2,5,4,3,6,1,0 );
+ if ((i&7) == 4) decrypt[i] = bitswap<8>(decrypt[i], 7,2,5,4,3,6,1,0 );
+ if ((i&7) == 5) decrypt[i] = bitswap<8>(decrypt[i], 3,6,5,0,7,2,1,4 );
+ if ((i&7) == 6) decrypt[i] = bitswap<8>(decrypt[i], 7,6,5,4,3,2,1,0 );
+ if ((i&7) == 7) decrypt[i] = bitswap<8>(decrypt[i], 3,2,1,4,7,6,5,0 );
}
// Decrypt:
diff --git a/src/mame/machine/tatsumi.cpp b/src/mame/machine/tatsumi.cpp
index a17a33ee903..1fe523e217a 100644
--- a/src/mame/machine/tatsumi.cpp
+++ b/src/mame/machine/tatsumi.cpp
@@ -12,22 +12,19 @@ void tatsumi_state::tatsumi_reset()
{
m_last_control = 0;
m_control_word = 0;
- m_apache3_adc = 0;
- m_apache3_rot_idx = 0;
save_item(NAME(m_last_control));
save_item(NAME(m_control_word));
- save_item(NAME(m_apache3_adc));
}
/******************************************************************************/
-READ16_MEMBER(tatsumi_state::apache3_bank_r)
+READ16_MEMBER(apache3_state::apache3_bank_r)
{
return m_control_word;
}
-WRITE16_MEMBER(tatsumi_state::apache3_bank_w)
+WRITE16_MEMBER(apache3_state::apache3_bank_w)
{
/*
0x8000 - Set when accessing palette ram (not implemented, perhaps blank screen?)
@@ -60,12 +57,12 @@ WRITE16_MEMBER(tatsumi_state::apache3_bank_w)
// D1 = /ZBREQ - Z80 bus request
// D0 = /GRDACC - Allow 68000 access to road pattern RAM
-WRITE16_MEMBER(tatsumi_state::apache3_z80_ctrl_w)
+WRITE16_MEMBER(apache3_state::apache3_z80_ctrl_w)
{
m_subcpu2->set_input_line(INPUT_LINE_HALT, data & 2 ? ASSERT_LINE : CLEAR_LINE);
}
-READ16_MEMBER(tatsumi_state::apache3_v30_v20_r)
+READ16_MEMBER(apache3_state::apache3_v30_v20_r)
{
address_space &targetspace = m_audiocpu->space(AS_PROGRAM);
@@ -81,7 +78,7 @@ READ16_MEMBER(tatsumi_state::apache3_v30_v20_r)
return 0xff00 | targetspace.read_byte(offset);
}
-WRITE16_MEMBER(tatsumi_state::apache3_v30_v20_w)
+WRITE16_MEMBER(apache3_state::apache3_v30_v20_w)
{
address_space &targetspace = m_audiocpu->space(AS_PROGRAM);
@@ -95,17 +92,17 @@ WRITE16_MEMBER(tatsumi_state::apache3_v30_v20_w)
}
}
-READ16_MEMBER(tatsumi_state::apache3_z80_r)
+READ16_MEMBER(apache3_state::apache3_z80_r)
{
return m_apache3_z80_ram[offset];
}
-WRITE16_MEMBER(tatsumi_state::apache3_z80_w)
+WRITE16_MEMBER(apache3_state::apache3_z80_w)
{
m_apache3_z80_ram[offset] = data & 0xff;
}
-READ8_MEMBER(tatsumi_state::apache3_adc_r)
+READ8_MEMBER(apache3_state::apache3_adc_r)
{
switch (m_apache3_adc)
{
@@ -122,7 +119,7 @@ READ8_MEMBER(tatsumi_state::apache3_adc_r)
return 0;
}
-WRITE8_MEMBER(tatsumi_state::apache3_adc_w)
+WRITE8_MEMBER(apache3_state::apache3_adc_w)
{
m_apache3_adc = offset;
}
@@ -133,7 +130,7 @@ WRITE8_MEMBER(tatsumi_state::apache3_adc_w)
* presumably loaded into the 8 TZ2213 custom
* accumulators and counters.
*/
-WRITE16_MEMBER(tatsumi_state::apache3_rotate_w)
+WRITE16_MEMBER(apache3_state::apache3_rotate_w)
{
m_apache3_rotate_ctrl[m_apache3_rot_idx] = data;
m_apache3_rot_idx = (m_apache3_rot_idx + 1) % 12;
@@ -141,7 +138,7 @@ WRITE16_MEMBER(tatsumi_state::apache3_rotate_w)
/******************************************************************************/
-READ16_MEMBER(tatsumi_state::roundup_v30_z80_r)
+READ16_MEMBER(roundup5_state::roundup_v30_z80_r)
{
address_space &targetspace = m_audiocpu->space(AS_PROGRAM);
@@ -152,7 +149,7 @@ READ16_MEMBER(tatsumi_state::roundup_v30_z80_r)
return 0xff00 | targetspace.read_byte(offset);
}
-WRITE16_MEMBER(tatsumi_state::roundup_v30_z80_w)
+WRITE16_MEMBER(roundup5_state::roundup_v30_z80_w)
{
address_space &targetspace = m_audiocpu->space(AS_PROGRAM);
@@ -167,7 +164,7 @@ WRITE16_MEMBER(tatsumi_state::roundup_v30_z80_w)
}
-WRITE16_MEMBER(tatsumi_state::roundup5_control_w)
+WRITE16_MEMBER(roundup5_state::roundup5_control_w)
{
COMBINE_DATA(&m_control_word);
@@ -225,13 +222,13 @@ WRITE16_MEMBER(tatsumi_state::roundup5_control_w)
m_last_control = m_control_word;
}
-WRITE16_MEMBER(tatsumi_state::roundup5_d0000_w)
+WRITE16_MEMBER(roundup5_state::roundup5_d0000_w)
{
COMBINE_DATA(&m_roundup5_d0000_ram[offset]);
// logerror("d_68k_d0000_w %06x %04x\n", space.device().safe_pc(), data);
}
-WRITE16_MEMBER(tatsumi_state::roundup5_e0000_w)
+WRITE16_MEMBER(roundup5_state::roundup5_e0000_w)
{
/* Bit 0x10 is road bank select,
Bit 0x100 is used, but unknown
@@ -245,7 +242,7 @@ WRITE16_MEMBER(tatsumi_state::roundup5_e0000_w)
/******************************************************************************/
-WRITE8_MEMBER(tatsumi_state::cyclwarr_control_w)
+WRITE8_MEMBER(cyclwarr_state::cyclwarr_control_w)
{
m_control_word = data;
diff --git a/src/mame/machine/ticket.cpp b/src/mame/machine/ticket.cpp
index bb7c4481f98..2180d4fd17e 100644
--- a/src/mame/machine/ticket.cpp
+++ b/src/mame/machine/ticket.cpp
@@ -44,7 +44,6 @@ ticket_dispenser_device::ticket_dispenser_device(const machine_config &mconfig,
m_status_sense(TICKET_STATUS_ACTIVE_LOW),
m_period(attotime::from_msec(100)),
m_hopper_type(false),
- m_active_bit(0x80),
m_motoron(0),
m_ticketdispensed(0),
m_ticketnotdispensed(0),
@@ -99,19 +98,7 @@ void ticket_dispenser_device::static_set_senses(device_t &device, uint8_t motor_
//**************************************************************************
//-------------------------------------------------
-// read - read the status line via the active bit
-// (legacy method)
-//-------------------------------------------------
-
-READ8_MEMBER( ticket_dispenser_device::read )
-{
- LOG(("%s: Ticket Status Read = %02X\n", machine().describe_context(), m_status));
- return m_status;
-}
-
-
-//-------------------------------------------------
-// line_r - read the status line as a proper line
+// line_r - read the status line
//-------------------------------------------------
READ_LINE_MEMBER( ticket_dispenser_device::line_r )
@@ -121,20 +108,19 @@ READ_LINE_MEMBER( ticket_dispenser_device::line_r )
//-------------------------------------------------
-// write - write the control line via the active
-// bit (legacy method)
+// motor_w - write the control line
//-------------------------------------------------
-WRITE8_MEMBER( ticket_dispenser_device::write )
+WRITE_LINE_MEMBER( ticket_dispenser_device::motor_w )
{
// On an activate signal, start dispensing!
- if ((data & m_active_bit) == m_motoron)
+ if (bool(state) == m_motoron)
{
if (!m_power)
{
LOG(("%s: Ticket Power On\n", machine().describe_context()));
m_timer->adjust(m_period);
- m_power = 1;
+ m_power = true;
m_status = m_ticketnotdispensed;
}
}
@@ -148,21 +134,11 @@ WRITE8_MEMBER( ticket_dispenser_device::write )
m_timer->adjust(attotime::never);
machine().output().set_led_value(2, 0);
}
- m_power = 0;
+ m_power = false;
}
}
}
-//-------------------------------------------------
-// motor_w - write the control line as a proper
-// line
-//-------------------------------------------------
-
-WRITE_LINE_MEMBER( ticket_dispenser_device::motor_w )
-{
- write(machine().dummy_space(), 0, state ? m_active_bit : 0);
-}
-
//**************************************************************************
// DEVICE INTERFACE
@@ -174,10 +150,9 @@ WRITE_LINE_MEMBER( ticket_dispenser_device::motor_w )
void ticket_dispenser_device::device_start()
{
- m_active_bit = 0x80;
- m_motoron = (m_motor_sense == TICKET_MOTOR_ACTIVE_HIGH) ? m_active_bit : 0;
- m_ticketdispensed = (m_status_sense == TICKET_STATUS_ACTIVE_HIGH) ? m_active_bit : 0;
- m_ticketnotdispensed = m_ticketdispensed ^ m_active_bit;
+ m_motoron = (m_motor_sense == TICKET_MOTOR_ACTIVE_HIGH);
+ m_ticketdispensed = (m_status_sense == TICKET_STATUS_ACTIVE_HIGH);
+ m_ticketnotdispensed = !m_ticketdispensed;
m_timer = timer_alloc();
@@ -193,7 +168,7 @@ void ticket_dispenser_device::device_start()
void ticket_dispenser_device::device_reset()
{
m_status = m_ticketnotdispensed;
- m_power = 0x00;
+ m_power = false;
}
@@ -206,13 +181,13 @@ void ticket_dispenser_device::device_timer(emu_timer &timer, device_timer_id id,
// if we still have power, keep toggling ticket states
if (m_power)
{
- m_status ^= m_active_bit;
+ m_status = !m_status;
LOG(("Ticket Status Changed to %02X\n", m_status));
m_timer->adjust(m_period);
}
else if (m_hopper_type)
{
- m_status ^= m_active_bit;
+ m_status = !m_status;
LOG(("%s: Ticket Power Off\n", machine().describe_context()));
m_timer->adjust(attotime::never);
machine().output().set_led_value(2, 0);
diff --git a/src/mame/machine/ticket.h b/src/mame/machine/ticket.h
index 929085fe5b9..cef52442159 100644
--- a/src/mame/machine/ticket.h
+++ b/src/mame/machine/ticket.h
@@ -67,9 +67,7 @@ public:
static void static_set_senses(device_t &device, uint8_t motor_sense, uint8_t status_sense, bool hopper_type);
// read/write handlers
- DECLARE_READ8_MEMBER( read );
DECLARE_READ_LINE_MEMBER( line_r );
- DECLARE_WRITE8_MEMBER( write );
DECLARE_WRITE_LINE_MEMBER( motor_w );
protected:
@@ -85,13 +83,12 @@ protected:
bool m_hopper_type;
// active state
- uint8_t m_active_bit;
- uint8_t m_motoron;
- uint8_t m_ticketdispensed;
- uint8_t m_ticketnotdispensed;
+ bool m_motoron;
+ bool m_ticketdispensed;
+ bool m_ticketnotdispensed;
- uint8_t m_status;
- uint8_t m_power;
+ bool m_status;
+ bool m_power;
emu_timer *m_timer;
};
diff --git a/src/mame/machine/trs80m2kb.cpp b/src/mame/machine/trs80m2kb.cpp
index 97c5dbeceec..1cefe9d5b3c 100644
--- a/src/mame/machine/trs80m2kb.cpp
+++ b/src/mame/machine/trs80m2kb.cpp
@@ -347,5 +347,5 @@ WRITE8_MEMBER( trs80m2_keyboard_device::kb_p2_w )
*/
- m_keylatch = BITSWAP8(data, 7, 6, 5, 4, 0, 1, 2, 3) & 0x0f;
+ m_keylatch = bitswap<8>(data, 7, 6, 5, 4, 0, 1, 2, 3) & 0x0f;
}
diff --git a/src/mame/machine/xevious.cpp b/src/mame/machine/xevious.cpp
index e4818ba080b..f09677d6daf 100644
--- a/src/mame/machine/xevious.cpp
+++ b/src/mame/machine/xevious.cpp
@@ -167,7 +167,7 @@ READ8_MEMBER( xevious_state::battles_input_port_r )
switch ( offset )
{
default:
- case 0: return ~BITSWAP8(ioport("IN0H")->read(),7,6,5,4,2,3,1,0);
+ case 0: return ~bitswap<8>(ioport("IN0H")->read(),7,6,5,4,2,3,1,0);
case 1: return ~ioport("IN1L")->read();
case 2: return ~ioport("IN1H")->read();
case 3: return ~ioport("IN0L")->read();