1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-11-22 16:34:15 +00:00
C02/test/structs.c02
2019-05-12 23:34:47 -04:00

121 lines
2.3 KiB
Plaintext

/*********************************
* STRUCTS - Test C02 structures *
*********************************/
//Specify System Header using -H option
#include <stddef.h02>
#include <stdlib.h02>
#include <stdio.h02>
#include <stdiox.h02>
#include <memory.h02>
#include <string.h02>
char d, i;
char aa,xx,yy;
int yx;
//Define Structure
struct record { /* Sample Record */
char name[8]; //Name
char index; //Index
int addr; //Address
char data[128]; //Data
};
//Declare Structure Variable
struct record srcrec;
struct record dstrec;
//Structs Containing Structs
struct point {char x, y; };
struct point pnt;
struct rect {struct point toplft, btmrgt; };
struct rect box;
struct frame {struct rect outer, inner; };
struct frame fram;
main:
//Set Structure Members
strdst(srcrec.name); strcpy("RECNAME");
srcrec.index = 1;
srcrec.addr = &srcrec;
for (i = 0; i<=@srcrec.data; i++)
srcrec.data[i] = i;
//Clear Destination Record
memclr(@dstrec, dstrec);
prtdst();
//Copy Source Record into Destination Record
memdst(dstrec);
memcpy(@srcrec, srcrec);
prtdst();
//Clear Box
memclr(@box, box); //Clear Box Members
prtbox(""); //Print Box Members
//Set Box Members
box.toplft.x=1; box.toplft.y=2;
box.btmrgt.x=8; box.btmrgt.y=9;
prtbox("");
newlin();
//Clear Frame
memclr(@fram, fram); //Clear Frame Members
prtfrm(); //Print Frame Members
//Set Frame Members
fram.outer.toplft.x=10; fram.outer.toplft.y=11;
fram.outer.btmrgt.x=98; fram.outer.btmrgt.y=99;
fram.inner.toplft.x=22; fram.inner.toplft.y=23;
fram.inner.btmrgt.x=86; fram.inner.btmrgt.y=87;
prtfrm();
newlin();
goto exit;
//Print Destination Record
void prtdst() {
setdst(dstrec.name); printf("REC.NAME=\"%s\"%n");
printf(dstrec.index, "REC.INDEX=%d%n");
setdst(dstrec.addr); printf("REC.ADDR=$%w%n");
puts("REC.DATA=[");
for (i = 0; i<@dstrec.data; i++) {
if (i) putc(',');
putdec(dstrec.data[i]);
}
putln("]");
anykey();
}
//Print Frame
void prtfrm() {
cpybox(fram.outer); prtbox("OUTER.");
cpybox(fram.inner); prtbox("INNER.");
anykey();
}
void cpybox() {
savrxy(); setdst(box);
resrxy(); memcpy(@box);
}
//Print Box
void prtbox(yx) {
puts(yx); puts("TOPLFT."); prtpnt(box.toplft);
puts(yx); puts("BTMRGT."); prtpnt(box.btmrgt);
}
//Print Point
void prtpnt() {
savrxy(); setdst(pnt);
resrxy(); memcpy(@pnt);
printf(pnt.x,"X=%d,");
printf(pnt.y,"Y=%d%n");
}