2020-05-01 13:19:25 +00:00
|
|
|
import joy
|
2019-09-16 20:55:08 +00:00
|
|
|
|
|
|
|
void x16_reset_joy() {
|
|
|
|
input_dx = 0
|
|
|
|
input_dy = 0
|
|
|
|
input_a = 0
|
|
|
|
input_b = 0
|
|
|
|
input_x = 0
|
|
|
|
input_y = 0
|
|
|
|
input_start = 0
|
|
|
|
input_select = 0
|
|
|
|
input_l = 0
|
|
|
|
input_r = 0
|
|
|
|
}
|
|
|
|
|
|
|
|
alias reset_joy = x16_reset_joy!
|
|
|
|
|
|
|
|
// TODO: be more controller-agnostic?
|
|
|
|
|
|
|
|
// SNES:B NES:A keyboard:Ctrl
|
|
|
|
alias input_b = input_btn
|
|
|
|
|
|
|
|
// SNES:A
|
|
|
|
byte input_a
|
|
|
|
|
|
|
|
// SNES:X
|
|
|
|
byte input_x
|
|
|
|
|
|
|
|
// SNES:Y NES:B keyboard:Alt
|
|
|
|
byte input_y
|
|
|
|
|
|
|
|
// SNES/NES:Start keyboard:Enter
|
|
|
|
byte input_start
|
|
|
|
|
|
|
|
// SNES/NES:Select keyboard:Space
|
|
|
|
byte input_select
|
|
|
|
|
|
|
|
// SNES:L
|
|
|
|
byte input_l
|
|
|
|
|
|
|
|
// SNES:R
|
|
|
|
byte input_r
|
|
|
|
|
2020-05-01 13:19:25 +00:00
|
|
|
enum x16_joy_type {
|
|
|
|
joy_nes = 0
|
|
|
|
joy_keyboard = 1
|
|
|
|
joy_snes = 15
|
|
|
|
joy_none = 255
|
|
|
|
}
|
|
|
|
|
|
|
|
x16_joy_type joy_type
|
|
|
|
|
2019-09-16 20:55:08 +00:00
|
|
|
void read_joy1() {
|
|
|
|
x16_reset_joy()
|
|
|
|
read_also_joy1()
|
|
|
|
}
|
|
|
|
void read_joy2() {
|
|
|
|
x16_reset_joy()
|
|
|
|
read_also_joy2()
|
|
|
|
}
|
2020-05-01 13:19:25 +00:00
|
|
|
|
|
|
|
inline void read_also_joy1() {
|
|
|
|
__read_joy(0)
|
2019-09-16 20:55:08 +00:00
|
|
|
}
|
2020-05-01 13:19:25 +00:00
|
|
|
inline void read_also_joy2() {
|
|
|
|
__read_joy(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
asm void __read_joy(byte register(a) joy_id) {
|
|
|
|
JSR $FF53 // TODO: should we?
|
|
|
|
JSR $FF56
|
|
|
|
STY joy_type
|
|
|
|
CPY #0
|
|
|
|
BMI __read_joy_skip
|
|
|
|
PHX
|
2019-09-16 20:55:08 +00:00
|
|
|
JSR x16_joy_byte0
|
2020-05-01 13:19:25 +00:00
|
|
|
PLA
|
2019-09-16 20:55:08 +00:00
|
|
|
JSR x16_joy_byte1
|
2020-05-01 13:19:25 +00:00
|
|
|
__read_joy_skip:
|
2019-09-16 20:55:08 +00:00
|
|
|
RTS
|
|
|
|
}
|
|
|
|
|
|
|
|
void x16_joy_byte0(byte value) {
|
|
|
|
if value & 8 == 0 { input_dy -= 1 }
|
|
|
|
if value & 4 == 0 { input_dy += 1 }
|
|
|
|
if value & 2 == 0 { input_dx -= 1 }
|
|
|
|
if value & 1 == 0 { input_dx += 1 }
|
|
|
|
if value & 16 == 0 { input_start += 1 }
|
|
|
|
if value & 32 == 0 { input_select += 1 }
|
|
|
|
if value & 64 == 0 { input_y += 1 }
|
|
|
|
if value & 128 == 0 { input_b += 1 }
|
|
|
|
}
|
|
|
|
void x16_joy_byte1(byte value) {
|
|
|
|
if value & 16 == 0 { input_r += 1 }
|
|
|
|
if value & 32 == 0 { input_l += 1 }
|
|
|
|
if value & 64 == 0 { input_x += 1 }
|
|
|
|
if value & 128 == 0 { input_a += 1 }
|
2020-05-01 13:19:25 +00:00
|
|
|
joy_type = x16_joy_type(value & 15)
|
2019-09-16 20:55:08 +00:00
|
|
|
}
|