Integrate Aznable codebase

This commit is contained in:
jimmystones
2021-12-22 17:11:57 +00:00
parent 2aab758881
commit 8a93d6fdb2
169 changed files with 17233 additions and 2032 deletions

37
src/shared/Makefile Normal file
View File

@@ -0,0 +1,37 @@
SDCC=sdcc
CPU=z80
DATALOC=0xC000
OUT_DIR=build/
MAIN=os
OUTPUT=rom
SHARED_PATH=../shared/
SHARED_RELS_ALL=$(patsubst %.c,build/%.rel,$(wildcard $(SHARED_PATH)*.c)) # Get all c files from src/shared/ folder
IGNORE_SHARED_RELS=$(patsubst %, build/../shared/%.rel, $(IGNORE_SHARED)) # Format shared files to ignore correctly for filtering
SHARED_RELS=$(filter-out $(IGNORE_SHARED_RELS), $(SHARED_RELS_ALL)) # Filter out ignored shared files
PROJECT_RELS_ALL=$(patsubst %.c,build/%.rel,$(wildcard *.c)) # Get all c files from src/[project] folder
IGNORE_PROJECT_RELS=$(patsubst %, build/%.rel, $(IGNORE_PROJECT)) # Format project files to ignore correctly for filtering
PROJECT_RELS_FILTERED=$(filter-out $(IGNORE_PROJECT_RELS),$(PROJECT_RELS_ALL)) # Filter out ignored shared files
PROJECT_RELS=$(patsubst build/$(MAIN).rel,,$(PROJECT_RELS_FILTERED)) # Remove main c file
TARGET_RELS=$(patsubst build/$(MAIN).rel,,$(wildcard build/*.rel))
all: $(OUTPUT).bin
build/$(OUTPUT).ihx: $(PROJECT_RELS) $(SHARED_RELS)
$(SDCC) $(DEFINES) -m$(CPU) --data-loc $(DATALOC) -o $(OUT_DIR)$(OUTPUT).ihx $(MAIN).c $(TARGET_RELS)
build/%.rel: %.c
$(SDCC) $(DEFINES) -m$(CPU) --data-loc $(DATALOC) -o $(OUT_DIR) -c $<
$(OUTPUT).bin: build/$(OUTPUT).ihx
srec_cat $< -intel -o $@ -binary
rm build/$(OUTPUT).ihx
mv $(OUTPUT).bin bin/$(OUTPUT).bin
rm -f build/$(OUTPUT).*
clean:
rm -f build/*
rm -f bin/*

55
src/shared/music.c Normal file
View File

@@ -0,0 +1,55 @@
/*============================================================================
Aznable OS - Music engine (YM player)
Author: Jim Gregory - https://github.com/JimmyStones/
Version: 1.1
Date: 2022-01-07
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/>.
===========================================================================*/
#include "../shared/sys.h"
#include "../shared/music.h"
#define const_music_track_max 32
unsigned char music_track_max = const_music_track_max;
unsigned char music_last_played = 255;
#include myPATH(../PROJECT_NAME/,music_tracks.h) // Include auto generated track array
void play_music(unsigned char track, unsigned char loop)
{
// Write track start address (3 bytes)
musicram[1] = (unsigned char)(music_track_address[track] >> 16);
musicram[2] = music_track_address[track] >> 8;
musicram[3] = music_track_address[track];
// Write start track instruction (2 for looping, 1 for single play)
musicram[0] = loop ? 2 : 1;
music_last_played = track;
}
void play_music_if(unsigned char track, unsigned char loop)
{
if (musicram[0] == 0 || music_last_played != track)
{
play_music(track, loop);
}
}
void stop_music()
{
// Send stop command
musicram[0] = 3;
}

30
src/shared/music.h Normal file
View File

@@ -0,0 +1,30 @@
/*============================================================================
Aznable OS - Music engine (YM player)
Author: Jim Gregory - https://github.com/JimmyStones/
Version: 1.1
Date: 2022-01-07
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 MUSIC_H
#define MUSIC_H
extern unsigned char music_track_max;
extern void play_music(unsigned char track, unsigned char loop);
extern void play_music_if(unsigned char track, unsigned char loop);
extern void stop_music();
#endif

248
src/shared/ps2.c Normal file
View File

@@ -0,0 +1,248 @@
/*============================================================================
Aznable OS - PS/2 interface functions
Author: Jim Gregory - https://github.com/JimmyStones/
Version: 1.1
Date: 2021-10-20
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/>.
===========================================================================*/
#include "sys.h"
#include "ps2.h"
// COMMAND KEYS
const char KEY_TAB = 0x0d;
const char KEY_CAPSLOCK = 0x58;
const char KEY_ENTER = 0x5a;
const char KEY_BACKSPACE = 0x66;
const char KEY_ESC = 0x76;
const char KEY_LEFTSHIFT = 0x12;
const char KEY_RIGHTSHIFT = 0x59;
const char KEY_ALT = 0x11; // EXT 0 = LEFT, EXT 1 = RIGHT
const char KEY_CTRL = 0x63; // EXT 0 = LEFT, EXT 1 = RIGHT
// USEFUL KEYS
const char KEY_1 = 0x16;
const char KEY_SPACE = 0x29;
// EXTENSION KEYS
const char KEY_UP = 0x75;
const char KEY_LEFT = 0x6b;
const char KEY_RIGHT = 0x74;
const char KEY_DOWN = 0x72;
char kbd_UK[256] =
{
0, 0, // 0x00
0, 0, // 0x01
0, 0, // 0x02
0, 0, // 0x03
0, 0, // 0x04
0, 0, // 0x05
0, 0, // 0x06
0, 0, // 0x07
0, 0, // 0x08
0, 0, // 0x09
0, 0, // 0x0a
0, 0, // 0x0b
0, 0, // 0x0c
0, 0, // 0x0d
'¬', '`', // 0x0e
0, 0, // 0x0f
0, 0, // 0x10
0, 0, // 0x11
0, 0, // 0x12
0, 0, // 0x13
0, 0, // 0x14
'Q', 'q', // 0x15
'!', '1', // 0x16
0, 0, // 0x17
0, 0, // 0x18
0, 0, // 0x19
'Z', 'z', // 0x1a
'S', 's', // 0x1b
'A', 'a', // 0x1c
'W', 'w', // 0x1d
'"', '2', // 0x1e
0, 0, // 0x1f
0, 0, // 0x20
'C', 'c', // 0x21
'X', 'x', // 0x22
'D', 'd', // 0x23
'E', 'e', // 0x24
'$', '4', // 0x25
'£', '3', // 0x26
0, 0, // 0x27
0, 0, // 0x28
' ', ' ', // 0x29
'V', 'v', // 0x2a
'F', 'f', // 0x2b
'T', 't', // 0x2c
'R', 'r', // 0x2d
'%', '5', // 0x2e
0, 0, // 0x2f
0, 0, // 0x30
'N', 'n', // 0x31
'B', 'b', // 0x32
'H', 'h', // 0x33
'G', 'g', // 0x34
'Y', 'y', // 0x35
'^', '6', // 0x36
0, 0, // 0x37
0, 0, // 0x38
0, 0, // 0x39
'M', 'm', // 0x3a
'J', 'j', // 0x3b
'U', 'u', // 0x3c
'&', '7', // 0x3d
'*', '8', // 0x3e
0, 0, // 0x3f
0, 0, // 0x40
'<', ',', // 0x41
'K', 'k', // 0x42
'I', 'i', // 0x43
'O', 'o', // 0x44
')', '0', // 0x45
'(', '9', // 0x46
0, 0, // 0x47
0, 0, // 0x48
'>', '.', // 0x49
'?', '/', // 0x4a
'L', 'l', // 0x4b
':', ';', // 0x4c
'P', 'p', // 0x4d
'_', '-', // 0x4e
0, 0, // 0x4f
0, 0, // 0x50
0, 0, // 0x51
'@', '\'', // 0x52
0, 0, // 0x53
'{', '[', // 0x54
'+', '=', // 0x55
0, 0, // 0x56
0, 0, // 0x57
'+', '=', // 0x58
0, 0, // 0x59 (RSHIFT)
'\n', '\n', // 0x5a (ENTER)
'}', ']', // 0x5b
0, 0, // 0x5c
'|', '\\', // 0x5d
0, 0, // 0x5e
0, 0, // 0x5f
0, 0, // 0x60
0, 0, // 0x61
0, 0, // 0x62
0, 0, // 0x63
0, 0, // 0x64
0, 0, // 0x65
'\b', '\b', // 0x66
0, 0};
char kbd_in[2];
char kbd_lastclock = 0;
char kbd_shift_left = 0;
char kbd_shift_right = 0;
char kbd_scan = 0;
char kbd_pressed;
char kbd_extend;
char kbd_ascii = 0;
char mse_lastclock = 0;
bool mse_changed = 1;
signed char mse_x;
signed char mse_y;
signed char mse_w;
char mse_button1;
char mse_button2;
char kbd_buffer[128];
char kbd_buffer_len = 0;
bool kbd_down[256];
void get_ascii()
{
char p = (kbd_scan * 2);
if (!(kbd_shift_left || kbd_shift_right))
{
p++;
}
kbd_ascii = kbd_UK[p];
if (kbd_ascii > 0)
{
kbd_buffer[kbd_buffer_len] = kbd_ascii;
kbd_buffer_len++;
}
}
void handle_ps2()
{
bool kbd_clock = CHECK_BIT(ps2_key[1], 2);
if (kbd_clock != kbd_lastclock)
{
for (char k = 0; k < 2; k++)
{
kbd_in[k] = ps2_key[k];
}
kbd_extend = CHECK_BIT(kbd_in[1], 0) > 0;
kbd_pressed = CHECK_BIT(kbd_in[1], 1) > 0;
kbd_scan = kbd_in[0];
kbd_ascii = 0;
if (kbd_pressed)
{
kbd_down[kbd_scan] = 1;
if (kbd_scan == KEY_LEFTSHIFT)
{
kbd_shift_left = 1;
}
else if (kbd_scan == KEY_RIGHTSHIFT)
{
kbd_shift_right = 1;
}
else
{
get_ascii();
}
}
else
{
kbd_down[kbd_scan] = 0;
if (kbd_scan == KEY_LEFTSHIFT)
{
kbd_shift_left = 0;
}
else if (kbd_scan == KEY_RIGHTSHIFT)
{
kbd_shift_right = 0;
}
else
{
get_ascii();
}
}
}
kbd_lastclock = kbd_clock;
bool mse_clock = CHECK_BIT(ps2_mouse[3], 0);
if (mse_clock != mse_lastclock)
{
mse_changed = 1;
mse_button1 = ps2_mouse[0];
mse_button2 = ps2_mouse[5];
mse_x = ps2_mouse[1];
mse_y = ps2_mouse[2];
mse_w = ps2_mouse[4];
}
mse_lastclock = mse_clock;
}

106
src/shared/ps2.h Normal file
View File

@@ -0,0 +1,106 @@
/*============================================================================
Aznable OS - PS/2 interface functions
Author: Jim Gregory - https://github.com/JimmyStones/
Version: 1.1
Date: 2021-10-20
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 PS2_H
#define PS2_H
// COMMAND KEYS
extern const char KEY_TAB;
extern const char KEY_CAPSLOCK;
extern const char KEY_ENTER;
extern const char KEY_BACKSPACE;
extern const char KEY_ESC;
extern const char KEY_LEFTSHIFT;
extern const char KEY_RIGHTSHIFT;
extern const char KEY_ALT;
extern const char KEY_CTRL;
// USEFUL KEYS
extern const char KEY_1;
extern const char KEY_SPACE;
// UNMAPPED COMMAND KEYS
// 0x7c, //55 KEY_KPASTERISK
// 0x05, //59 KEY_F1
// 0x06, //60 KEY_F2
// 0x04, //61 KEY_F3
// 0x0c, //62 KEY_F4
// 0x03, //63 KEY_F5
// 0x0b, //64 KEY_F6
// 0x83, //65 KEY_F7
// 0x0a, //66 KEY_F8
// 0x01, //67 KEY_F9
// 0x09, //68 KEY_F10
// 0x6c, //71 KEY_KP7
// 0x75, //72 KEY_KP8
// 0x7d, //73 KEY_KP9
// 0x7b, //74 KEY_KPMINUS
// 0x6b, //75 KEY_KP4
// 0x73, //76 KEY_KP5
// 0x74, //77 KEY_KP6
// 0x79, //78 KEY_KPPLUS
// 0x69, //79 KEY_KP1
// 0x72, //80 KEY_KP2
// 0x7a, //81 KEY_KP3
// 0x70, //82 KEY_KP0
// 0x71, //83 KEY_KPDOT
// 0x61, //86 KEY_102ND
// 0x78, //87 KEY_F11
// 0x07, //88 KEY_F12
// EXTENSION KEYS
extern const char KEY_UP;
extern const char KEY_LEFT;
extern const char KEY_RIGHT;
extern const char KEY_DOWN;
// UNMAPPED EXTENSION KEYS
// EXT | 0x5a, //96 KEY_KPENTER
// EXT | 0x4a, //98 KEY_KPSLASH
// EXT | 0x6c, //102 KEY_HOME
// EXT | 0x7d, //104 KEY_PAGEUP
// EXT | 0x69, //107 KEY_END
// EXT | 0x7a, //109 KEY_PAGEDOWN
// EXT | 0x70, //110 KEY_INSERT
// EXT | 0x71, //111 KEY_DELETE
extern char kbd_shift_left;
extern char kbd_shift_right;
extern char kbd_scan;
extern char kbd_pressed;
extern char kbd_extend;
extern char kbd_ascii;
extern bool mse_changed;
extern signed char mse_x;
extern signed char mse_y;
extern signed char mse_w;
extern char mse_button1;
extern char mse_button2;
extern char kbd_buffer[128];
extern char kbd_buffer_len;
extern bool kbd_down[256];
extern void get_ascii();
extern void handle_ps2();
#endif

46
src/shared/sound.c Normal file
View File

@@ -0,0 +1,46 @@
/*============================================================================
Aznable OS - Sound engine (M5205 sample player)
Author: Jim Gregory - https://github.com/JimmyStones/
Version: 1.0
Date: 2021-12-20
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/>.
===========================================================================*/
#include "sys.h"
#include "sound.h"
#define const_sound_sample_max 32
unsigned char sound_sample_max = const_sound_sample_max;
#include myPATH(../PROJECT_NAME/,sound_samples.h) // Include auto generated track array
void play_sound(unsigned char sample)
{
// Write sample start address (2 bytes)
sndram[1] = sound_sample_address[sample] >> 8;
sndram[0] = sound_sample_address[sample];
// Write sample length (2 bytes)
unsigned short end = sound_sample_address[sample] + sound_sample_length[sample];
sndram[5] = end >> 8;
sndram[4] = end;
// Write play instruction
sndram[8] = 1;
}
void set_sound_volume(unsigned char volume)
{
// Write sample volume
sndram[12] = volume;
}

29
src/shared/sound.h Normal file
View File

@@ -0,0 +1,29 @@
/*============================================================================
Aznable OS - Sound engine (M5205 sample player)
Author: Jim Gregory - https://github.com/JimmyStones/
Version: 1.0
Date: 2021-12-20
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 SOUND_H
#define SOUND_H
extern unsigned char sound_sample_max;
extern void play_sound(unsigned char sample);
extern void set_sound_volume(unsigned char volume);
#endif

96
src/shared/sprite.c Normal file
View File

@@ -0,0 +1,96 @@
/*============================================================================
Aznable OS - Casval (sprite engine)
Author: Jim Gregory - https://github.com/JimmyStones/
Version: 1.0
Date: 2021-11-27
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/>.
===========================================================================*/
#include "sys.h"
#include "sprite.h"
#define const_sprite_max 32
unsigned char sprite_max = const_sprite_max;
unsigned char spr_x_l[const_sprite_max];
unsigned char spr_x_h[const_sprite_max];
unsigned char spr_y_l[const_sprite_max];
unsigned char spr_y_h[const_sprite_max];
bool spr_on[const_sprite_max];
bool spr_collide[const_sprite_max];
unsigned char spr_palette_index[const_sprite_max];
unsigned char spr_index[const_sprite_max];
unsigned char spr_size[const_sprite_max];
unsigned char spr_highbits[const_sprite_max]; // Temp cache of high bits excluding upper 2 Y bits
void set_sprite_position(unsigned char sprite, unsigned short x, unsigned short y)
{
spr_x_h[sprite] = x >> 8;
spr_x_l[sprite] = (unsigned char)x;
spr_y_h[sprite] = y >> 8;
spr_y_l[sprite] = (unsigned char)y;
}
void set_sprite_position_x(unsigned char sprite, unsigned short x)
{
spr_x_h[sprite] = x >> 8;
spr_x_l[sprite] = (unsigned char)x;
}
void update_sprites()
{
unsigned char s = 0;
for (unsigned char sprite = 0; sprite < sprite_max; sprite++)
{
if (spr_on[sprite])
{
// Set sprite properties
spriteram[s++] = spr_highbits[sprite] | spr_y_h[sprite]; // Enabled (1 bit) + Collide (1 bit) + Size (2 bits) + Palette Index (2 bits) + Position Y (upper 2 bits)
spriteram[s++] = spr_y_l[sprite]; // Position Y (lower 8 bits)
spriteram[s++] = spr_index[sprite] << 2 | spr_x_h[sprite]; // Sprite Index (6 bits) + Position X (upper 2 bits)
spriteram[s++] = spr_x_l[sprite]; // Position X (lower 8 bits)
}
else
{
// Clear first sprite byte to disable
spriteram[s] = 0;
s += 4;
}
}
}
void enable_sprite(unsigned char sprite, unsigned char palette_index, unsigned char size, unsigned char collide)
{
spr_on[sprite] = 1;
spr_collide[sprite] = collide;
spr_palette_index[sprite] = palette_index;
spr_size[sprite] = size;
spr_highbits[sprite] = 1 << 7 | collide << 6 | palette_index << 4 | size << 2;
}
void clear_sprites()
{
for (unsigned char sprite = 0; sprite < sprite_max; sprite++)
{
spr_on[sprite] = 0;
}
}
void clear_sprites_range(unsigned char first, unsigned char last)
{
for (unsigned char sprite = first; sprite <= last; sprite++)
{
spr_on[sprite] = 0;
}
}

47
src/shared/sprite.h Normal file
View File

@@ -0,0 +1,47 @@
/*============================================================================
Aznable OS - Casval (sprite engine)
Author: Jim Gregory - https://github.com/JimmyStones/
Version: 1.0
Date: 2021-11-27
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 SPRITE_H
#define SPRITE_H
extern unsigned char sprite_max;
extern unsigned char spr_x_l[];
extern unsigned char spr_x_h[];
extern unsigned char spr_y_l[];
extern unsigned char spr_y_h[];
extern bool spr_on[];
extern bool spr_collide[];
extern unsigned char spr_palette_index[];
extern unsigned char spr_index[];
extern unsigned char spr_size[];
extern void set_sprite_position(unsigned char sprite, unsigned short x, unsigned short y);
extern void set_sprite_position_x(unsigned char sprite, unsigned short x);
extern void update_sprites();
extern void enable_sprite(unsigned char sprite, unsigned char palette_index, unsigned char size, unsigned char collide);
extern void clear_sprites();
extern void clear_sprites_range(unsigned char first, unsigned char last);
#endif

62
src/shared/starfield.c Normal file
View File

@@ -0,0 +1,62 @@
/*============================================================================
Aznable OS - Moroboshi (starfield)
Author: Jim Gregory - https://github.com/JimmyStones/
Version: 1.0
Date: 2021-11-27
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/>.
===========================================================================*/
#include "sys.h"
void enable_starfield()
{
starfield1[0] = 1;
starfield2[0] = 1;
starfield3[0] = 1;
}
void disable_starfield()
{
starfield1[0] = 0;
starfield2[0] = 0;
starfield3[0] = 0;
}
void set_starfield_speed_x(float speed)
{
unsigned char dir = (speed < 0) << 7;
unsigned short mag = (unsigned short)abs(speed * 256);
starfield3[1] = dir | mag >> 8;
starfield3[2] = (unsigned char)mag;
mag = mag << 1;
starfield2[1] = dir | mag >> 8;
starfield2[2] = (unsigned char)mag;
mag = mag << 1;
starfield1[1] = dir | mag >> 8;
starfield1[2] = (unsigned char)mag;
}
void set_starfield_speed_y(float speed)
{
unsigned char dir = (speed < 0) << 7;
unsigned short mag = (unsigned short)abs(speed * 256);
starfield3[3] = dir | mag >> 8;
starfield3[4] = (unsigned char)mag;
mag = mag << 1;
starfield2[3] = dir | mag >> 8;
starfield2[4] = (unsigned char)mag;
mag = mag << 1;
starfield1[3] = dir | mag >> 8;
starfield1[4] = (unsigned char)mag;
}

32
src/shared/starfield.h Normal file
View File

@@ -0,0 +1,32 @@
/*============================================================================
Aznable OS - Moroboshi (starfield)
Author: Jim Gregory - https://github.com/JimmyStones/
Version: 1.0
Date: 2021-11-27
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 STARFIELD_H
#define STARFIELD_H
extern void enable_starfield();
extern void disable_starfield();
extern void set_starfield_speed_x(float speed);
extern void set_starfield_speed_y(float speed);
#endif

59
src/shared/sys.c Normal file
View File

@@ -0,0 +1,59 @@
/*============================================================================
Aznable OS - System interface functions
Author: Jim Gregory - https://github.com/JimmyStones/
Version: 1.2
Date: 2021-11-27
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/>.
===========================================================================*/
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <math.h>
#include <errno.h>
#include "sys.h"
// Character map
const unsigned char chram_cols = 64;
const unsigned char chram_rows = 32;
unsigned short chram_size;
// Hardware inputs
bool hsync;
bool hsync_last;
bool vsync;
bool vsync_last;
bool hblank;
bool hblank_last;
bool vblank;
bool vblank_last;
// Helper functions
unsigned char rand_uchar(unsigned char lower, unsigned char upper)
{
return (rand() % (upper - lower + 1)) + lower;
}
unsigned short rand_ushort(unsigned short lower, unsigned short upper)
{
return (rand() % (upper - lower + 1)) + lower;
}
signed char rand_schar(signed char lower, signed char upper)
{
return (rand() % (upper - lower + 1)) + lower;
}

110
src/shared/sys.h Normal file
View File

@@ -0,0 +1,110 @@
/*============================================================================
Aznable OS - System interface functions
Author: Jim Gregory - https://github.com/JimmyStones/
Version: 1.2
Date: 2021-11-27
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 SYS_H
#define SYS_H
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
// Memory mapped IO
// - Inputs
unsigned char __at(0x8000) input0;
unsigned char __at(0x8100) joystick[24];
unsigned char __at(0x8200) analog_l[12];
unsigned char __at(0x8300) analog_r[12];
unsigned char __at(0x8400) paddle[6];
unsigned char __at(0x8500) spinner[12];
unsigned char __at(0x8600) ps2_key[2];
unsigned char __at(0x8700) ps2_mouse[6];
unsigned char __at(0x8800) timestamp[5];
unsigned char __at(0x8900) timer[2];
unsigned char __at(0x8A00) starfield1[5];
unsigned char __at(0x8A10) starfield2[5];
unsigned char __at(0x8A20) starfield3[5];
unsigned char __at(0x8A30) system_pause;
unsigned char __at(0x8A31) system_menu;
// - Casval (character map)
unsigned char __at(0x9800) chram[2048];
unsigned char __at(0xA000) fgcolram[2048];
unsigned char __at(0xA800) bgcolram[2048];
// - Comet (sprite engine)
unsigned char __at(0xB000) spriteram[512];
unsigned char __at(0xB400) spritecollisionram[32];
// - Zechs (tilemap)
unsigned char __at(0x8C00) tilemapctl[4];
unsigned char __at(0x8C10) tilemapram[1024];
// - Charles (sound)
unsigned char __at(0x8B00) sndram[16];
// - Deikun (music)
unsigned char __at(0x8B10) musicram[4];
// Character map
extern const unsigned char chram_cols;
extern const unsigned char chram_rows;
extern unsigned short chram_size;
// Hardware inputs
extern bool hsync;
extern extern bool hsync_last;
extern bool vsync;
extern bool vsync_last;
extern bool hblank;
extern bool hblank_last;
extern bool vblank;
extern bool vblank_last;
// INPUT 0 bits
#define INPUT_HBLANK 5
#define INPUT_VBLANK 4
// Macros
#define CHECK_BIT(var, pos) ((var) & (1 << (pos)))
#define SET_BIT(var, pos) ((var) |= (1 << (pos)))
#define CLEAR_BIT(var, pos) ((var) &= ~(1 << (pos)))
#define VBLANK_RISING (vblank && !vblank_last)
#define VSYNC_RISING (vsync && !vsync_last)
#define HBLANK_RISING (hblank && !hblank_last)
#define HSYNC_RISING (hsync && !hsync_last)
#define VBLANK_FALLING (!vblank && vblank_last)
#define VSYNC_FALLING (!vsync && vsync_last)
#define HBLANK_FALLING (!hblank && hblank_last)
#define HSYNC_FALLING (!hsync && hsync_last)
#define GET_TIMER ((unsigned short)timer[1] << 8) | (unsigned char)timer[0]
// Auto include handling
#define myIDENT(x) x
#define myXSTR(x) #x
#define mySTR(x) myXSTR(x)
#define myPATH(x,y) mySTR(myIDENT(x)myIDENT(y))
// Helper functions
extern unsigned char rand_uchar(unsigned char lower, unsigned char upper);
extern unsigned short rand_ushort(unsigned short lower, unsigned short upper);
extern signed char rand_schar(signed char lower, signed char upper);
#endif

68
src/shared/tilemap.c Normal file
View File

@@ -0,0 +1,68 @@
/*============================================================================
Aznable OS - Zechs (tilemap engine)
Author: Jim Gregory - https://github.com/JimmyStones/
Version: 1.0
Date: 2022-01-03
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/>.
===========================================================================*/
#include "sys.h"
#include "tilemap.h"
signed char tilemap_offset_x = 0;
signed char tilemap_offset_y = 0;
void update_tilemap_offset()
{
tilemapctl[0] = tilemap_offset_x;
tilemapctl[1] = tilemap_offset_y;
}
void scroll_tilemap_left()
{
tilemapctl[2] = 1;
while (tilemapctl[2] != 0)
{
}
}
void scroll_tilemap_right()
{
tilemapctl[2] = 2;
while (tilemapctl[2] != 0)
{
}
}
void scroll_tilemap_up()
{
tilemapctl[2] = 3;
while (tilemapctl[2] != 0)
{
}
}
void scroll_tilemap_down()
{
tilemapctl[2] = 4;
while (tilemapctl[2] != 0)
{
}
}
void clear_tilemap()
{
tilemapctl[2] = 5;
while (tilemapctl[2] != 0)
{
}
}

34
src/shared/tilemap.h Normal file
View File

@@ -0,0 +1,34 @@
/*============================================================================
Aznable OS - Zechs (tilemap engine)
Author: Jim Gregory - https://github.com/JimmyStones/
Version: 1.0
Date: 2022-01-03
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 TILEMAP_H
#define TILEMAP_H
extern signed char tilemap_offset_x;
extern signed char tilemap_offset_y;
extern void update_tilemap_offset();
extern void scroll_tilemap_left();
extern void scroll_tilemap_right();
extern void scroll_tilemap_up();
extern void scroll_tilemap_down();
extern void clear_tilemap();
#endif

312
src/shared/ui.c Normal file
View File

@@ -0,0 +1,312 @@
/*============================================================================
Aznable OS - User interface functions
Author: Jim Gregory - https://github.com/JimmyStones/
Version: 1.1
Date: 2021-07-15
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/>.
===========================================================================*/
#include "sys.h"
#include "ui.h"
char asc_0 = 48;
char asc_1 = 49;
// Set all character RAM to specified character
void clear_chars(char c)
{
for (unsigned short p = 0; p < chram_size; p++)
{
chram[p] = c;
fgcolram[p] = c;
bgcolram[p] = c;
}
}
void clear_char_area(char c, unsigned char tx, unsigned char ty, unsigned char bx, unsigned char by)
{
for (char y = ty; y <= by; y++)
{
write_char_row(c, 0, tx, y, (bx - tx) + 1);
}
}
// Set all character background colours to specified
void clear_bgcolor(char color)
{
for (unsigned short p = 0; p < chram_size; p++)
{
bgcolram[p] = color;
}
}
// Write string to character RAM
void write_string(const char *string, char color, unsigned char x, unsigned char y)
{
unsigned short p = (y * chram_cols) + x;
unsigned char l = strlen(string);
for (char c = 0; c < l; c++)
{
chram[p] = string[c];
fgcolram[p] = color;
p++;
}
}
// Write formatted string to character RAM (signed char data)
void write_stringfs(const char *format, char color, unsigned char x, unsigned char y, signed char data)
{
unsigned short p = (y * chram_cols) + x;
char temp[30];
sprintf(temp, format, data);
unsigned char l = strlen(temp);
for (char c = 0; c < l; c++)
{
if (temp[c] == 0)
{
return;
}
chram[p] = temp[c];
fgcolram[p] = color;
p++;
}
}
// Write formatted string to character RAM (unsigned char data)
void write_stringf(const char *format, char color, unsigned char x, unsigned char y, unsigned char data)
{
unsigned short p = (y * chram_cols) + x;
char temp[30];
sprintf(temp, format, data);
unsigned char l = strlen(temp);
for (char c = 0; c < l; c++)
{
if (temp[c] == 0)
{
return;
}
chram[p] = temp[c];
fgcolram[p] = color;
p++;
}
}
// Write formatted string to character RAM (unsigned short data)
void write_stringf_ushort(const char *format, char color, unsigned char x, unsigned char y, unsigned short data)
{
unsigned short p = (y * chram_cols) + x;
char temp[40];
sprintf(temp, format, data);
unsigned char l = strlen(temp);
for (char c = 0; c < l; c++)
{
if (temp[c] == 0)
{
return;
}
chram[p] = temp[c];
fgcolram[p] = color;
p++;
}
}
// Write formatted string to character RAM (signed short data)
void write_stringf_short(const char *format, char color, unsigned char x, unsigned char y, signed short data)
{
unsigned short p = (y * chram_cols) + x;
char temp[40];
sprintf(temp, format, data);
unsigned char l = strlen(temp);
for (char c = 0; c < l; c++)
{
if (temp[c] == 0)
{
return;
}
chram[p] = temp[c];
fgcolram[p] = color;
p++;
}
}
// Write formatted string to character RAM (unsigned long data)
void write_stringf_ulong(const char *format, char color, unsigned char x, unsigned char y, unsigned long data)
{
unsigned short p = (y * chram_cols) + x;
char temp[40];
sprintf(temp, format, data);
unsigned char l = strlen(temp);
for (char c = 0; c < l; c++)
{
if (temp[c] == 0)
{
return;
}
chram[p] = temp[c];
fgcolram[p] = color;
p++;
}
}
// Write single char to character RAM and colour RAM
void write_char(unsigned char c, char color, unsigned char x, unsigned char y)
{
unsigned short p = (y * chram_cols) + x;
chram[p] = c;
fgcolram[p] = color;
}
// Write row of consecutive chars to character RAM and colour RAM
void write_char_row(unsigned char c, char color, unsigned char x, unsigned char y, unsigned char count)
{
unsigned short p = (y * chram_cols) + x;
for (char b = 0; b < count; b++)
{
chram[p] = c;
fgcolram[p] = color;
p++;
}
}
// Set colour of single char
void set_fgcolour(char color, char x, char y)
{
unsigned short p = (y * chram_cols) + x;
fgcolram[p] = color;
}
// Set background colour of single char
void set_bgcolour(char color, char x, char y)
{
unsigned short p = (y * chram_cols) + x;
bgcolram[p] = color;
}
// Write row of consecutive chars to character RAM and colour RAM
void write_bgcol_row(char color, unsigned char x, unsigned char y, unsigned char count)
{
unsigned short p = (y * chram_cols) + x;
for (char b = 0; b < count; b++)
{
bgcolram[p] = color;
p++;
}
}
// Write grouped bits to character RAM
void write_bits(char bits[], char multi, unsigned char first, unsigned char length, char color, unsigned char x, unsigned char y)
{
for (char b = first; b < first + length; b++)
{
write_char((b) ? asc_1 : asc_0, color, x, y - 1);
char m = 0b00000001;
for (char i = 0; i < 8; i++)
{
write_char((bits[b * multi] & m) ? asc_1 : asc_0, color, x, y);
x++;
m <<= 1;
}
x++;
}
}
// Draw box outline with specified character
void box(unsigned char tx, unsigned char ty, unsigned char bx, unsigned char by, char c, char color)
{
for (unsigned char x = tx; x <= bx; x++)
{
write_char(c, color, x, ty);
write_char(c, color, x, by);
}
for (unsigned char y = ty + 1; y < by; y++)
{
write_char(c, color, tx, y);
write_char(c, color, bx, y);
}
}
// Draw UI panel
void panel(char tx, char ty, char bx, char by, char color)
{
write_char(char_corner_round_tl, color, tx, ty);
write_char(char_corner_round_tr, color, bx, ty);
write_char(char_corner_round_bl, color, tx, by);
write_char(char_corner_round_br, color, bx, by);
for (char x = tx + 1; x < bx; x++)
{
write_char(char_line_h, color, x, ty);
write_char(char_line_h, color, x, by);
}
for (char y = ty + 1; y < by; y++)
{
write_char(char_line_v, color, tx, y);
write_char(char_line_v, color, bx, y);
}
}
// Shaded panel
void panel_shaded(char tx, char ty, char bx, char by, char color_high, char color1, char color2)
{
write_char(char_corner_round_tl, color_high, tx, ty);
write_char(char_corner_round_tr, color1, bx, ty);
write_char(char_corner_round_bl, color1, tx, by);
write_char(char_corner_round_br, color2, bx, by);
for (char x = tx + 1; x < bx; x++)
{
write_char(char_line_h, color1, x, ty);
write_char(char_line_h, color2, x, by);
}
for (char y = ty + 1; y < by; y++)
{
write_char(char_line_v, color1, tx, y);
write_char(char_line_v, color2, bx, y);
}
}
void fill(char tx, char ty, char bx, char by, char c, char color)
{
for (char y = ty; y <= by; y++)
{
write_char_row(c, color, tx, y, (bx - tx) + 1);
}
}
void fill_bgcol(char tx, char ty, char bx, char by, char color)
{
for (char y = ty; y <= by; y++)
{
write_bgcol_row(color, tx, y, bx - tx);
}
}
// Draw page border
void page_border(char color)
{
panel(0, 0, 39, 29, color);
}
void draw_charactermap()
{
char c = 94;
for (char y = 0; y < 29; y += 2)
{
for (char x = 0; x < 39; x += 4)
{
write_stringf("%d", 0xFF, x, y, c);
write_char(c, 0, x, y + 1);
c++;
}
}
}

100
src/shared/ui.h Normal file
View File

@@ -0,0 +1,100 @@
/*============================================================================
Aznable OS - User interface functions
Author: Jim Gregory - https://github.com/JimmyStones/
Version: 1.1
Date: 2021-07-15
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 UI_H
#define UI_H
extern char asc_0;
extern char asc_1;
#define char_corner_round_tl 149
#define char_corner_round_tr 137
#define char_corner_round_bl 138
#define char_corner_round_br 139
#define char_line_h 131
#define char_line_v 130
#define char_t_up 177
#define char_dot 27
#define char_cross 155
// Set all character RAM to specified character
extern void clear_chars(char c);
// Set area of character RAM to specified character
extern void clear_char_area(char c, unsigned char tx, unsigned char ty, unsigned char bx, unsigned char by);
// Set all character background colours to specified
extern void clear_bgcolor(char color);
// Write string to character RAM
extern void write_string(const char *string, char color, unsigned char x, unsigned char y);
// Write formatted string to character RAM (signed char data)
extern void write_stringfs(const char *format, char color, unsigned char x, unsigned char y, signed char data);
// Write formatted string to character RAM (unsigned char data)
extern void write_stringf(const char *format, char color, unsigned char x, unsigned char y, unsigned char data);
// Write formatted string to character RAM (unsigned short data)
extern void write_stringf_ushort(const char *format, char color, unsigned char x, unsigned char y, unsigned short data);
// Write formatted string to character RAM (signed short data)
extern void write_stringf_short(const char *format, char color, unsigned char x, unsigned char y, signed short data);
// Write formatted string to character RAM (unsigned long data)
extern void write_stringf_ulong(const char *format, char color, unsigned char x, unsigned char y, unsigned long data);
// Write single char to character RAM and colour RAM
extern void write_char(unsigned char c, char color, unsigned char x, unsigned char y);
// Write row of consecutive chars to character RAM and colour RAM
extern void write_char_row(unsigned char c, char color, unsigned char x, unsigned char y, unsigned char count);
// Set colour of single char
extern void set_fgcolour(char color, char x, char y);
// Set background colour of single char
extern void set_bgcolour(char color, char x, char y);
// Write row of consecutive chars to character RAM and colour RAM
extern void write_bgcol_row(char color, unsigned char x, unsigned char y, unsigned char count);
// Write grouped bits to character RAM
extern void write_bits(char bits[], char multi, unsigned char first, unsigned char length, char color, unsigned char x, unsigned char y);
// Draw box outline with specified character
extern void box(unsigned char tx, unsigned char ty, unsigned char bx, unsigned char by, char c, char color);
// Draw UI panel
extern void panel(char tx, char ty, char bx, char by, char color);
// Shaded panel
extern void panel_shaded(char tx, char ty, char bx, char by, char color_high, char color1, char color2);
extern void fill(char tx, char ty, char bx, char by, char c, char color);
extern void fill_bgcol(char tx, char ty, char bx, char by, char color);
// Draw page border
extern void page_border(char color);
extern void draw_charactermap();
#endif