131 lines
4.3 KiB
C
131 lines
4.3 KiB
C
/* cocosmash.h
|
|
Copyright (C) 2026 Pierre Sarrazin <http://sarrazip.com/>
|
|
|
|
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 <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef _H_cocosmash
|
|
#define _H_cocosmash
|
|
|
|
#include <coco.h>
|
|
#include <assert.h>
|
|
|
|
#include "scoring.h"
|
|
|
|
#ifdef OS9
|
|
#define IF_OS9(os9_value, non_os9_value) os9_value
|
|
#else
|
|
#define IF_OS9(os9_value, non_os9_value) non_os9_value
|
|
#endif
|
|
|
|
|
|
enum
|
|
{
|
|
// PMODE 4 constants.
|
|
PMODE = 4,
|
|
PMODE4_SAMV_VALUE = 6, // value for the 3-bit SAM V register (display mode control register)
|
|
page0 = 7, // first PMODE 4 screen (for 7-bit SAM F register value, i.e., buffer address / 512)
|
|
page1 = 19, // second PMODE 4 screen
|
|
grbuf0 = page0 * 512, // address of 1st screen
|
|
grbuf1 = page1 * 512, // address of 2nd screen
|
|
PIXELS_PER_BYTE = 8,
|
|
BYTES_PER_ROW = 32,
|
|
COLS_PER_SCREEN = 256,
|
|
ROWS_PER_SCREEN = 192,
|
|
VIDRAM = 0x0400, // location of Basic's 32x16 text screen
|
|
|
|
// Game constants.
|
|
VSYNCS_PER_FLIP = 3,
|
|
BYTES_PER_BITMAP_ROW = 6,
|
|
MAX_BITMAP_HEIGHT = 42, // 43*BYTES_PER_BITMAP_ROW would be > 255 and would require MUL168
|
|
DIRTY_RECT_WIDTH = 3, // in bytes
|
|
GROUND_HEIGHT = 7, // zero would be last visible row of pixels
|
|
GROUND_Y_POS = ROWS_PER_SCREEN - 1 - GROUND_HEIGHT,
|
|
SPRITE_WIDTH = 16, // in pixels
|
|
SHOOTER_WIDTH = SPRITE_WIDTH, // width in pixels (must be consistent w/shooter_bm)
|
|
INIT_NUM_LIVES = 0x10, // BCD
|
|
MAX_NUM_LIVES = 0x99, // BCD; due to only 2 digits being drawn for number of lives
|
|
MIN_SAUCER_LEVEL = 4, // first level in which saucers can appear (must be <= MAX_LEVEL_NO)
|
|
MAX_LEVEL_NO = 6,
|
|
MAX_ROCKS = 2,
|
|
MAX_MISSILES = 3,
|
|
MAX_EXPLOSIONS = 20,
|
|
MAX_SPINNERS = 2,
|
|
ROCK_WIDTH = SPRITE_WIDTH,
|
|
ROCK_HEIGHT = 12,
|
|
PULSAR_WIDTH = SPRITE_WIDTH, // width in pixels
|
|
PULSAR_HEIGHT = 14, // height in pixels
|
|
SAUCER_WIDTH = SPRITE_WIDTH,
|
|
SAUCER_HEIGHT = 12,
|
|
SAUCER_BULLET_HEIGHT = 12,
|
|
DIGIT_WIDTH = 8, // width in pixels of the digit pixmaps (digit0_bm, etc.)
|
|
DIGIT_HEIGHT = 5, // height in pixels
|
|
SCORE_Y_POS = ROWS_PER_SCREEN - 1 - DIGIT_HEIGHT,
|
|
SCORE_WIDTH = 9,
|
|
FRAMES_PER_EXPLOSION = 20, // duration of an explosion animation
|
|
|
|
// Speeds in pixels per frame. Horizontal speeds must all be even numbers.
|
|
SHOOTER_X_SPEED = 6, // horizontal speed of player's shooter
|
|
PLAYER_MISSILE_Y_SPEED = 15,
|
|
PULSAR_X_SPEED = 4,
|
|
PULSAR_Y_SPEED = 6,
|
|
SAUCER_X_SPEED = 4,
|
|
SAUCER_Y_SPEED = 4, // SAUCER_HEIGHT must be a multiple of this
|
|
|
|
// Misc.
|
|
BREAK_KEY = 3, // ASCII code of Break key
|
|
INVERTED_COLOR_TOGGLE_CHAR = '^', // re: printWrapped()
|
|
};
|
|
|
|
|
|
// Gives a number of elements, not a number of bytes.
|
|
//
|
|
#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
|
|
|
|
|
|
#define ARRAY_END(array) ((array) + ARRAY_SIZE(array))
|
|
|
|
|
|
// A ThinBitmap is always 8 pixels wide.
|
|
//
|
|
typedef struct ThinBitmap
|
|
{
|
|
byte height; // in pixel rows
|
|
byte bytes[]; // only pixel bytes, no mask bytes
|
|
} ThinBitmap;
|
|
|
|
|
|
// A PreShiftedBitmap is always 16 pixels wide.
|
|
//
|
|
typedef struct PreShiftedBitmap
|
|
{
|
|
byte height; // in pixel rows, non zero
|
|
|
|
// Offsets in bytes[].
|
|
// A PreShiftedBitmap can be only be written horizontal pixel positions
|
|
// that are even, and less than 240.
|
|
// This horiz. position is thus equal to {0, 2, 4, 6} modulo 8.
|
|
// That modulo 8 value is the index into preShiftOffsets[].
|
|
// The offset obtained this way is an index in bytes[].
|
|
// At that offset in bytes[], there are six bytes for each row of the bitmap.
|
|
// The first 3 bytes are mask bytes. The last 3 are image bytes.
|
|
//
|
|
word preShiftOffsets[4];
|
|
|
|
byte bytes[];
|
|
} PreShiftedBitmap;
|
|
|
|
|
|
#endif /* _H_cocosmash */
|