diff --git a/!Run,feb b/!Run,feb new file mode 100644 index 0000000..b5bada1 --- /dev/null +++ b/!Run,feb @@ -0,0 +1,5 @@ +Set TheEscape$Dir +IconSprites .!Sprites +WimpSlot -min 512k -max 512k +Dir +Run .!RunImage \ No newline at end of file diff --git a/!RunImage,ff8 b/!RunImage,ff8 new file mode 100644 index 0000000..7654428 Binary files /dev/null and b/!RunImage,ff8 differ diff --git a/!Sprites,ff9 b/!Sprites,ff9 new file mode 100644 index 0000000..5de963b Binary files /dev/null and b/!Sprites,ff9 differ diff --git a/!Sprites22,ff9 b/!Sprites22,ff9 new file mode 100644 index 0000000..6c40a52 Binary files /dev/null and b/!Sprites22,ff9 differ diff --git a/Makefile,fe1 b/Makefile,fe1 new file mode 100644 index 0000000..11c7902 --- /dev/null +++ b/Makefile,fe1 @@ -0,0 +1,55 @@ +# Project: CTheEscape + + +# Toolflags: +CCflags = -c -depend !Depend -IC: -throwback -w +Linkflags = -aif -o $@ +#ObjAsmflags = -depend !Depend -Stamp -quit -CloseExec +#CMHGflags = +#LibFileflags = -c -o $@ +#Squeezeflags = -o $@ + + +# Final targets: +@.!RunImage: @.o.CTheEscape @.o.Graphics @.o.Sound C:o.stubs + Link $(Linkflags) @.o.CTheEscape @.o.Graphics @.o.Sound 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 + +# 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.Sound: c.Sound +o.Sound: C:h.swis +o.Sound: C:h.kernel +o.Sound: C:h.kernel +o.Sound: h.Sound diff --git a/Spr,ff9 b/Spr,ff9 new file mode 100644 index 0000000..bded19b Binary files /dev/null and b/Spr,ff9 differ diff --git a/c/CTheEscape b/c/CTheEscape new file mode 100644 index 0000000..46497aa --- /dev/null +++ b/c/CTheEscape @@ -0,0 +1,99 @@ +#include +#include "swis.h" +#include +#include +#include "Sound.h" + +// SWI Registers +_kernel_swi_regs inreg; +_kernel_swi_regs outreg; + +// Sprite buffer +unsigned char *buffer; + +extern struct CompositionElement composition[128]; + +void intro() +{ + int currentstart = 0; + + sound_voices(4); + + sound_set_voice(1,"WaveSynth-Beep"); + sound_set_voice(2,"WaveSynth-Beep"); + sound_set_voice(3,"WaveSynth-Beep"); + sound_set_voice(4,"WaveSynth-Beep"); + sound_composition_init(); + + // DUn, dun, daan duhhn + sound_composition_element_add(currentstart,1,sound_note("A4#"),200); + sound_composition_element_add(currentstart,2,sound_note("A5#"),200); + currentstart += 200; + sound_composition_element_add(currentstart,1,sound_note("F3"),200); + sound_composition_element_add(currentstart,2,sound_note("F4"),200); + currentstart += 200; + sound_composition_element_add(currentstart,1,sound_note("G3#"),200); + sound_composition_element_add(currentstart,2,sound_note("G4#"),200); + currentstart += 200; + sound_composition_element_add(currentstart,1,sound_note("C3"),200); + sound_composition_element_add(currentstart,2,sound_note("C4"),200); + currentstart += 200; + + // DUn, dun, daan duhhn + sound_composition_element_add(currentstart,1,sound_note("A3#"),200); + sound_composition_element_add(currentstart,2,sound_note("A4#"),200); + currentstart += 200; + sound_composition_element_add(currentstart,1,sound_note("F2"),200); + currentstart += 200; + sound_composition_element_add(currentstart,2,sound_note("G2#"),200); + currentstart += 200; + sound_composition_element_add(currentstart,1,sound_note("C2"),200); + currentstart += 250; + + // Duh + sound_composition_element_add(currentstart,3,sound_note("A3#"),300); + sound_composition_element_add(currentstart,4,sound_note("A2#"),300); + currentstart += 200; + + //REM Dun De Da + sound_composition_element_add(currentstart,1,sound_note("F1"),20); + currentstart += 50; + sound_composition_element_add(currentstart,2,sound_note("A2#"),5); + currentstart += 20; + sound_composition_element_add(currentstart,1,sound_note("D2#"),200); + currentstart += 180; + + + sound_composition_element_add(currentstart,2,sound_note("D2"),50); + currentstart += 50; + sound_composition_element_add(currentstart,1,sound_note("A2#"),30); + currentstart += 30; + sound_composition_element_add(currentstart,2,sound_note("G1"),50); + currentstart += 50; + sound_composition_element_add(currentstart,1,sound_note("C2"),50); + currentstart += 50; + sound_composition_element_add(currentstart,3,sound_note("A2#"),100); + sound_composition_element_add(currentstart,4,sound_note("F2"),100); + currentstart += 100; + + draw_sprite("tng",320,400); + + sound_composition_start(clock()); + + while(sound_composition_incomplete()) + sound_composition_tick(clock()); +} + +int main(int argc, char *argv[]) +{ + sound_on(); + + display_mode(28); + load_sprites("Spr"); + + intro(); + + free(buffer); + + return 0; +} diff --git a/c/Graphics b/c/Graphics new file mode 100644 index 0000000..b4071dc --- /dev/null +++ b/c/Graphics @@ -0,0 +1,80 @@ +#include +#include "swis.h" +#include + +// SWI Registers +extern _kernel_swi_regs inreg; +extern _kernel_swi_regs outreg; + +extern unsigned char *buffer; + + +// 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) +{ + // mode 28 80x60 640x480 16 colours + inreg.r[0] = 0; + inreg.r[1] = mode; + _kernel_swi(OS_ScreenMode,&inreg,&outreg); +} + +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); +} diff --git a/c/Sound b/c/Sound new file mode 100644 index 0000000..50f09af --- /dev/null +++ b/c/Sound @@ -0,0 +1,143 @@ +#include +#include "swis.h" +#include +#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_composition_element_play(struct CompositionElement element) +{ + inreg.r[0] = element.Channel; + inreg.r[1] = element.Volume; + inreg.r[2] = element.Note; + inreg.r[3] = element.Length; + _kernel_swi(Sound_Control,&inreg,&outreg); +} + +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("------------------------------\n"); +} + +void sound_composition_start(int cent) +{ + composition_startcent = cent; +} + +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; +} diff --git a/h/Sound b/h/Sound new file mode 100644 index 0000000..805ffe5 --- /dev/null +++ b/h/Sound @@ -0,0 +1,8 @@ +#define COMPOSITION_MAX 128 +struct CompositionElement { +int Start; +int Note; +int Volume; +int Channel; +int Length; +};