Skip to content

Commit

Permalink
add support for entering level-codes
Browse files Browse the repository at this point in the history
(issue #8 and issue #16)
  • Loading branch information
felipesanches committed Jun 1, 2017
1 parent 889934f commit b74e622
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 44 deletions.
22 changes: 10 additions & 12 deletions src/devices/cpu/anotherworld/anotherworld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ another_world_cpu_device::another_world_cpu_device(const machine_config &mconfig
m_palette_config("palette", ENDIANNESS_LITTLE, 8, 11, 0),
m_video_config("video", ENDIANNESS_LITTLE, 8, 16, 0),
m_icount(0),
m_read_input(*this)
m_read_input(*this),
m_read_keyboard(*this)
{
m_stack = new Stack(&m_sp);
m_requestedNextPart = 0;
Expand Down Expand Up @@ -82,21 +83,17 @@ void another_world_cpu_device::checkThreadRequests(){
}

void another_world_cpu_device::input_updatePlayer() {

#if 0
if (res->currentPartId == 0x3E89) {
char c = sys->input.lastChar;
if (c == 8 || /*c == 0xD |*/ c == 0 || (c >= 'a' && c <= 'z')) {
write_vm_variable(VM_VARIABLE_LAST_KEYCHAR, = c & ~0x20);
sys->input.lastChar = 0;
}
}
#endif

int16_t lr = 0;
int16_t m = 0;
int16_t ud = 0;
int8_t input = m_read_input();

write_vm_variable(VM_VARIABLE_LAST_KEYCHAR, m_read_keyboard());

if (m_currentPartId != GAME_PART(0)
&& m_currentPartId != GAME_PART(9)
&& BIT(input, 4)) m_requestedNextPart = GAME_PART(9);

if (BIT(input, 2)) {
lr = 1;
m |= 1;
Expand Down Expand Up @@ -185,6 +182,7 @@ void another_world_cpu_device::device_start()
{
//resolve callbacks
m_read_input.resolve_safe(0);
m_read_keyboard.resolve_safe(0);

m_program = &space(AS_PROGRAM);
m_data = &space(AS_DATA);
Expand Down
4 changes: 4 additions & 0 deletions src/devices/cpu/anotherworld/anotherworld.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

#define MCFG_ANOTHERW_READ_INPUT_CALLBACK(_devcb) \
devcb = &another_world_cpu_device::set_read_input_callback(*device, DEVCB_##_devcb);
#define MCFG_ANOTHERW_READ_KEYBOARD_CALLBACK(_devcb) \
devcb = &another_world_cpu_device::set_read_keyboard_callback(*device, DEVCB_##_devcb);

enum {
RESET_TYPE__FREEZE_CHANNELS=0,
Expand Down Expand Up @@ -111,6 +113,7 @@ class another_world_cpu_device : public cpu_device
~another_world_cpu_device();

template<class _Object> static devcb_base &set_read_input_callback(device_t &device, _Object object) { return downcast<another_world_cpu_device &>(device).m_read_input.set_callback(object); }
template<class _Object> static devcb_base &set_read_keyboard_callback(device_t &device, _Object object) { return downcast<another_world_cpu_device &>(device).m_read_keyboard.set_callback(object); }

void write_vm_variable(uint8_t i, uint16_t value);

Expand Down Expand Up @@ -178,6 +181,7 @@ class another_world_cpu_device : public cpu_device
uint16_t fetch_word();
uint16_t read_vm_variable(uint8_t i);
devcb_read8 m_read_input;
devcb_read8 m_read_keyboard;
};

// device type definition
Expand Down
47 changes: 16 additions & 31 deletions src/mame/drivers/another_world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,67 +42,51 @@ void another_world_state::machine_start(){
}

static INPUT_PORTS_START( another_world )
PORT_START("keyboard")
PORT_START("buttons")
PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Arrow down") PORT_CODE(KEYCODE_DOWN)
PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Arrow up") PORT_CODE(KEYCODE_UP)
PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Arrow right") PORT_CODE(KEYCODE_RIGHT)
PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Arrow left") PORT_CODE(KEYCODE_LEFT)
PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Code") PORT_CODE(KEYCODE_C)
PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Action") PORT_CODE(KEYCODE_LCONTROL)

/*
PORT_START("keyboard_letters")
PORT_BIT(0x0000001, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("A") PORT_CODE(KEYCODE_A)
PORT_START("keyboard")
PORT_BIT(0x0000002, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("B") PORT_CODE(KEYCODE_B)
PORT_BIT(0x0000004, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("C") PORT_CODE(KEYCODE_C)
PORT_BIT(0x0000008, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("D") PORT_CODE(KEYCODE_D)
PORT_BIT(0x0000010, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("E") PORT_CODE(KEYCODE_E)
PORT_BIT(0x0000020, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("F") PORT_CODE(KEYCODE_F)
PORT_BIT(0x0000040, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("G") PORT_CODE(KEYCODE_G)
PORT_BIT(0x0000080, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("H") PORT_CODE(KEYCODE_H)
PORT_BIT(0x0000100, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("I") PORT_CODE(KEYCODE_I)
PORT_BIT(0x0000200, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("J") PORT_CODE(KEYCODE_J)
PORT_BIT(0x0000400, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("K") PORT_CODE(KEYCODE_K)
PORT_BIT(0x0000800, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("L") PORT_CODE(KEYCODE_L)
PORT_BIT(0x0001000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("M") PORT_CODE(KEYCODE_M)
PORT_BIT(0x0002000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("N") PORT_CODE(KEYCODE_N)
PORT_BIT(0x0004000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("O") PORT_CODE(KEYCODE_O)
PORT_BIT(0x0008000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("P") PORT_CODE(KEYCODE_P)
PORT_BIT(0x0010000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Q") PORT_CODE(KEYCODE_Q)
PORT_BIT(0x0020000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("R") PORT_CODE(KEYCODE_R)
PORT_BIT(0x0040000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("S") PORT_CODE(KEYCODE_S)
PORT_BIT(0x0080000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("T") PORT_CODE(KEYCODE_T)
PORT_BIT(0x0100000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("U") PORT_CODE(KEYCODE_U)
PORT_BIT(0x0200000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("V") PORT_CODE(KEYCODE_V)
PORT_BIT(0x0400000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("W") PORT_CODE(KEYCODE_W)
PORT_BIT(0x0800000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("X") PORT_CODE(KEYCODE_X)
PORT_BIT(0x1000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Y") PORT_CODE(KEYCODE_Y)
PORT_BIT(0x2000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Z") PORT_CODE(KEYCODE_Z)
PORT_BIT(0x4000000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("ENTER") PORT_CODE(KEYCODE_ENTER)
*/
INPUT_PORTS_END

READ8_MEMBER(another_world_state::input_r)
{
return ioport("keyboard")->read();
return ioport("buttons")->read();
}

/*
READ16_MEMBER(another_world_state::letters_r)
READ8_MEMBER(another_world_state::keyboard_r)
{
uint16_t value = ioport("keyboard_letters")->read();
uint16_t value = ioport("keyboard")->read();
if (value & 0x4000000)
return ((uint16_t) 8) & ~0x20;
uint8_t retval = 'a';
uint8_t i = 1;
while ((retval <= 'z')){
if ((value & i) == 0)
return ((uint16_t) retval) & ~0x20;
return 8;

uint8_t retval = 'A';
uint16_t i = 1;
while ((retval <= 'Z')){
if ((value & i) != 0)
return retval;
retval++;
i = i << 1;
}
return 0;//0xFFFF;
}*/
return 0;
}

static ADDRESS_MAP_START( aw_prog_map, AS_PROGRAM, 8, another_world_state )
AM_RANGE(0x00000, 0x0ffff) AM_ROMBANK("bytecode_bank")
Expand Down Expand Up @@ -130,6 +114,7 @@ static MACHINE_CONFIG_START( another_world )
MCFG_CPU_PROGRAM_MAP(aw_prog_map)
MCFG_CPU_DATA_MAP(aw_data_map)
MCFG_ANOTHERW_READ_INPUT_CALLBACK(READ8(another_world_state, input_r))
MCFG_ANOTHERW_READ_KEYBOARD_CALLBACK(READ8(another_world_state, keyboard_r))
MCFG_DEVICE_ADDRESS_MAP(AS_PALETTE, aw_palette_map)
MCFG_DEVICE_ADDRESS_MAP(AS_VIDEO, aw_video_map)

Expand Down
2 changes: 1 addition & 1 deletion src/mame/includes/anotherworld.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ class another_world_state : public driver_device
DECLARE_PALETTE_INIT(anotherw);

DECLARE_WRITE8_MEMBER(mus_mark_w);
// DECLARE_READ16_MEMBER(letters_r);
DECLARE_READ8_MEMBER(input_r);
DECLARE_READ8_MEMBER(keyboard_r);

bitmap_ind16* m_curPagePtr1;
bitmap_ind16* m_curPagePtr2;
Expand Down

0 comments on commit b74e622

Please sign in to comment.