/* ints.c - Storage allocation for various integers.
 *  Copyright (C) 2022 by Jed Marti
 *   This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *  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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see https://www.gnu.org/licenses/.
 */


#include <C8051F380.h>
#include <stdint.h>

#include "config.h"
#include "storage.h"
#include "serial.h"


// Two constants.
__xdata uint16_t iZERO;
__xdata uint16_t iONE;


// D space address register.
extern uint16_t           DREG;

// Integer accumulator.
extern __xdata floatOrInt IACC;


uint16_t newInt(int32_t v)
{
  // Allocate space. Returns offset in D.
  DREG = dmalloc(4);
  setTag(DESC_INT);

  // Copy the value there.
  IACC.i = v;
  setIACC();
  return DREG;
  
}


  
void initInts(void)
// These values are used everywhere so this keeps them from getting constantly reallocated.
{
  iZERO = newInt(0);
  iONE = newInt(1);
}



// EOF
