diff harelet.c @ 19:8fe0b5711413

Added BasedTremGrx and Dvorak
author VilyaemKenyaz
date Wed, 27 Sep 2023 01:47:28 -0400
parents 7bf25e90a1de
children 0555050bada0
line wrap: on
line diff
--- a/harelet.c	Tue Sep 26 23:19:42 2023 -0400
+++ b/harelet.c	Wed Sep 27 01:47:28 2023 -0400
@@ -7,27 +7,16 @@
 #include <stdio.h> 
 #include <stdlib.h>
 #include <string.h>
+#include <assert.h>
 
 #include "basedfilelib.h"
-
-#ifdef __linux__
-#include "linuxconio.h"
-#endif
-
-#ifdef _WIN32
-#include <windows.h>>
-#include <conio.h>
-#endif
+#include "basedtermgrx.h"
 
 #define DEEPNESS 5
 #define MAXPOINT 4096
 #define UNITS	"G20\n"
 #define SPEED	20
 
-#define SBPUP "JZ &ZUP\n"
-#define SBPDWN 0.0625
-
-
 typedef struct{
 	unsigned int X;
 	unsigned int Y;
@@ -36,8 +25,8 @@
 
 point points[MAXPOINT];
 
-unsigned int X = 100;
-unsigned int Y = 25;
+unsigned int X = 5;
+unsigned int Y = 5;
 unsigned int step = 5;
 unsigned int down = 0;
 unsigned int numpoints = 0;
@@ -45,11 +34,23 @@
 
 
 /*********************************************
-* Description - Convert integers to strings, makes
-* source code more pretty.
-* Author - William King
-* Date - Sep 26 2023
-* *******************************************/
+ * Description - Warn the user about something
+ * Author - William King
+ * Date - Sep 27 2023
+ * *******************************************/
+void Warn(char * s){
+	printf("WARNING:");
+	puts(s);
+	putchar('\a');
+	getchar();
+}
+
+/*********************************************
+ * Description - Convert integers to strings, makes
+ * source code more pretty.
+ * Author - William King
+ * Date - Sep 26 2023
+ * *******************************************/
 char * IntToString(int num){
 	char * s;
 	sprintf(s,"%d",num);
@@ -62,37 +63,27 @@
  * Date - Sep 08 2023
  * *******************************************/
 void Render(){	
-	clrscr();
-	gotoxy(0,3);
+	ClrScr();
 	puts("HARELET A CAD PROGRAM BY VILYAEM KENYAZ, PEEP SOFTWARE 2023");
 	printf("Number of Points: %d X: %d Y: %d STEPSIZE: %d DWN?: %d\n",numpoints,X,Y,step,down);
 
 	//Render points
-	for(int i = 0;i != MAXPOINT;i++){
-		gotoxy(0,50);
-
-		gotoxy(points[i].X,points[i].Y);
+	if(numpoints > 0){
+		for(int i = 0;i != numpoints;i++){
+			if(points[i].down == 0){
+				DrawChar(points[i].X,points[i].Y,'U');
 
-		if(points[i].down == 0){
-			printf("X");
+			}
+			else{
+				DrawChar(points[i].X,points[i].Y,'D');
+			}
 		}
-		else{
-			printf("*");
-		}
-
-
 	}
 
 	//Render cursor
-
-	gotoxy(X,Y);
-
-	puts("&");
+	DrawChar(X,Y,'&');
 
-	//Move cursor to top of document, so its not trailing the cadcursor
-	gotoxy(0,0);
-
-
+	Splash();
 
 }
 
@@ -108,7 +99,6 @@
 	char buffer[64];
 	unsigned int choice;
 
-	clrscr();
 	puts("Select your format\n1. RAW GCODE\n2. OPENSBP");
 	scanf("%d",&choice);
 
@@ -125,14 +115,10 @@
 			//Compose
 			char instruction[64];
 			strcat(instruction,"G0 X ");
-			//Convert X to string
-			sprintf(buffer,"%d",points[i].X);
-			strcat(instruction,buffer);
+			strcat(instruction,IntToString(points[i].X));
 			strcat(instruction," Y ");
-			//Convert Y to string
-			sprintf(buffer,"%d",points[i].Y);
-			strcat(instruction,buffer);
-			if(points[i].down = 1){
+			strcat(instruction,IntToString(points[i].Y));
+			if(points[i].down == 1){
 				strcat(instruction," Z 5\n");
 			}
 			else{
@@ -147,11 +133,11 @@
 		WriteFile(filename,file);
 	}
 	else if(choice == 2){
-	// Setup the miller
-	strcat(file,"'OpenSBP file written by Harelet\n'Harelet, written by William King\n'No responsibilty is taken for any damages to any equipment\n\n'Starting\nSO, 1,1\nPause 2\nSA,\n&ZUP = 0.25\nMH\n\n'Bulk of instructions\n");
+		// Setup the miller
+		strcat(file,"'OpenSBP file written by Harelet\n'Harelet, written by William King\n'No responsibilty is taken for any damages to any equipment\n\n'Starting\nSO, 1,1\nPause 2\nSA,\n&ZUP = 0.25\nMH\n\n'Bulk of instructions\n");
 
-	for(int i = 0;i != numpoints;i++){
-	
+		for(int i = 0;i != numpoints;i++){
+
 			char instruction[64];
 
 			strcat(instruction,"J2 ");
@@ -166,27 +152,22 @@
 			else{
 				strcat(instruction,"JZ,&ZUP\n");
 			}
-				
 
 			strcat(file,instruction);
-	}
+		}
 
-	//Finished, add instructions to wait for the user
-	strcat(file,"\nJ2,0,0\nSO, 1,0\n'All done. Wait for user.\nPAUSE");
+		//Finished, add instructions to wait for the user
+		strcat(file,"\nJ2,0,0\nSO, 1,0\n'All done. Wait for user.\nPAUSE");
 
-	WriteFile(filename,file);
+		WriteFile(filename,file);
 
 	}
 	else{
-
-		puts("Invalid compiliation format");
-		scanf("");
-
-
+		Warn("Invalid compiliation format");
 	}
 
 	puts("Finished compiling instructions");
-	scanf("");
+	getchar();
 
 }
 
@@ -197,27 +178,33 @@
  * Date - Sep 08 2023
  * *******************************************/
 void main(int argc, char* argv[]){
-	clrscr();
 	while(1){
 		Render();
+#ifndef DVORAK
 		switch(getchar()){
 			case 'h': 
-				X -= step;
+				if(X - step >= 2){
+					X -= step;
+				}	
 				break;
 			case 'j': 
-				Y += step;
+				if(Y + step < RESY - step){
+					Y += step;
+				}
 				break;
 			case 'k': 
-				Y -= step;
+				if(Y - step >= 2){
+					Y -= step;
+				}
 				break;
 			case 'l': 
-				X += step;
+				if(X + step < RESX - step){
+					X += step;
+				}
 				break;
-
 			case 's': 
-				puts("New stepsize");
+				puts("New stepsize:");
 				scanf("%d",&step);
-
 				break;
 
 			case 'a': 
@@ -234,18 +221,69 @@
 					down = 1;
 				}
 				break;
-
 			case 'c': 
 				Compile();
 				break;
 			case 'q':
-				clrscr();
+				ClrScr();
 				exit(0);
 				break;
 			default:
-				putchar('\a');
 				break;
 		}
+#endif
+#ifdef DVORAK
+		switch(getchar()){
+			case 'a': 
+				if(X - step >= 2){
+					X -= step;
+				}	
+				break;
+			case 'o': 
+				if(Y + step < RESY - step){
+					Y += step;
+				}
+				break;
+			case ',': 
+				if(Y - step >= 2){
+					Y -= step;
+				}
+				break;
+			case 'e': 
+				if(X + step < RESX - step){
+					X += step;
+				}
+				break;
+			case '.': 
+				puts("New stepsize:");
+				scanf("%d",&step);
+				break;
+
+			case ' ': 
+				points[numpoints].X = X;
+				points[numpoints].Y = Y;
+				points[numpoints].down = down;
+				numpoints++;
+				break;
+			case 'p':
+				if(down == 1){
+					down = 0;
+				}
+				else{
+					down = 1;
+				}
+				break;
+			case 'y': 
+				Compile();
+				break;
+			case 'q':
+				ClrScr();
+				exit(0);
+				break;
+			default:
+				break;
+		}
+#endif
 	}
 
 	exit(0);