tfv: split up the files

This commit is contained in:
Vince Weaver 2017-08-12 20:15:34 -04:00
parent 13119609e1
commit bc9937215f
7 changed files with 253 additions and 188 deletions

View File

@ -28,12 +28,20 @@ text.o: text.c
####
tfv: tfv.o gr-sim.o
$(CC) $(LFLAGS) $(SDL_LIBS) -o tfv tfv.o gr-sim.o
tfv_opener.o: tfv_opener.c tfv_utils.h
$(CC) $(CFLAGS) -c tfv_opener.c
tfv_utils.o: tfv_utils.c tfv_utils.h
$(CC) $(CFLAGS) -c tfv_utils.c
tfv.o: tfv.c gr-sim.h backgrounds.h tfv_sprites.h
$(CC) $(CFLAGS) -c tfv.c
tfv: tfv.o tfv_opener.o tfv_utils.o gr-sim.o
$(CC) $(LFLAGS) $(SDL_LIBS) -o tfv tfv.o tfv_opener.o tfv_utils.o gr-sim.o
###

View File

@ -98,6 +98,7 @@ label140:
for(l=(y-S);l<=(y+S);l+=(r/4)+1) {
for(k=(x-S);k<=(x+S);k+=r) {
basic_plot(k,l);
grsim_update();
}
}
}

View File

