<commit_before>/*
 *  libstdgb - library of useful Game Boy operations
 *  Copyright (C) 2016 Delwink, LLC
 *  
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as published by
 *  the Free Software Foundation, version 3 only.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "stdgb.h"

uint8_t (* const GB_OBJECTS)[GB_BYTES_PER_OBJ] = (void *) 0xDF00;
static uint8_t * const DPAD_STATE = (void *) 0xDFA0;
static uint8_t * const BTN_STATE = (void *) 0xDFA1;

static void
state_invert (uint8_t *state)
{
  *state = (~(*state)) & 0x0F;
}

void
gb_update_input_state ()
{
  // this routine is copied from the official Nintendo programming document
  __asm__ ("ld a, #0x20\n\t"     // read d-pad
	   "ld (#0xFF00), a\n\t" // set port to do so
	   "ld a, (#0xFF00)\n\t" // read input ports
	   "ld a, (#0xFF00)\n\t" // do this twice for necessary delay
	   "ld (#0xDFA0), a\n\t" // save it in *DPAD_STATE

	   "ld a, #0x10\n\t"     // read buttons
	   "ld (#0xFF00), a\n\t" // set port to do so
	   "ld a, (#0xFF00)\n\t" // read input ports
	   "ld a, (#0xFF00)\n\t" // do this six times for necessary delay
	   "ld a, (#0xFF00)\n\t"
	   "ld a, (#0xFF00)\n\t"
	   "ld a, (#0xFF00)\n\t"
	   "ld a, (#0xFF00)\n\t"
	   "ld (#0xDFA1), a\n\t" // save it in *BTN_STATE

	   "ld a, #0x30\n\t"     // read none
	   "ld (#0xFF00), a");   // set port to do so

  state_invert (DPAD_STATE);
  state_invert (BTN_STATE);
}

uint8_t
gb_get_dpad_direction ()
{
  uint8_t state = *DPAD_STATE;<commit_msg>Change function name to verb<commit_after>/*
 *  libstdgb - library of useful Game Boy operations
 *  Copyright (C) 2016 Delwink, LLC
 *  
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as published by
 *  the Free Software Foundation, version 3 only.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "stdgb.h"

uint8_t (* const GB_OBJECTS)[GB_BYTES_PER_OBJ] = (void *) 0xDF00;
static uint8_t * const DPAD_STATE = (void *) 0xDFA0;
static uint8_t * const BTN_STATE = (void *) 0xDFA1;

static void
invert_state (uint8_t *state)
{
  *state = (~(*state)) & 0x0F;
}

void
gb_update_input_state ()
{
  // this routine is copied from the official Nintendo programming document
  __asm__ ("ld a, #0x20\n\t"     // read d-pad
	   "ld (#0xFF00), a\n\t" // set port to do so
	   "ld a, (#0xFF00)\n\t" // read input ports
	   "ld a, (#0xFF00)\n\t" // do this twice for necessary delay
	   "ld (#0xDFA0), a\n\t" // save it in *DPAD_STATE

	   "ld a, #0x10\n\t"     // read buttons
	   "ld (#0xFF00), a\n\t" // set port to do so
	   "ld a, (#0xFF00)\n\t" // read input ports
	   "ld a, (#0xFF00)\n\t" // do this six times for necessary delay
	   "ld a, (#0xFF00)\n\t"
	   "ld a, (#0xFF00)\n\t"
	   "ld a, (#0xFF00)\n\t"
	   "ld a, (#0xFF00)\n\t"
	   "ld (#0xDFA1), a\n\t" // save it in *BTN_STATE

	   "ld a, #0x30\n\t"     // read none
	   "ld (#0xFF00), a");   // set port to do so

  invert_state (DPAD_STATE);
  invert_state (BTN_STATE);
}

uint8_t
gb_get_dpad_direction ()
{
  uint8_t state = *DPAD_STATE;
{'fraction_non_alphanumeric': 0.129757343550447, 'fraction_numerical': 0.03371647509578544, 'mean_word_length': 2.9436052366565963, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2284985', 'n_tokens_mistral': 1539, 'n_tokens_neox': 1423, 'n_words': 503}