#include <config.c>
#include <zas.inc>
#include <zas1.inc>
#include <fnt.inc>
#define THA 0x1700 /* text home adr */
#define GHA 0x0000 /* graph home adr & attribute home adr*/
#define CGRAM 0x1c00 /* CG-RAM home adr */
void delay(unsigned int i)
{
while ( i--!=0);
}
void stat_lcd(void)
{
while((C_LCD&3)!=3);
}
void outgraph(char n)
{
unsigned int siz;
data char ch;
D_LCD=GHA & 0x00ff;
stat_lcd();
D_LCD=(GHA & 0xff00)>>8;
stat_lcd();
C_LCD=0x24;
stat_lcd();
C_LCD=0xb0;
stat_lcd();
for (siz=0;siz < sizeof(zast);siz++){
while((C_LCD&0x8)!=0x8);
if(n) ch=zast1[siz];
else ch=zast[siz];
D_LCD=ch;
}
while((C_LCD&0x8)!=0x8);
C_LCD=0xb3;
}
void outstr(char *str)
{
data char ch;
stat_lcd();
C_LCD=0xb0;
stat_lcd();
while (*str!=0){
while((C_LCD&0x8)!=0x8);
ch=*(str++);
if (ch<128) ch-=0x20;
D_LCD=ch;
}
while((C_LCD&0x8)!=0x8);
C_LCD=0xb3;
}
void setcur(char x,char y,char t)
{
stat_lcd(); /* CURSOR SET ADR*/
D_LCD=x;
stat_lcd();
D_LCD=y;
stat_lcd();
C_LCD=0x21;
stat_lcd(); /* CURSOR SET PATTERN */
C_LCD=0xa0 | (t&7) ;
}
void gotoxy(char x,char y)
{
unsigned int ad;
ad=THA+(y*40)+x;
stat_lcd(); /* SET ADRESS POINTER */
D_LCD=(ad & 0x00ff);
stat_lcd();
D_LCD=(ad & 0xff00)>>8;
stat_lcd();
C_LCD=0x24;
}
void init_text(void) {
unsigned int ch;
LCD_RES=0;
delay(20);
LCD_RES=1;
LCD_HMODE=1;
stat_lcd(); /* ONLY text,cursor on,blinc on */
C_LCD = 0x97; /*10010111b;*/
stat_lcd(); /* CG ROM + ONLY TEXT */
C_LCD=0x80; /*10000000b*/
stat_lcd(); /* SET ADRESS POINTER CG-RAM */
D_LCD=0;
stat_lcd();
D_LCD=0x1c;
stat_lcd();
C_LCD=0x24;
stat_lcd(); /*LOAD CG-RAM*/
C_LCD=0xb0;
stat_lcd();
for (ch=0;ch<1024;ch++){
while((C_LCD&0x8)!=0x8);
D_LCD=font[ch];
}
while((C_LCD&0x8)!=0x8);
C_LCD=0xb3;
stat_lcd(); /*TEXT AREA SET */
D_LCD=0x28;
stat_lcd();
D_LCD=0;
stat_lcd();
C_LCD=0x41;
stat_lcd(); /*OFFSET REGISTER SET */
D_LCD=3; /* CG-RAM home adr 0x1c00 */
stat_lcd();
D_LCD=0;
stat_lcd();
C_LCD=0x22;
stat_lcd(); /* TEXT HOME ADR */
D_LCD=THA & 0x00ff;
stat_lcd();
D_LCD=(THA & 0xff00)>>8;
stat_lcd();
C_LCD=0x40;
setcur(50,0,0);
}
void init_graph(void){ LCD_RES=0;
delay(20);
LCD_RES=1;
LCD_HMODE=0; /* 8bit*30*/
stat_lcd(); /* CG ROM + ONLY TEXT */
C_LCD=0x80; /*10000000b*/
stat_lcd(); /* ONLY Graph */
C_LCD = 0x98; /*10011000b;*/
stat_lcd();
D_LCD=0x1e; /*GRAPHIX AREA SET */
stat_lcd();
D_LCD=0;
stat_lcd();
C_LCD=0x43;
stat_lcd(); /* GRAPH HOME ADR */
D_LCD=GHA & 0x00ff;
stat_lcd();
D_LCD=(GHA & 0xff00)>>8;
stat_lcd();
C_LCD=0x42;
}
int putchar(int val)
{
stat_lcd();
if (val<128) val-=0x20;
D_LCD=val;
stat_lcd();
C_LCD=0xc0;
return (val);
}