1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-11-01 05:05:32 +00:00
millfork/include/x16_joy.mfk

100 lines
1.7 KiB
Plaintext
Raw Normal View History

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
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()
}
inline void read_also_joy1() {
__read_joy(0)
2019-09-16 20:55:08 +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
PLA
2019-09-16 20:55:08 +00:00
JSR x16_joy_byte1
__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 }
joy_type = x16_joy_type(value & 15)
2019-09-16 20:55:08 +00:00
}