1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-12-28 11:31:58 +00:00
millfork/include/nes_joy.mfk

63 lines
1.4 KiB
Plaintext
Raw Normal View History

2018-12-17 16:18:29 +00:00
// standard joystick driver for NES
import joy
import nes_hardware
alias input_a = input_btn
byte input_b
byte input_select
byte input_start
macro void read_joy1() {
nes_reset_joy()
2019-01-13 18:43:37 +00:00
read_also_joy1()
2018-12-17 16:18:29 +00:00
}
macro void read_joy2() {
nes_reset_joy()
2019-01-13 18:43:37 +00:00
read_also_joy2()
2018-12-17 16:18:29 +00:00
}
void nes_reset_joy() {
input_dx = 0
input_dy = 0
input_a = 0
2018-12-17 16:18:29 +00:00
input_b = 0
input_select = 0
input_start = 0
}
alias reset_joy = nes_reset_joy!
2018-12-17 16:18:29 +00:00
inline void read_also_joy1() {
strobe_joypad()
__parse_nes_joypad1()
2018-12-17 16:18:29 +00:00
}
inline void read_also_joy2() {
strobe_joypad()
__parse_nes_joypad2()
2018-12-17 16:18:29 +00:00
}
void __parse_nes_joypad1() {
2018-12-17 16:18:29 +00:00
if read_joypad1() & 1 != 0 { input_a += 1 }
if read_joypad1() & 1 != 0 { input_b += 1 }
if read_joypad1() & 1 != 0 { input_select += 1 }
if read_joypad1() & 1 != 0 { input_start += 1 }
if read_joypad1() & 1 != 0 { input_dy -= 1 }
if read_joypad1() & 1 != 0 { input_dy += 1 }
if read_joypad1() & 1 != 0 { input_dx -= 1 }
if read_joypad1() & 1 != 0 { input_dx += 1 }
}
void __parse_nes_joypad2() {
if read_joypad2() & 1 != 0 { input_a += 1 }
if read_joypad2() & 1 != 0 { input_b += 1 }
if read_joypad2() & 1 != 0 { input_select += 1 }
if read_joypad2() & 1 != 0 { input_start += 1 }
if read_joypad2() & 1 != 0 { input_dy -= 1 }
if read_joypad2() & 1 != 0 { input_dy += 1 }
if read_joypad2() & 1 != 0 { input_dx -= 1 }
if read_joypad2() & 1 != 0 { input_dx += 1 }
}