mirror of
https://github.com/stevenhowes/CTheEscape.git
synced 2026-05-26 15:53:29 +01:00
Re-arrange so application has a proper directory
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
Set TheEsc$Dir <Obey$Dir>
|
||||
IconSprites <TheEsc$Dir>.!Sprites
|
||||
WimpSlot -min 128k -max 128k
|
||||
Dir <TheEsc$Dir>
|
||||
Run <TheEsc$Dir>.!RunImage
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,51 @@
|
||||
# Project: TheEsc
|
||||
|
||||
|
||||
# Toolflags:
|
||||
CCflags = -c -depend !Depend -IC: -throwback -w
|
||||
Linkflags = -aif -o $@
|
||||
|
||||
|
||||
# Final targets:
|
||||
@.!RunImage: @.o.CTheEscape @.o.Graphics @.o.Sound @.o.Input C:o.stubs
|
||||
Link $(Linkflags) @.o.CTheEscape @.o.Graphics @.o.Sound @.o.Input C:o.stubs
|
||||
|
||||
|
||||
# User-editable dependencies:
|
||||
|
||||
|
||||
# Static dependencies:
|
||||
@.o.CTheEscape: @.c.CTheEscape
|
||||
cc $(ccflags) -o @.o.CTheEscape @.c.CTheEscape
|
||||
@.o.Graphics: @.c.Graphics
|
||||
cc $(ccflags) -o @.o.Graphics @.c.Graphics
|
||||
@.o.Sound: @.c.Sound
|
||||
cc $(ccflags) -o @.o.Sound @.c.Sound
|
||||
@.o.Input: @.c.Input
|
||||
cc $(ccflags) -o @.o.Input @.c.Input
|
||||
|
||||
# Dynamic dependencies:
|
||||
|
||||
o.CTheEscape: c.CTheEscape
|
||||
o.CTheEscape: C:h.swis
|
||||
o.CTheEscape: C:h.kernel
|
||||
o.CTheEscape: C:h.kernel
|
||||
o.CTheEscape: h.Sound
|
||||
o.CTheEscape: c.CTheEscape
|
||||
o.CTheEscape: C:h.swis
|
||||
o.CTheEscape: C:h.kernel
|
||||
o.CTheEscape: C:h.kernel
|
||||
o.CTheEscape: h.Sound
|
||||
o.Graphics: c.Graphics
|
||||
o.Graphics: C:h.swis
|
||||
o.Graphics: C:h.kernel
|
||||
o.Graphics: C:h.kernel
|
||||
o.Sound: c.Sound
|
||||
o.Sound: C:h.swis
|
||||
o.Sound: C:h.kernel
|
||||
o.Sound: C:h.kernel
|
||||
o.Sound: h.Sound
|
||||
o.Input: c.Input
|
||||
o.Input: C:h.swis
|
||||
o.Input: C:h.kernel
|
||||
o.Input: C:h.kernel
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,202 @@
|
||||
#include <stdio.h>
|
||||
#include "swis.h"
|
||||
#include <kernel.h>
|
||||
|
||||
// SWI Registers
|
||||
extern _kernel_swi_regs inreg;
|
||||
extern _kernel_swi_regs outreg;
|
||||
|
||||
extern unsigned char *buffer;
|
||||
int screen = 1;
|
||||
|
||||
// Loads sprite file into buffer
|
||||
void load_sprites(char* filename)
|
||||
{
|
||||
int length;
|
||||
|
||||
// Attempt to get file info
|
||||
inreg.r[0] = 13;
|
||||
inreg.r[1] = (int) filename;
|
||||
_kernel_swi(OS_File,&inreg,&outreg);
|
||||
|
||||
// Length will be in R4 if it exists
|
||||
length = outreg.r[4];
|
||||
|
||||
// If it's <1 it's fil not found
|
||||
if(outreg.r[0] < 1)
|
||||
{
|
||||
printf("Sprite file %s not found",filename);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// Stops us trying to mallocsomething mad if file is too big.
|
||||
if(length > 200000)
|
||||
{
|
||||
printf("Sprite file %s seems unreasonably large at %i bytes",filename, length);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// Attempt malloc, die if we cant
|
||||
buffer = (unsigned char *) malloc(length + 4);
|
||||
|
||||
if(buffer==NULL)
|
||||
{
|
||||
printf("Couldn't malloc %i bytes for sprite buffer",length);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// Store size and other info as required for SpriteOp 9 to init sprite area
|
||||
*(unsigned int *)buffer = length + 4;
|
||||
*(unsigned int *)(buffer + 4) = 16;
|
||||
inreg.r[0] = 256+9;
|
||||
inreg.r[1] = (unsigned int) buffer;
|
||||
_kernel_swi(OS_SpriteOp,&inreg,&outreg);
|
||||
|
||||
// Load sprite file into buffer
|
||||
inreg.r[0] = 256+10;
|
||||
inreg.r[1] = (int) buffer;
|
||||
inreg.r[2] = (int) filename;
|
||||
_kernel_swi(OS_SpriteOp,&inreg,&outreg);
|
||||
}
|
||||
|
||||
void display_mode(int mode)
|
||||
{
|
||||
int pitch;
|
||||
int height=256; // TODO: This shouldn't be here!
|
||||
|
||||
// OS_ScreenMode doesn't seem to work in 3.10
|
||||
inreg.r[0] = 22;
|
||||
_kernel_swi(OS_WriteC,&inreg,&outreg);
|
||||
inreg.r[0] = mode;
|
||||
_kernel_swi(OS_WriteC,&inreg,&outreg);
|
||||
|
||||
// The SDL library does this if double buffering is enabled - seems
|
||||
// to be what makes it work - although other examples dont have this
|
||||
inreg.r[0] = -1;
|
||||
inreg.r[1] = 6;
|
||||
_kernel_swi(OS_ReadModeVariable, &inreg, &outreg);
|
||||
pitch = outreg.r[2];
|
||||
|
||||
inreg.r[0] = 2; /* Screen area */
|
||||
_kernel_swi(OS_ReadDynamicArea, &inreg, &outreg);
|
||||
inreg.r[1] = (pitch * height * 2) - outreg.r[1];
|
||||
if (_kernel_swi(OS_ChangeDynamicArea, &inreg, &outreg) != NULL)
|
||||
{
|
||||
printf("Couldn't OS_ChangeDynamicArea");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
void draw_dotted_line(int x1,int y1,int x2,int y2)
|
||||
{
|
||||
inreg.r[0] = 4 + 16;
|
||||
inreg.r[1] = x1;
|
||||
inreg.r[2] = y1;
|
||||
_kernel_swi(OS_Plot,&inreg,&outreg);
|
||||
inreg.r[0] = 5 + 16;
|
||||
inreg.r[1] = x2;
|
||||
inreg.r[2] = y2;
|
||||
_kernel_swi(OS_Plot,&inreg,&outreg);
|
||||
}
|
||||
|
||||
void draw_line(int x1,int y1,int x2,int y2)
|
||||
{
|
||||
inreg.r[0] = 4;
|
||||
inreg.r[1] = x1;
|
||||
inreg.r[2] = y1;
|
||||
_kernel_swi(OS_Plot,&inreg,&outreg);
|
||||
inreg.r[0] = 5;
|
||||
inreg.r[1] = x2;
|
||||
inreg.r[2] = y2;
|
||||
_kernel_swi(OS_Plot,&inreg,&outreg);
|
||||
}
|
||||
|
||||
void draw_rectangle(int x1,int y1,int x2,int y2)
|
||||
{
|
||||
draw_line(x1,y1,x1,y2);
|
||||
draw_line(x1,y1,x2,y1);
|
||||
draw_line(x2,y2,x2,y1);
|
||||
draw_line(x2,y2,x1,y2);
|
||||
}
|
||||
|
||||
void draw_sprite(char* spritename,int x, int y)
|
||||
{
|
||||
// SpriteOp 34 to put sprite at a location
|
||||
inreg.r[0] = 256+34;
|
||||
inreg.r[1] = (int) buffer;
|
||||
inreg.r[2] = (int) spritename;
|
||||
inreg.r[3] = x;
|
||||
inreg.r[4] = y;
|
||||
inreg.r[5] = 8; // GCOL dest=source and sprite mask
|
||||
_kernel_swi(OS_SpriteOp,&inreg,&outreg);
|
||||
}
|
||||
|
||||
void draw_text(char* text, int x, int y, int fonthandle)
|
||||
{
|
||||
inreg.r[0] = fonthandle;
|
||||
inreg.r[1] = (int) text;
|
||||
inreg.r[2] = 1 << 4;
|
||||
inreg.r[3] = x;
|
||||
inreg.r[4] = y;
|
||||
inreg.r[5] = 0;
|
||||
inreg.r[6] = 0;
|
||||
inreg.r[7] = 0;
|
||||
_kernel_swi(Font_Paint,&inreg,&outreg);
|
||||
}
|
||||
|
||||
int font_find(char* font, int height, int width)
|
||||
{
|
||||
inreg.r[0] = 0;
|
||||
inreg.r[1] = (int) font;
|
||||
inreg.r[2] = height*16;
|
||||
inreg.r[3] = width*16;
|
||||
inreg.r[4] = 0;
|
||||
inreg.r[5] = 0;
|
||||
_kernel_swi(Font_FindFont,&inreg,&outreg);
|
||||
|
||||
return outreg.r[0];
|
||||
}
|
||||
|
||||
void font_colour(int fg, int bg, int fonthandle)
|
||||
{
|
||||
inreg.r[0] = fonthandle;
|
||||
inreg.r[1] = bg;
|
||||
inreg.r[2] = fg;
|
||||
inreg.r[3] = 14;
|
||||
_kernel_swi(ColourTrans_SetFontColours, &inreg, &outreg);
|
||||
}
|
||||
|
||||
void graphics_colour(int setcolour)
|
||||
{
|
||||
inreg.r[0] = setcolour;
|
||||
inreg.r[1] = -1;
|
||||
inreg.r[2] = 0;
|
||||
_kernel_swi(ColourTrans_ReturnColourNumberForMode,&inreg,&outreg);
|
||||
inreg.r[0] = 0;
|
||||
inreg.r[1] = outreg.r[0];
|
||||
_kernel_swi(OS_SetColour,&inreg,&outreg);
|
||||
}
|
||||
void screen_flipbuffer()
|
||||
{
|
||||
// Hardware
|
||||
inreg.r[0] = 113;
|
||||
inreg.r[1] = screen+1;
|
||||
_kernel_swi(OS_Byte,&inreg,&outreg);
|
||||
|
||||
screen ^= 1;
|
||||
|
||||
// Drivers
|
||||
inreg.r[0] = 112;
|
||||
inreg.r[1] = screen+1;
|
||||
_kernel_swi(OS_Byte,&inreg,&outreg);
|
||||
|
||||
inreg.r[0] = 19;
|
||||
_kernel_swi(OS_Byte,&inreg,&outreg);
|
||||
|
||||
}
|
||||
|
||||
void screen_clear()
|
||||
{
|
||||
inreg.r[0] = 12;
|
||||
_kernel_swi(OS_WriteC,&inreg,&outreg);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#include <stdio.h>
|
||||
#include "swis.h"
|
||||
#include <kernel.h>
|
||||
|
||||
// SWI Registers
|
||||
extern _kernel_swi_regs inreg;
|
||||
extern _kernel_swi_regs outreg;
|
||||
|
||||
int input_readkey(int key)
|
||||
{
|
||||
inreg.r[0] = 129;
|
||||
inreg.r[1] = key ^ 255;
|
||||
inreg.r[2] = 255;
|
||||
_kernel_swi(OS_Byte,&inreg,&outreg);
|
||||
|
||||
if(outreg.r[1] == 255)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int input_readanykey()
|
||||
{
|
||||
inreg.r[0] = 129;
|
||||
inreg.r[1] = 123 + 255;
|
||||
inreg.r[2] = 255;
|
||||
_kernel_swi(OS_Byte,&inreg,&outreg);
|
||||
|
||||
return outreg.r[1];
|
||||
}
|
||||
+157
@@ -0,0 +1,157 @@
|
||||
#include <stdio.h>
|
||||
#include "swis.h"
|
||||
#include <kernel.h>
|
||||
#include "Sound.h"
|
||||
|
||||
// SWI Registers
|
||||
extern _kernel_swi_regs inreg;
|
||||
extern _kernel_swi_regs outreg;
|
||||
|
||||
int current_element = 0;
|
||||
int current_playback_element = 0;
|
||||
int composition_startcent = -1;
|
||||
|
||||
struct CompositionElement composition[COMPOSITION_MAX];
|
||||
|
||||
char *notes[] = {"AX","A#","BX","CX","C#","DX","D#","EX","FX","F#","GX","G#"};
|
||||
|
||||
void sound_on()
|
||||
{
|
||||
inreg.r[0] = 2;
|
||||
_kernel_swi(Sound_Enable,&inreg,&outreg);
|
||||
}
|
||||
|
||||
void sound_voices(int num)
|
||||
{
|
||||
inreg.r[0] = num;
|
||||
inreg.r[1] = 0;
|
||||
inreg.r[2] = 0;
|
||||
inreg.r[3] = 0;
|
||||
inreg.r[4] = 0;
|
||||
_kernel_swi(Sound_Configure,&inreg,&outreg);
|
||||
}
|
||||
|
||||
void sound_set_voice(int voicenum, char* voicename)
|
||||
{
|
||||
inreg.r[0] = voicenum;
|
||||
inreg.r[1] = (int) voicename;
|
||||
_kernel_swi(Sound_AttachNamedVoice,&inreg,&outreg);
|
||||
}
|
||||
|
||||
void sound_play(unsigned char Channel, signed char Volume, unsigned char Note, unsigned short int Length)
|
||||
{
|
||||
inreg.r[0] = Channel;
|
||||
inreg.r[1] = Volume;
|
||||
inreg.r[2] = Note;
|
||||
inreg.r[3] = Length;
|
||||
_kernel_swi(Sound_Control,&inreg,&outreg);
|
||||
}
|
||||
|
||||
|
||||
void sound_composition_element_play(struct CompositionElement element)
|
||||
{
|
||||
sound_play(element.Channel, element.Volume, element.Note, element.Length);
|
||||
}
|
||||
|
||||
|
||||
void sound_composition_init()
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i <= COMPOSITION_MAX; i++)
|
||||
{
|
||||
composition[i].Start = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void sound_composition_element_add(int start, int channel, int note, int length)
|
||||
{
|
||||
composition[current_element].Start = start;
|
||||
composition[current_element].Note = note;
|
||||
composition[current_element].Volume = -10;
|
||||
composition[current_element].Channel = channel;
|
||||
composition[current_element].Length = length;
|
||||
current_element++;
|
||||
}
|
||||
|
||||
void sound_composition_debug()
|
||||
{
|
||||
int i;
|
||||
|
||||
printf("------------------------------\n");
|
||||
|
||||
for(i = 0; i <= COMPOSITION_MAX; i++)
|
||||
{
|
||||
if(composition[i].Start >= 0)
|
||||
{
|
||||
printf("%5d: %3d %4d %3d %4d\n",
|
||||
composition[i].Start,
|
||||
composition[i].Note,
|
||||
composition[i].Volume,
|
||||
composition[i].Channel,
|
||||
composition[i].Length
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
printf("%i elements at %i bytes each\n",current_element,sizeof(composition[0]));
|
||||
|
||||
printf("------------------------------\n");
|
||||
}
|
||||
|
||||
void sound_composition_start(int cent)
|
||||
{
|
||||
composition_startcent = cent;
|
||||
}
|
||||
|
||||
void sound_composition_stop()
|
||||
{
|
||||
current_playback_element = COMPOSITION_MAX;
|
||||
}
|
||||
|
||||
void sound_composition_tick(int cents)
|
||||
{
|
||||
int offset_cents = cents - composition_startcent;
|
||||
int i;
|
||||
|
||||
for(i = current_playback_element; i <= COMPOSITION_MAX; i++)
|
||||
{
|
||||
if(composition[i].Start <= offset_cents)
|
||||
{
|
||||
if(composition[i].Start >= 0)
|
||||
{
|
||||
sound_composition_element_play(composition[i]);
|
||||
current_playback_element = i + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int sound_note(char* note)
|
||||
{
|
||||
int octave = note[1] - 48;
|
||||
char *basenote = "ZZ";
|
||||
int index = 1;
|
||||
int indexi = 0;
|
||||
int len = sizeof(notes)/sizeof(notes[0]);
|
||||
basenote[0] = note[0];
|
||||
if(strlen(note) == 3)
|
||||
{
|
||||
basenote[1] = '#';
|
||||
}else{
|
||||
basenote[1] = 'X';
|
||||
}
|
||||
for(indexi = 0; indexi < len; indexi++)
|
||||
{
|
||||
if(strcmp(notes[indexi],basenote) == 0)
|
||||
index = indexi;
|
||||
}
|
||||
return 41 + (4 * index) + ((octave - 2) * 48);
|
||||
}
|
||||
|
||||
int sound_composition_incomplete()
|
||||
{
|
||||
if(composition[current_playback_element].Start < 0)
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#define COMPOSITION_MAX 128
|
||||
|
||||
struct CompositionElement {
|
||||
signed short int Start;
|
||||
unsigned char Note;
|
||||
signed char Volume;
|
||||
unsigned char Channel;
|
||||
unsigned short int Length;
|
||||
};
|
||||
Reference in New Issue
Block a user