@ -4,182 +4,25 @@
#include <string.h>
#include "gr-sim.h"
#include "tfv_utils.h"
#include "tfv_zp.h"
#include "tfv_sprites.h"
#include "backgrounds.h"
/* Page Zero */
#define COLOR1 0x00
#define COLOR2 0x01
#define MATCH 0x02
#define XX 0x03
#define YY 0x04
#define YADD 0x05
#define LOOP 0x06
#define MEMPTRL 0x07
#define MEMPTRH 0x08
#define DISP_PAGE 0x09
#define DRAW_PAGE 0x0a
/* stats */
static unsigned char level=0;
static unsigned char hp=50,max_hp=100;
static unsigned char limit=2;
static unsigned char money=0,experience=0;
static unsigned char time_hours=0,time_minutes=0;
static unsigned char items1=0xff,items2=0xff;
static unsigned char steps=0;
unsigned char level=0;
unsigned char hp=50,max_hp=100;
unsigned char limit=2;
unsigned char money=0,experience=0;
unsigned char time_hours=0,time_minutes=0;
unsigned char items1=0xff,items2=0xff;
unsigned char steps=0;
/* location */
static unsigned char map_x=5;
static char tfv_x=15,tfv_y=19;
static unsigned char ground_color;
static void page_flip(void) {
if (ram[DISP_PAGE]==0) {
soft_switch(HISCR);
ram[DISP_PAGE]=1;
ram[DRAW_PAGE]=0;
}
else {
soft_switch(LOWSCR);
ram[DISP_PAGE]=0;
ram[DRAW_PAGE]=1;
}
}
static void draw_segment(void) {
for(ram[LOOP]=0;ram[LOOP]<4;ram[LOOP]++) {
ram[YY]=ram[YY]+ram[YADD];
if (ram[XX]==ram[MATCH]) color_equals(ram[COLOR1]*3);
else color_equals(ram[COLOR1]);
vlin(ram[DRAW_PAGE],10,ram[YY],9+ram[XX]);
if (ram[XX]==ram[MATCH]) color_equals(ram[COLOR2]*3);
else color_equals(ram[COLOR2]);
if (ram[YY]!=34) vlin(ram[DRAW_PAGE],ram[YY],34,9+ram[XX]);
ram[XX]++;
}
ram[YADD]=-ram[YADD];
}
static void draw_logo(void) {
ram[XX]=0;
ram[YY]=10;
ram[YADD]=6;
ram[COLOR1]=1;
ram[COLOR2]=0;
draw_segment();
ram[COLOR2]=4;
draw_segment();
ram[COLOR1]=2;
draw_segment();
draw_segment();
draw_segment();
ram[COLOR2]=0;
draw_segment();
page_flip();
grsim_update();
}
static int repeat_until_keypressed(void) {
int ch;
while(1) {
ch=grsim_input();
if (ch!=0) break;
usleep(10000);
}
return ch;
}
static int select_menu(int x, int y, int num, char **items) {
int result=0;
int ch,i;
while(1) {
for(i=0;i<num;i++) {
basic_htab(x);
basic_vtab(y+i);
if (i==result) {
basic_inverse();
basic_print("--> ");
}
else {
basic_print(" ");
}
basic_print(items[i]);
basic_normal();
grsim_update();
}
ch=repeat_until_keypressed();
if (ch=='\r') break;
if (ch==' ') break;
if (ch==APPLE_RIGHT) result++;
if (ch==APPLE_DOWN) result++;
if (ch==APPLE_LEFT) result--;
if (ch==APPLE_UP) result--;
if (result>=num) result=num-1;
if (result<0) result=0;
}
return result;
}
static void apple_memset(char *ptr, int value, int length) {
a=value;
x=length;
y=0;
while(x>0) {
ptr[y]=a;
y++;
x--;
}
}
static int opening(void) {
/* VMW splash */
ram[MATCH]=100;
draw_logo();
usleep(200000);
for(ram[MATCH]=0;ram[MATCH]<30;ram[MATCH]++) {
draw_logo();
grsim_update();
usleep(20000);
}
basic_vtab(21);
basic_htab(9);
basic_print("A VMW SOFTWARE PRODUCTION");
grsim_update();
repeat_until_keypressed();
return 0;
}
unsigned char map_x=5;
char tfv_x=15,tfv_y=19;
unsigned char ground_color;
static char *title_menu[]={
"NEW GAME",
@ -482,16 +325,6 @@ static void show_map(void) {
repeat_until_keypressed();
}
void print_u8(unsigned char value) {
char temp[4];
sprintf(temp,"%d",value);
basic_print(temp);
}
/*
1 2 3 4
@ -664,13 +497,6 @@ List hits
*/
static void print_byte(unsigned char value) {
char temp[4];
sprintf(temp,"%3d",value);
temp[3]=0;
basic_print(temp);
}
/* Enemies: */
/* Killer Crab, Tree, Big Fish, Procrastinon */

73
gr-sim/tfv_opener.c Normal file
View File

@ -0,0 +1,73 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "gr-sim.h"
#include "tfv_utils.h"
#include "tfv_zp.h"
static void draw_segment(void) {
for(ram[LOOP]=0;ram[LOOP]<4;ram[LOOP]++) {
ram[YY]=ram[YY]+ram[YADD];
if (ram[XX]==ram[MATCH]) color_equals(ram[COLOR1]*3);
else color_equals(ram[COLOR1]);
vlin(ram[DRAW_PAGE],10,ram[YY],9+ram[XX]);
if (ram[XX]==ram[MATCH]) color_equals(ram[COLOR2]*3);
else color_equals(ram[COLOR2]);
if (ram[YY]!=34) vlin(ram[DRAW_PAGE],ram[YY],34,9+ram[XX]);
ram[XX]++;
}
ram[YADD]=-ram[YADD];
}
static void draw_logo(void) {
ram[XX]=0;
ram[YY]=10;
ram[YADD]=6;
ram[COLOR1]=1;
ram[COLOR2]=0;
draw_segment();
ram[COLOR2]=4;
draw_segment();
ram[COLOR1]=2;
draw_segment();
draw_segment();
draw_segment();
ram[COLOR2]=0;
draw_segment();
page_flip();
grsim_update();
}
int opening(void) {
/* VMW splash */
ram[MATCH]=100;
draw_logo();
usleep(200000);
for(ram[MATCH]=0;ram[MATCH]<30;ram[MATCH]++) {
draw_logo();
grsim_update();
usleep(20000);
}
basic_vtab(21);
basic_htab(9);
basic_print("A VMW SOFTWARE PRODUCTION");
grsim_update();
repeat_until_keypressed();
return 0;
}

121
gr-sim/tfv_utils.c Normal file
View File

@ -0,0 +1,121 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "gr-sim.h"
#include "tfv_sprites.h"
#include "backgrounds.h"
/* Page Zero */
#define COLOR1 0x00
#define COLOR2 0x01
#define MATCH 0x02
#define XX 0x03
#define YY 0x04
#define YADD 0x05
#define LOOP 0x06
#define MEMPTRL 0x07
#define MEMPTRH 0x08
#define DISP_PAGE 0x09
#define DRAW_PAGE 0x0a
int repeat_until_keypressed(void) {
int ch;
while(1) {
ch=grsim_input();
if (ch!=0) break;
usleep(10000);
}
return ch;
}
int select_menu(int x, int y, int num, char **items) {
int result=0;
int ch,i;
while(1) {
for(i=0;i<num;i++) {
basic_htab(x);
basic_vtab(y+i);
if (i==result) {
basic_inverse();
basic_print("--> ");
}
else {
basic_print(" ");
}
basic_print(items[i]);
basic_normal();
grsim_update();
}
ch=repeat_until_keypressed();
if (ch=='\r') break;
if (ch==' ') break;
if (ch==APPLE_RIGHT) result++;
if (ch==APPLE_DOWN) result++;
if (ch==APPLE_LEFT) result--;
if (ch==APPLE_UP) result--;
if (result>=num) result=num-1;
if (result<0) result=0;
}
return result;
}
void apple_memset(char *ptr, int value, int length) {
a=value;
x=length;
y=0;
while(x>0) {
ptr[y]=a;
y++;
x--;
}
}
void print_u8(unsigned char value) {
char temp[4];
sprintf(temp,"%d",value);
basic_print(temp);
}
void print_byte(unsigned char value) {
char temp[4];
sprintf(temp,"%3d",value);
temp[3]=0;
basic_print(temp);
}
void page_flip(void) {
if (ram[DISP_PAGE]==0) {
soft_switch(HISCR);
ram[DISP_PAGE]=1;
ram[DRAW_PAGE]=0;
}
else {
soft_switch(LOWSCR);
ram[DISP_PAGE]=0;
ram[DRAW_PAGE]=1;
}
}

6
gr-sim/tfv_utils.h Normal file
View File

@ -0,0 +1,6 @@
int repeat_until_keypressed(void);
int select_menu(int x, int y, int num, char **items);
void apple_memset(char *ptr, int value, int length);
void print_u8(unsigned char value);
void print_byte(unsigned char value);
void page_flip(void);

30
gr-sim/tfv_zp.h Normal file
View File

@ -0,0 +1,30 @@
/* Page Zero */
#define COLOR1 0x00
#define COLOR2 0x01
#define MATCH 0x02
#define XX 0x03
#define YY 0x04
#define YADD 0x05
#define LOOP 0x06
#define MEMPTRL 0x07
#define MEMPTRH 0x08
#define DISP_PAGE 0x09
#define DRAW_PAGE 0x0a
/* stats */
extern unsigned char level;
extern unsigned char hp,max_hp;
extern unsigned char limit;
extern unsigned char money,experience;
extern unsigned char time_hours,time_minutes;
extern unsigned char items1,items2;
extern unsigned char steps;
/* location */
extern unsigned char map_x;
extern char tfv_x,tfv_y;
extern unsigned char ground_color;
int opening(void);