Á¦¸ñ : <¾ÆÀÌÄÜ #2> ¾È³çÇϼ¼¿ä Ç㸣¹ÌÀÔ´Ï´Ù. ¿À´ÃÀº ¾ÆÀÌÄÜ Ãâ·Â,File ºÎ ºÐÀ» ¿Ï°áÁö¾îº¸µµ·Ï ÇÏ°ÚÀ¾´Ï´Ù. ¿ì¼± Icondraw.exe ¿¡ Æ÷Ç﵂ ¾î ÀÖ´Â File Load/Save ºÎºÐÀ» º¸µµ·Ï ÇÏÁÒ. int store() { char sizeb[2]; char *sav[4]; int i; unsigned size; char *vhdr="Hurumi LIB 1.5 VGA Icon File "; char *hhdr="Hurumi LIB 1.5 HERC Icon File "; FILE *fpt; if (!isfill) return ESC; sizeb[0]=(char)gicon->size.xwidth; sizeb[1]=(char)gicon->size.ywidth; size=(unsigned)(gicon->size.xwidth*gicon->size.ywidth); if (!_H) { for (i=0;i<4;i++) { sav[i]=(char *)malloc((size_t)size); hgVGetImagePlane(67,205,67+gicon->size.xwidth-1,205+gico n->size.ywidth-1,i,sav[i]); } fpt=fopen(fname,"wb"); fwrite(vhdr,33,1,fpt); /* write header */ for (i=0;i<4;i++) fwrite(sav[i],size,1,fpt); /* write data */ fseek(fpt,30,0); putc(0x1a,fpt); /* send EOF */ fseek(fpt,31,0); /* skip one ch. */ putc(sizeb[0],fpt); /* send Xsize */ putc(sizeb[1],fpt); /* send Ysize */ fclose(fpt); for (i=0;i<4;i++) free(sav[i]); } else { sav[0]=(char *)malloc((size_t)size); hercgetimage(67,205,67+gicon->size.xwidth-1,205+gicon->s ize.ywidth-1,sav[0]); fpt=fopen(fname,"wb"); fwrite(hhdr,33,1,fpt); /* write header */ fwrite(sav[0],size,1,fpt); /* write data */ fseek(fpt,30,0); putc(0x1a,fpt); /* send EOF */ fseek(fpt,31,0); /* skip one ch. */ putc(sizeb[0],fpt); /* send Xsize */ putc(sizeb[1],fpt); /* send Ysize */ fclose(fpt); free(sav[0]); } ismodify=0; return 1; } store ÇÔ¼ö´Â _H flag ÀÇ °ª¿¡ µû¶ó¼­ Hercules Çü½Ä ȤÀº VGA Çü½ÄÀ¸·Î ÀúÀåÇÕ´Ï´Ù. ÇÔ¼ö³»ºÎ¸¦ º¸¸é ¾Ë ¼ö ÀÖÁö¸¸ VGA ÀÇ °æ ¿ì hgVGetImagePlane ÇÔ¼ö¸¦ Àо ¹öÆÛ 4 °³¿¡ ÇÒ´çÇÏ°í ÀÖÀ¾ ´Ï´Ù. ÀÌ°ÍÀ» fwrite ·Î ½áÁÖ´Â °ÍÀÌÁÒ. Çì´õ¸¦ Á¦ÀÏ Ã³À½¿¡ ³Ö °í.. 0x1a (EOF) ¸¦ ³ÖÀ½À¸·Î½á type ¸í·É¿¡ ÀÇÇؼ­ ÀÌ»óÇÑ ¹®ÀÚ °¡ ³ªÅ¸³ª´Â °ÍÀ» ¿¹¹æÇÏ°í ÀÖÀ¾´Ï´Ù. Hercules ÀÇ °æ¿ì ±×³É È­ ¸éÀ» ¹öÆÛ¿¡ ÀúÀåÇÏ¸é µË´Ï´Ù. ¿©±â¿¡¼­´Â ¿¹Àü °­Á¿¡¼­ ¼Ò°³Çß ´ø hercgetimage ÇÔ¼ö¸¦ ±×´ë·Î »ç¿ëÇÏ°í ÀÖÀ¾´Ï´Ù. Àü °­Á¸¦ Âü°íÇϼ¼¿ä. ±×·³ ÀÌ·¸°Ô Çؼ­ ÀúÀåÇÑ µ¥ÀÌÅ͸¦ ÀоîµéÀÌ´Â ºÎºÐ Àº Ç㸣¹Ì ÇÑ±Û ¶óÀ̺귯¸®¿¡ Æ÷ÇԵǾî ÀÖ´Â Load ÇÔ¼ö¸¦ Âü°íÇÏ µµ·Ï ÇսôÙ. HICON *hgHICON_VLoad(char *fname) { char hdr[40]; unsigned size; FILE *fpt; int xs,ys; HICON *p; int i; fpt=fopen(fname,"rb"); if (fpt==NULL) return NULL; p=(HICON *)malloc(sizeof(HICON)); fseek(fpt,31,0); xs=getc(fpt); /* get Xsize */ ys=getc(fpt); /* get Ysize */ fseek(fpt,0,0); fread(hdr,33,1,fpt); /* read header */ size=(unsigned) ( xs*ys ); for (i=0;i<4;i++) { p->buff[i]=(char *)malloc((size_t)size); fread(p->buff[i],size,1,fpt); } fclose(fpt); p->size.xwidth=xs; p->size.ywidth=ys; return p; } ÀÏ´Ü Å©±â¸¦ Àаí Çì´õ¸¦ Pass ÇÑÈÄ Å©±â¿¡ µû¶ó µ¥ÀÌÅ͸¦ 4 Plane Àаí ÀÖÀ¾´Ï´Ù. HICON Àº ¾ÆÀÌÄÜ °´Ã¼ÀÇ Á¤ÀǷμ­ xsize,ysize,buff ·Î Á¤Àǵ˴ϴÙ. ±×·¸°Ô Çؼ­ ¹öÆÛ¿¡ ÀоîÁö¸é À̸¦ Ç¥½ÃÇØ ÁÖ´Â ·çƾÀº ´ÙÀ½°ú °°½À´Ï´Ù. void hgHICON_VDraw(HICON *p,int x,int y) { vicon_out(x,y,p->buff[0],p->size.xwidth,p->size.ywidth,1); vicon_out(x,y,p->buff[1],p->size.xwidth,p->size.ywidth,2); vicon_out(x,y,p->buff[2],p->size.xwidth,p->size.ywidth,4); vicon_out(x,y,p->buff[3],p->size.xwidth,p->size.ywidth,8); } ±×Àú È£ÃâÇÏ¸é µË´Ï´Ù. Çãŧ·¹½ºÀÇ °æ¿ì¸¦ º¼±î¿ä ? HICON *hgHICON_HLoad(char *fname) { char hdr[40]; unsigned size; FILE *fpt; int xs,ys; HICON *p; fpt=fopen(fname,"rb"); if (fpt==NULL) return NULL; p=(HICON *)malloc(sizeof(HICON)); fseek(fpt,31,0); xs=getc(fpt); /* get Xsize */ ys=getc(fpt); /* get Ysize */ fseek(fpt,0,0); fread(hdr,33,1,fpt); /* read header */ size=(unsigned) ( xs*ys ); p->buff[0]=(char *)malloc((size_t)size); fread(p->buff[0],size,1,fpt); /* read data */ fclose(fpt); p->size.xwidth=xs; p->size.ywidth=ys; return p; } void hgHICON_HDraw(HICON *p,int x,int y) { hicon_out(x,y,p->buff[0],p->size.xwidth,p->size.ywidth); } ´Ù¸¥ °ÍÀÌ ÀÖ´Ù¸é Load ÇÔ¼ö¿¡¼­ buff[0] ¸¸À» »ç¿ëÇÏ¿© ÀÐ¾î µé Àδٴ Á¡ÀÔ´Ï´Ù. Ãâ·Â ·çƾÀº hicon_out À» ¾²°í ÀÖÀ¾´Ï´Ù. ÀÌ °ÍÀº Àú¹ø °­ÁÂÀÇ vicon_out ÇÔ¼ö¸¦ Çãŧ·¹½ºÈ­ ÇÑ °ÍÀÔ´Ï´Ù. void hicon_out(int x,int y,char *buff,int m,int n) { int x_width=m; int y_width=n; unsigned offset=ret_herc_offset(y); asm push ds asm mov bx,offset asm lds si,buff asm mov ax,0b000h /* segment setting */ asm mov es,ax asm mov dx,WORD PTR x asm mov ax,dx asm shr dx,1 asm shr dx,1 asm shr dx,1 asm add bl,dl asm adc bh,0 asm and al,07h asm mov cl,al asm dec cl asm jnc nosign asm mov cl,8 nosign: asm mov ah,080h asm shr ah,cl asm dec ah /* ah = bitmask */ asm mov di,bx asm mov bx,ax /* bx <- ax */ asm mov cx,WORD PTR y_width nloop: asm push cx asm push di asm mov cx,WORD PTR x_width mloop: asm push cx asm mov cl,al asm mov al,ds:[si] asm ror al,cl asm mov ch,al asm not ah asm and es:[di],ah asm not ah asm and ah,al asm or es:[di],ah asm mov ax,bx asm mov al,ch asm and es:[di+1],ah asm not ah asm and ah,al asm or es:[di+1],ah asm mov ax,bx asm inc si asm inc di asm pop cx asm loop mloop asm pop di asm pop cx asm add di,2000h asm cmp di,8000h asm jb enext4 asm sub di,07fb0h enext4: asm loop nloop asm pop ds } hputchmn °ú °ÅÀÇ ºñ½ÁÇϹǷΠ´õ ¼³¸íÇÏÁö´Â ¾Ê°ÚÀ¾´Ï´Ù. ÁÖÀÇÇØ ¼­ º¼ Á¡À̶ó¸é color ¸¦ ÀÔ·ÂÀ¸·Î ¹ÞÁö ¾Ê½À´Ï´Ù. ¹«Á¶°Ç µ¤¾î ¾²±â ¸ðµå·Î Ç쵂 ±×·¡ÇÈ ÁÂÇ¥¸¦ Áö¿øÇØ¾ß ÇϹǷΠ¾à°£ÀÇ ºñÆ®¿¬ »êÀ» ¼öÇàÇÏ°í ÀÖÀ¾´Ï´Ù. ´õ ÀÚ¼¼È÷ ¾Ë°í ½ÍÀ¸½Å ºÐÀº hputchmn ÇÔ¼öµî¿¡¼­ÀÇ ZERO color ÀÇ Ãâ·Â°úÁ¤À» ã¾Æº¸½Ã¸é µÉ °Ì´Ï´Ù. ÀÌ ÇÔ¼ö´Â ZERO color ¶ó°í °¡Á¤ÇÏ°í Ãâ·ÂÇÏ°í ÀÖÀ¾´Ï´Ù. ZERO color ´Â ±×·¡ÇÈ ÁÂÇ¥¸¦ Áö¿øÇϸ鼭µµ Ãâ·ÂµÇ¾î¾ß ÇÒ ºÎºÐÀº Overwrite ÇÏ°í ½ÍÀ»¶§ »ç¿ëÇÕ´Ï´Ù. À̰͵µ Ç㸣¹Ì 1.5 ¿¡¼­ µµ ÀÔµÈ °³³äÀε¥ ¿¹Àü °­Áµ鿡 ÀÚ¼¼È÷ ¼³¸íÀÌ ³ª¿Í ÀÖÀ¾´Ï´Ù. ÀÌ °æ¿ì mov ¸í·ÉÀ» ½á¹ö¸®¸é Overwrite ´Â µÇÁö¸¸ °¡·Î µµÆ®´ÜÀ§·Î Ãâ·ÂÇÒ¶§ ÇÊ¿äÇÑ Masking À» ÇÒ ¼ö°¡ ¾ø°Ô µË´Ï´Ù. Âü°íÇϼ¼¿ä. Âü..Àú¹ø °­Á¿¡¼­ »©³õ°í ¼³¸íÇÏÁö ¾ÊÀº ºÎºÐÀÌ Àִµ¥.. Á¡ÀÐ ±â ·çƾÀÇ ¼³¸íÀÔ´Ï´Ù. VGA ÀÇ '»ö' Àº ¾Æ½Ã´Ù½ÃÇÇ 4 plane ÀÇ È¥ÇÕÀÔ´Ï´Ù. º¸Åë 16 color ¶ó°í ÇÏ´Â °ÍÀº 4 Plane À» °¢°¢ 0,1 ·ÎÇ¥ÇöÇÒ¶§ °¡·Î·Î ´Ã¾î³õÀº 4 ºñÆ®ÀÇ °ªÀÔ´Ï´Ù. Èò»öÀº Ä÷¯°ª 15 À̹ǷΠ1111 , Áï 4 Plane ÀÌ ¸ðµÎ 1 ÀÎ °æ¿ìÀÔ´Ï´Ù. Á¡Àб⠷çƾ¿¡¼­´Â Plane ¹øÈ£¸¦ 3,2,1,0 ·Î ¹Ù²Ù¾î °¡¸é¼­ ¾òÀº µ¥ÀÌÅÍ ¸¦ x ÁÂÇ¥¿¡ ÀÇÇؼ­ °è»êÇÑ Bitmask ¿Í AND ½ÃŲ °ªÀÌ 1 À̸é ÇØ ´ç Plane °ªÀ» 1 ·Î ÇÏ°í 0 À̸é 0 À¸·Î ³õ¾Æ µÓ´Ï´Ù. ÀÌ°ÍÀº 4 ¹øÀÇ ½¬ÇÁÆ® ¿¬»ê¿¡ ÀÇÇؼ­ ÇØ°áµÇ´Âµ¥.. 󸮴 ´ÙÀ½°ú °°½À´Ï ´Ù. 1. plane <- 3,value <- 0 2. value << 1 3. read data from screen 4. and data,bitmask 5. if not zero, value++ 6. offset Á¶Á¤,plane-- 7. 2 ·Î °¨.. 4 ¹ø ¹Ýº¹ ¼Ò½º¿Í Àß ºñ±³ÇØ º¸¼¼¿ä. ±×·³ Çãŧ·¹½º¿¡¼­ÀÇ Á¡Àбâ,Á¡Âï±â ·çƾÀ» º¸¸é¼­ ³¡À» ³»°ÚÀ¾ ´Ï´Ù. ÀÌ Á¡Àбâ,Á¡Âï±â ·çƾµéÀº ´ÙÀ½ °­Á³»¿ëÀÎ Line,Circle ¿¡ ¶Ç ¾²À̴ϱî Àß ÀÐ¾î µÎ¼¼¿ä.. void hgHPlotXy(int x,int y,char color) { unsigned offset=ret_herc_offset(y); asm mov ax,0b000h asm mov es,ax asm mov bx,offset asm mov dx,WORD PTR x asm mov ax,dx asm shr dx,1 asm shr dx,1 asm shr dx,1 asm add bl,dl asm adc bh,0 asm and al,07h asm mov cl,al asm mov ah,080h asm shr ah,cl asm mov al,BYTE PTR color asm cmp al,ZERO asm jz zerop asm or es:[bx],ah /* not ZERO */ return; zerop: asm not ah asm and es:[bx],ah /* ZERO */ return; } char hgHGetPlotXy(int x,int y) { unsigned offset=ret_herc_offset(y); asm mov ax,0b000h asm mov es,ax asm mov bx,offset asm mov dx,WORD PTR x asm mov ax,dx asm shr dx,1 asm shr dx,1 asm shr dx,1 asm add bl,dl asm adc bh,0 asm and al,07h asm mov cl,al asm mov ah,080h asm shr ah,cl asm mov al,15 /* this is WHITE */ asm and ah,es:[bx] asm jnz next asm dec al asm dec al /* this is ZERO */ next: asm mov ah,0 } ¹¹ º°´Ù¸¥ °ÍÀº ¾øÀ¾´Ï´Ù. Á¡Âï±â ·çƾ¿¡¼­´Â color °¡ ZERO °¡ ¾Æ´Ï¸é È­¸é°ú OR ÇÏ°í ZERO À̸é bit mask ¸¦ ¹ÝÀüÇؼ­ AND ÇÕ ´Ï´Ù. ZERO ´Â °ËÀº»öÀ¸·Î ¾²´Â °ÍÀ̹ǷΠOR Çؼ­´Â Èò»ö¹è°æ À§ ¿¡ ³ªÅ¸³ªÁö ¾ÊÁÒ. ±×·¡¼­ ÀÌ·¯ÇÑ Ã³¸®¸¦ ÇØÁÖ¾î¾ß ÇÏ´Â °ÍÀÔ´Ï ´Ù. Á¡Àб⠿¡¼­´Â ±× Á¡ÀÇ ºñÆ®°¡ 0 À̸é ZERO °ª ( color 13 ) À»,¾Æ´Ï¸é WHITE °ª ( color 15 ) ¸¦ ¸®ÅÏÇØ ÁÝ´Ï´Ù. ¸®ÅÏÇÒ¶§´Â char ÇüÀ̹ǷΠal ¿¡ °ªÀ» ³Ö¾îÁÖ¸é µË´Ï´Ù. ±×·³... ´ÙÀ½ °­Á ±îÁö.. ¾È³çÈ÷. Ç㸣¹Ì.