1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-11-26 13:49:21 +00:00
C02/test/structs.c02

121 lines
2.3 KiB
Plaintext
Raw Normal View History

2019-05-13 03:34:47 +00:00
/*********************************
* STRUCTS - Test C02 structures *
*********************************/
2018-11-07 05:12:05 +00:00
//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;
2018-11-07 05:12:05 +00:00
//Define Structure
struct record { /* Sample Record */
2019-05-13 03:34:47 +00:00
char name[8]; //Name
char index; //Index
int addr; //Address
char data[128]; //Data
2018-11-07 05:12:05 +00:00
};
//Declare Structure Variable
struct record srcrec;
struct record dstrec;
2019-05-13 03:34:47 +00:00
//Structs Containing Structs
struct point {char x, y; };
2018-11-07 05:12:05 +00:00
struct point pnt;
2019-05-13 03:34:47 +00:00
struct rect {struct point toplft, btmrgt; };
2018-11-07 05:12:05 +00:00
struct rect box;
2019-05-13 03:34:47 +00:00
struct frame {struct rect outer, inner; };
2018-11-07 05:12:05 +00:00
struct frame fram;
main:
//Set Structure Members
2019-05-13 03:34:47 +00:00
strdst(srcrec.name); strcpy("RECNAME");
2018-11-07 05:12:05 +00:00
srcrec.index = 1;
2019-05-13 03:34:47 +00:00
srcrec.addr = &srcrec;
2018-11-07 05:12:05 +00:00
for (i = 0; i<=@srcrec.data; i++)
srcrec.data[i] = i;
//Clear Destination Record
2019-05-13 03:34:47 +00:00
memclr(@dstrec, dstrec);
2018-11-07 05:12:05 +00:00
prtdst();
//Copy Source Record into Destination Record
2019-05-13 03:34:47 +00:00
memdst(dstrec);
memcpy(@srcrec, srcrec);
2018-11-07 05:12:05 +00:00
prtdst();
//Clear Box
2019-05-13 03:34:47 +00:00
memclr(@box, box); //Clear Box Members
prtbox(""); //Print Box Members
2018-11-07 05:12:05 +00:00
//Set Box Members
2019-05-13 03:34:47 +00:00
box.toplft.x=1; box.toplft.y=2;
box.btmrgt.x=8; box.btmrgt.y=9;
prtbox("");
2018-11-07 05:12:05 +00:00
newlin();
//Clear Frame
2019-05-13 03:34:47 +00:00
memclr(@fram, fram); //Clear Frame Members
2018-11-07 05:12:05 +00:00
prtfrm(); //Print Frame Members
//Set Frame Members
2019-05-13 03:34:47 +00:00
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;
2018-11-07 05:12:05 +00:00
prtfrm();
newlin();
goto exit;
//Print Destination Record
void prtdst() {
2019-05-13 03:34:47 +00:00
setdst(dstrec.name); printf("REC.NAME=\"%s\"%n");
printf(dstrec.index, "REC.INDEX=%d%n");
2019-05-13 03:34:47 +00:00
setdst(dstrec.addr); printf("REC.ADDR=$%w%n");
puts("REC.DATA=[");
2018-11-07 05:12:05 +00:00
for (i = 0; i<@dstrec.data; i++) {
if (i) putc(',');
putdec(dstrec.data[i]);
}
putln("]");
anykey();
2018-11-07 05:12:05 +00:00
}
//Print Frame
void prtfrm() {
2019-05-13 03:34:47 +00:00
cpybox(fram.outer); prtbox("OUTER.");
cpybox(fram.inner); prtbox("INNER.");
anykey();
2018-11-07 05:12:05 +00:00
}
void cpybox() {
2019-05-13 03:34:47 +00:00
savrxy(); setdst(box);
2018-11-07 05:12:05 +00:00
resrxy(); memcpy(@box);
}
//Print Box
2019-05-13 03:34:47 +00:00
void prtbox(yx) {
puts(yx); puts("TOPLFT."); prtpnt(box.toplft);
puts(yx); puts("BTMRGT."); prtpnt(box.btmrgt);
2018-11-07 05:12:05 +00:00
}
//Print Point
void prtpnt() {
2019-05-13 03:34:47 +00:00
savrxy(); setdst(pnt);
2018-11-07 05:12:05 +00:00
resrxy(); memcpy(@pnt);
2019-05-13 03:34:47 +00:00
printf(pnt.x,"X=%d,");
printf(pnt.y,"Y=%d%n");
2018-11-07 05:12:05 +00:00
}