/* util.h Copyright (C) 2026 Pierre Sarrazin 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 . */ #ifndef _H_util #define _H_util #include "cocosmash.h" // Counter that is incremented 60 times per second. // extern word timer; // Counts down to zero from VSYNCS_PER_FLIP. // extern byte numVSyncsBeforeScreenFlip; // Sets up the IRQ service that updates 'numVSyncsBeforeScreenFlip' and 'timer' // on the V-Sync interrupt. // void setupIRQService(void); void coldBoot(void); // Equivalent to SCREEN 1,colorSet. // __gcccall void setCoCo12ColorSet(byte colorSet); // Emulates setCoCo12ColorSet() with palette changes. // __gcccall void setCoCo3ColorSet(byte colorSet); // Returns a random integer between the two limits, inclusively. // word rnd(word lowerLimit, word upperLimit); // Makes the absolute value of 'n' even. // sword makeEven(sword n); // Returns ⌈num / den⌉. // __gcccall byte ceilDiv(byte num, byte den); // screenRow: Considered negative if in -64..-1, non-negative if 0..191. // Returns this value as a signed word. // __gcccall asm sword signExtendYPos(byte screenRow); // valueToAdd: 0..9. // digitIndex: Index in decimalScore[]. // void addToDecimalDigit(byte valueToAdd, sbyte digitIndex, byte digitArray[SCORE_WIDTH]); // Sets parameters used by printWrapped(). // MUST be called at least once before calling printWrapped(). // leftMargin: Column where logical lines start. // logicalLineLength: leftMargin + logicalLineLength must be less than screen width. // void setWrappedPrinting(byte leftMargin, byte logicalLineLength); // setWrappedPrinting() MUST have been called at least once before // calling this function. // Newlines must be specified with '\n'. // Character INVERTED_COLOR_TOGGLE_CHAR toggled color inversion. // void printWrapped(const char *text); // Copies 'numRows' of bitmapRows[] twice each to screenPtr. // void copyDoubleRowBitmap(byte *screenPtr, const uint32_t bitmapRows[][8], byte numRows); // XORs every byte of the region at screenPtr with xorArg. // The region size is numRows * BYTES_PER_ROW. // void xorRegion(byte *screenPtr, byte numRows, byte xorArg); // Must be called before calling playSoundSample(). // void enableSound(void); // enableSound() must be called before calling this function. // The array bytes must contain sample values in { 0, 4, 8, ... , 252 }, // bits 0 and 1 must be zero. // delayLength: Longer values put more time between writing each // sample byte to the sound port. A unit represents 6 cycles // on a CoCo 6809 CPU. // void playSoundSample(const void *sampleArray, const void *sampleArrayEnd, word delayLength); #endif /* _H_util */