From abfc1b4212921abe31295b92590a257908b2d7fb Mon Sep 17 00:00:00 2001 From: Damien Ciabrini Date: Thu, 19 Aug 2021 22:34:06 +0200 Subject: [PATCH] nullbios: credits management for 2 players Ref dciabrin/ngdevkit-examples#7 --- nullbios/biosstart.S | 52 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/nullbios/biosstart.S b/nullbios/biosstart.S index 5847692..5f71998 100644 --- a/nullbios/biosstart.S +++ b/nullbios/biosstart.S @@ -127,6 +127,11 @@ RESET: /* Set initial system information in RAM */ #if BIOS_ROM_HARDWARE != 0 move.b #0x80, BIOS_MVS_FLAG + /* Init credits information, and assume credits + * are always stored in P1_CREDITS_BCD + */ + move.b #0, BIOS_STATCURNT + move.b #0, BIOS_STATCURNT_RAW move.b #0, P1_CREDITS_BCD jsr load_soft_dip #else @@ -208,7 +213,17 @@ NO_OP: SYSTEM_IO: - /* player 1 */ + /* check player 1 coin button */ + move.b BIOS_P1CURRENT, %d1 + move.b %d1, BIOS_P1PREVIOUS + move.b REG_P1CNT, %d0 + not.b %d0 + move.b %d0, BIOS_P1CURRENT + eor.b %d0, %d1 + and.b %d1, %d0 + move.b %d0, BIOS_P1CHANGE + + /* check player 2 coin button */ move.b BIOS_P1CURRENT, %d1 move.b %d1, BIOS_P1PREVIOUS move.b REG_P1CNT, %d0 @@ -273,11 +288,18 @@ SYSTEM_IO: .Lstart_status: /* start status */ - move.b BIOS_STATCURNT, %d1 - move.b %d1, BIOS_STATCURNT_RAW move.b REG_STATUS_B, %d0 not.b %d0 - andi.b #0xf, %d0 + /* bits 1 and 3 from reg_status_b (start buttons) + * to bit 1 and 2 in %d0 (for bios_start_flag) + */ + move.b %d0, %d1 + andi.b #0x4, %d1 + lsr #1, %d1 + andi.b #0x1, %d0 + or.b %d1, %d0 + move.b BIOS_STATCURNT, %d1 + move.b %d1, BIOS_STATCURNT_RAW move.b %d0, BIOS_STATCURNT eor.b %d0, %d1 and.b %d1, %d0 @@ -286,12 +308,30 @@ SYSTEM_IO: beq .Lnostart .Lstart_pressed: /* when start is pressed and credits are available: - * . game's "plater_start" callback is executed + * . game's "player_start" callback is executed + * . the callback sees which player wants to start + * via bits set in bios_start_flag * . the callback engages "game mode" by * setting bios_user_mode set to 2. * [only when game mode is engaged] - * . credits are decremented + * . credits are decremented for each bit still set + * in bios_start_flag when the callback exits + * [before the game is started] + * . hitting 2UP start means that two players want + * to start, and it only runs the callback if + * enough credits are available */ + cmp.b #2, BIOS_USER_MODE + beq .Lend_of_coin_prechecks + btst #1, %d0 + beq .L2up_no_pressed + bset #0, %d0 + cmp.b #2, P1_CREDITS_BCD + blt .Lnostart +.L2up_no_pressed: + cmp.b #1, P1_CREDITS_BCD + blt .Lnostart +.Lend_of_coin_prechecks: move.b %d0, BIOS_START_FLAG jsr PLAYER_START.l cmp.b #2, BIOS_USER_MODE