1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-12-24 15:29:23 +00:00
millfork/include/nes_joy.mfk
2019-06-28 16:26:05 +02:00

59 lines
1.4 KiB
Plaintext

// 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()
read_also_joy1()
}
macro void read_joy2() {
nes_reset_joy()
read_also_joy2()
}
void nes_reset_joy() {
input_b = 0
input_select = 0
input_start = 0
reset_joy()
}
inline void read_also_joy1() {
strobe_joypad()
__parse_nes_joypad1()
}
inline void read_also_joy2() {
strobe_joypad()
__parse_nes_joypad2()
}
void __parse_nes_joypad1() {
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 }
}