📄 wrdt_mac.c
字号:
/* TiMidity++ -- MIDI to WAVE converter and player Copyright (C) 1999-2002 Masanao Izumo <mo@goice.co.jp> Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA wrdt_mac.c Written by by T.Nogami <t-nogami@happy.email.ne.jp>*/#ifdef HAVE_CONFIG_H#include "config.h"#endif /* HAVE_CONFIG_H */#include <stdio.h>#include <stdlib.h>#ifndef NO_STRING_H#include <string.h>#else#include <strings.h>#endif#include "timidity.h"#include "common.h"#include "instrum.h"#include "playmidi.h"#include "readmidi.h"#include "controls.h"#include "wrd.h"#include "VTparse.h"//#include <Palettes.h>#include "mac_main.h"#include "mac_c.h"#include "mac_wrdwindow.h"#include "mac_mag.h"#include "mac_wrd.h"#include "aq.h"static int wrd_argc;//static int wrd_args[WRD_MAXPARAM];static int inkey_flag;//#define WRD_DEBUG(x) ctl->cmsg x #define WRD_DEBUG(x) /*nothing*/static int wrdt_open(char *wrdt_opts);static void wrdt_apply(int cmd, int wrd_argc, int wrd_args[]);static void wrdt_update_events(void);static int wrdt_start(int wrdflag){ if( wrdflag ){ #ifdef ENABLE_SHERRY sry_start(); #endif ctl->cmsg(CMSG_INFO, VERB_VERBOSE, "WRD START"); } return 0;}static void wrdt_end(void){ wrd_argc = 0; inkey_flag = 0; #ifdef ENABLE_SHERRY sry_end(); #endif ctl->cmsg(CMSG_INFO, VERB_VERBOSE, "WRD END");}static void wrdt_end(void);static void wrdt_close(void);#define wrdt mac_wrdt_mode#define win mac_WrdWindowWRDTracer wrdt ={ "mac WRD tracer", 'm', 0, wrdt_open, wrdt_apply, #ifdef ENABLE_SHERRY sry_wrdt_apply, #else NULL, #endif wrdt_update_events, wrdt_start, wrdt_end, wrdt_close};// ***********************************************// Low level outputvoid dev_set_height(int height){ SizeWindow(win.ref, WRD_GSCR_WIDTH, height, false);}static void mac_RedrawControl(int flag){ dev_redrawflag=flag;}void dev_redisp(Rect rect){ GDHandle oldGD; GWorldPtr oldGW; if( !dev_redrawflag ) return; //ActivatePalette(win.ref); LOCK_ALL_PIXMAP(); GetGWorld(&oldGW, &oldGD); SetPortWindowPort(win.ref); RGBBackColor(&white); RGBForeColor(&black); CopyBits((BitMap*)&DISP_PIX, &win.ref->portBits, &rect, &rect, srcCopy,0); SetGWorld(oldGW, oldGD); UNLOCK_ALL_PIXMAP();}static void reverse_helper(int x, int y, int byte){ Rect rect; rect.left=WRD_LOCX(x); //erase upper rect.top=WRD_LOCY(y-1)+3; rect.right=rect.left+BASE_X*byte; rect.bottom=rect.top+1; PaintRect(&rect); rect.left=WRD_LOCX(x)+7*byte; //erase right //rect.top=WRD_LOCY(y-1)+2; rect.right=rect.left+byte; rect.bottom=WRD_LOCY(y)+3; PaintRect(&rect);}static void dev_text_redraw(int locx1, int locy1, int locx2, int locy2){ int x,y,startx, mode,color, len; GDHandle oldGD; GWorldPtr oldGW; if( !wrd_ton ) return; if( locx1<1 ) locx1=1; if( locx2>80 ) locx2=80; if( locy1<1 ) locy1=1; if( locy2>25 ) locy2=25; if( wrd_ton==2 ){ //locx1-= (locx1-1)%4; locx1=1; } LOCK_ALL_PIXMAP(); GetGWorld(&oldGW, &oldGD); SetGWorld(dispWorld,0); TextMode(srcOr); for( y=locy1; y<=locy2; y++){ startx=locx1; if( startx-1>=1 && MULTI_BYTE_FLAG(startx-1,y) ) startx--; for( x=startx; x<=locx2; ){ if( CHAR_VRAM(x,y)==0 ){ x++; continue;} SET_T_RGBFORECOLOR_TMP(CHAR_COLOR_VRAM(x,y)&CATTR_TXTCOL_MASK); mode= (CHAR_COLOR_VRAM(x,y)&CATTR_BGCOLORED)? 2:1; color= TCODE2INDEX(CHAR_COLOR_VRAM(x,y)); len= MULTI_BYTE_FLAG(x,y)? 2:1; if( wrd_ton==2 ){ char *cp; if( MULTI_BYTE_FLAG(x-1,y) ){ cp= &CHAR_VRAM(x-1,y); len=2; SET_T_RGBFORECOLOR_TMP(CHAR_COLOR_VRAM(x-1,y)&CATTR_TXTCOL_MASK); mode= (CHAR_COLOR_VRAM(x-1,y)&CATTR_BGCOLORED)? 2:1; color= TCODE2INDEX(CHAR_COLOR_VRAM(x-1,y)); }else{ cp= &CHAR_VRAM(x,y); } dev_draw_text_gmode( dispWorld->portPixMap, WRD_LOCX(x), WRD_LOCY(y-1)+3, cp, len, 0xFF, mode, color, color, wrd_ton ); x+= len*2; continue; } (CHAR_COLOR_VRAM(x,y)&CATTR_BGCOLORED)? TextMode(notSrcOr) : TextMode(srcOr); WRD_MOVE_COURSOR_TMP(x,y); if( MULTI_BYTE_FLAG(x,y) ){ DrawText(&CHAR_VRAM(x,y), 0, 2); if(CHAR_COLOR_VRAM(x,y)&CATTR_BGCOLORED) reverse_helper(x,y, 2); x+=2; }else{ if( CHAR_VRAM(x,y)==' ' && (CHAR_COLOR_VRAM(x,y)&CATTR_BGCOLORED) ){ Rect rect; //speedy draw rect.top=WRD_LOCY(y-1)+3; rect.left=WRD_LOCX(x); rect.bottom=rect.top+BASE_Y; rect.right=rect.left+BASE_X; PaintRect(&rect); x++; }else{ DrawText(&CHAR_VRAM(x,y), 0, 1); if(CHAR_COLOR_VRAM(x,y)&CATTR_BGCOLORED) reverse_helper(x,y, 1); x++; } } } } SetGWorld(oldGW, oldGD); UNLOCK_ALL_PIXMAP();}static void dev_text_redraw_rect(Rect rect){ dev_text_redraw(rect.left/BASE_X+1, rect.top/BASE_Y+1, rect.right/BASE_X+1, rect.bottom/BASE_Y+1);}void dev_remake_disp(Rect rect){ //copy gdisp -> disp, draw text on gdisp LOCK_ALL_PIXMAP(); if( dev_gon_flag) MyCopyBits(GDISP_PIX, DISP_PIX, rect, rect, 0, 0, 0xFF, 0,0,0); else dev_box(DISP_PIX, rect, 0, 0xFF); //all pal=0 color UNLOCK_ALL_PIXMAP(); dev_text_redraw_rect(rect);}static Rect loc2rect(int locx1, int locy1, int locx2, int locy2){ Rect rect; if( locx1 < 1 ) locx1=1; if( locx2 > COLS ) locx2=COLS; if( locy1 < 1 ) locy1=1; if( locy2 > LINES ) locy2=LINES; rect.top=WRD_LOCY(locy1-1)+3; rect.left=WRD_LOCX(locx1); rect.bottom=WRD_LOCY(locy2)+3; rect.right=WRD_LOCX(locx2+1); return rect;}static void dev_text_clear(int locx1, int locy1, int locx2, int locy2, int color, char ch, int need_update){ // clear (x1,y1) .... (x2,y1) int y, startx,endx, width; if( COLS<locx2 ) locx2=COLS; if( locx1<0 || COLS<locx1 || locx2<0 || locy1<0 || LINES<locy1 || locy2<0 || LINES<locy2 ) return; if( locx2 < locx1 ) return; if( ch==' ' && !(color & 0x08) ){ch=0;} width=locx2-locx1+1; for( y=locy1; y<=locy2; y++ ){ startx= locx1-(MULTI_BYTE_FLAG(locx1-1,y)? 1:0); endx= locx2+(MULTI_BYTE_FLAG(locx2,y)? 1:0); width=endx-startx+1; memset(&CHAR_VRAM(startx,y), ch, width); memset(&MULTI_BYTE_FLAG(startx,y), 0, width); memset(&CHAR_COLOR_VRAM(startx,y), color, width); } if( need_update ){ Rect rect=loc2rect(locx1-1, locy1, locx2+1, locy2); //take margin dev_remake_disp(rect); dev_redisp(rect); }}static void dev_text_clear_all(){ memset(&CHAR_VRAM(0,0), 0, sizeof(char_vram)); memset(&MULTI_BYTE_FLAG(0,0), 0, sizeof(multi_byte_flag));}static void dev_text_output(const char* text, int n){ int i, startx=wrd_coursor_x, endx=wrd_coursor_x+n-1; GDHandle oldGD; GWorldPtr oldGW; if( wrd_coursor_x<=0 || 81<=wrd_coursor_x || wrd_coursor_y<=0 || 26 <=wrd_coursor_y ) return; LOCK_ALL_PIXMAP(); GetGWorld(&oldGW, &oldGD); dev_text_clear(startx, wrd_coursor_y, endx, wrd_coursor_y, 0, 0, false); SetGWorld(oldGW, oldGD); UNLOCK_ALL_PIXMAP(); for( i=0; i<n; i++ ){ if( wrd_coursor_x+i<=0 || 81<=wrd_coursor_x+i || wrd_coursor_y<=0 || 26 <=wrd_coursor_y ) continue; CHAR_VRAM(wrd_coursor_x+i,wrd_coursor_y)=text[i]; CHAR_COLOR_VRAM(wrd_coursor_x+i,wrd_coursor_y)= wrd_text_color_attr; if( IS_MULTI_BYTE(text[i]) ){ MULTI_BYTE_FLAG(wrd_coursor_x+i,wrd_coursor_y)=1; if( i<n ){ i++; CHAR_VRAM(wrd_coursor_x+i,wrd_coursor_y)=text[i]; MULTI_BYTE_FLAG(wrd_coursor_x+i,wrd_coursor_y)=0; } } } wrd_coursor_x+=n; if( wrd_ton==2) endx+=2; dev_remake_disp(loc2rect(startx-1, wrd_coursor_y, endx+1, wrd_coursor_y)); dev_redisp(loc2rect(startx-1, wrd_coursor_y, endx+1, wrd_coursor_y));}static void dev_text_scroll(int x1, int y1, int x2, int y2, int mode, int color, char ch, int num){ int y,width; if( num<=0 ) return; switch(mode) { case 0: //scroll upper for( y=y1; y<=y2 && y<=LINES; y++ ){ if( y-num <y1 ) continue; memcpy(&CHAR_VRAM(1,y-num),&CHAR_VRAM(1,y),COLS); memcpy(&CHAR_COLOR_VRAM(1,y-num),&CHAR_COLOR_VRAM(1,y),COLS); memcpy(&MULTI_BYTE_FLAG(1,y-num),&MULTI_BYTE_FLAG(1,y),COLS); } dev_text_clear(x1, y2-num+1, x2, y2, color, ch, false); break; case 1: //scroll down for( y=y2; y>=y1 && y>=1; y-- ){ if( y+num> y2 ) continue; memcpy(&CHAR_VRAM(1,y+num),&CHAR_VRAM(1,y),COLS); memcpy(&CHAR_COLOR_VRAM(1,y+num),&CHAR_COLOR_VRAM(1,y),COLS); memcpy(&MULTI_BYTE_FLAG(1,y+num),&MULTI_BYTE_FLAG(1,y),COLS); } dev_text_clear(x1, y1, x2, y1+num-1, color, ch, false); break; case 2: //scroll right case 3: //scroll left if( mode==3 ) num*=-1; if( x1+num<1 ) x1=1-num; if( x2+num>COLS ) x2=COLS-num; width=x2-x1+1; if( width<=0 ) break; for( y=y1; y<=y2 && y<=LINES; y++ ){ memmove(&CHAR_VRAM(x1+num,y),&CHAR_VRAM(x1,y),width); memmove(&CHAR_COLOR_VRAM(x1+num,y),&CHAR_COLOR_VRAM(x1,y),width); memmove(&MULTI_BYTE_FLAG(x1+num,y),&MULTI_BYTE_FLAG(x1,y),width); } if( mode==2 ) //right dev_text_clear(x1, y1, x1+num-1, y2, color, ch, false); else if( mode==3 ) dev_text_clear(x2+num+1, y1, x2, y2, color, ch, false); break; }}static void dev_move_coursor(int x, int y){ wrd_coursor_x=x; wrd_coursor_y=y; if( wrd_coursor_x<1 ) wrd_coursor_x=1; else if( wrd_coursor_x>COLS ) wrd_coursor_x=COLS; if( wrd_coursor_y<1 ) wrd_coursor_y=1; else if( wrd_coursor_y>LINES ) wrd_coursor_y=LINES;}static void dev_newline(){ if( wrd_coursor_y>=25 ){ dev_text_scroll(1, 1, 80, 25, 0, 0, 0, 1); dev_remake_disp(portRect); dev_redisp(portRect); dev_move_coursor(1, 25); }else{ dev_move_coursor(1, wrd_coursor_y+1); }}static void dev_clear_graphics(int pmask){ //clear active bank only GDHandle oldGD; GWorldPtr oldGW; GetGWorld(&oldGW, &oldGD); LOCK_ALL_PIXMAP(); SetGWorld(graphicWorld[activeGraphics],0); dev_box(GACTIVE_PIX, portRect, 0, pmask); UNLOCK_ALL_PIXMAP(); SetGWorld(oldGW, oldGD); if( activeGraphics==dispGraphics ){ dev_remake_disp(portRect); dev_redisp(portRect); }}#define CHECK_RECT(rect) { \ short tmp; \ if( rect.left>rect.right ){ tmp=rect.left; rect.left=rect.right; rect.right=tmp;} \ if( rect.top>rect.bottom ){ tmp=rect.top; rect.top=rect.bottom; rect.bottom=tmp;} \}void dev_gmove(int x1, int y1, int x2, int y2, int xd, int yd, GWorldPtr srcworld, GWorldPtr destworld, int sw, int trans, int pmask, int maskx, int masky, const uint8 maskdata[]){ static Rect src,dest, rect; GDHandle oldGD; GWorldPtr oldGW; if( srcworld==NULL || destworld==NULL ){ ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Can't use gvram bank" ); return; } LOCK_ALL_PIXMAP(); GetGWorld(&oldGW, &oldGD); LockPixels(srcworld->portPixMap); LockPixels(destworld->portPixMap); SetRect(&src, x1,y1,x2+1,y2+1); CHECK_RECT(src); SetRect(&dest, xd,yd, xd+x2-x1+1, yd+y2-y1+1); CHECK_RECT(dest); SetPortWindowPort(win.ref); RGBBackColor(&white); RGBForeColor(&black); if( sw==0 ){ //simple copy //CopyBits((BitMap*)&graphicWorld[vs]->portPixMap, (BitMap*)&graphicWorld[vd]->portPixMap, // &src, &dest, srcCopy,0); //make offscreen Graphics MyCopyBits(srcworld->portPixMap, destworld->portPixMap, src, dest, 0, 0, gmode_mask,0,0,0); //make offscreen Graphics } else if(sw==1){ //exchange CopyBits((BitMap*)&srcworld->portPixMap, (BitMap*)&destworld->portPixMap, &src, &dest, srcXor,0); CopyBits((BitMap*)&destworld->portPixMap, (BitMap*)&srcworld->portPixMap, &dest, &src, srcXor,0); CopyBits((BitMap*)&srcworld->portPixMap, (BitMap*)&destworld->portPixMap, &src, &dest, srcXor,0); //make offscreen Graphics } else if(sw==2){ //xor copy CopyBits((BitMap*)&srcworld->portPixMap, (BitMap*)&destworld->portPixMap, &src, &dest, srcXor,0); //make offscreen Graphics }else if( sw & 0x10 ){ //xcopy mode MyCopyBits(srcworld->portPixMap, destworld->portPixMap, src, dest, sw, trans, pmask, maskx, masky, maskdata); //make offscreen Graphics } SetGWorld(oldGW, oldGD); UNLOCK_ALL_PIXMAP(); UnlockPixels(srcworld->portPixMap); UnlockPixels(destworld->portPixMap); if( graphicWorld[dispGraphics]==destworld ){ dev_remake_disp(dest); dev_redisp(dest); } if( graphicWorld[dispGraphics]==srcworld && sw==1 ){ //exchange? update src dev_remake_disp(src); dev_redisp(src); }}static void dev_gscreen(int act, int dis){ if( act!=0 && act!=1 ) return; if( dis!=0 && dis!=1 ) return; activeGraphics=act; if( dispGraphics!=dis ){ dispGraphics=dis; dev_remake_disp(portRect); dev_redisp(portRect); }}static int dev_get_pixel(int x, int y){ Ptr baseadr; int rowBytes; baseadr=GetPixBaseAddr(graphicWorld[activeGraphics]->portPixMap); rowBytes= (**graphicWorld[activeGraphics]->portPixMap).rowBytes & 0x1FFF; return baseadr[y*rowBytes+x];}void dev_gline(int x1, int y1, int x2, int y2, int p1, int sw, int p2, GWorldPtr world){ Rect rect; GDHandle oldGD; GWorldPtr oldGW; GetGWorld(&oldGW, &oldGD); LockPixels(world->portPixMap); SetGWorld(world,0); rect.left=x1; rect.right=x2; rect.top=y1; rect.bottom=y2; CHECK_RECT(rect); switch(sw) { case 0: //line if( p2==0 || p2==WRD_NOARG ) p2= 0xFF; dev_line(x1, y1, x2, y2, p1,p2, gmode_mask_gline, world->portPixMap ); break; case 1: //rect if( p2==0 || p2==WRD_NOARG ) p2= 0xFF; dev_line(x1, y1, x2, y1, p1,p2, gmode_mask_gline,world->portPixMap ); dev_line(x1, y1, x1, y2, p1,p2, gmode_mask_gline,world->portPixMap ); dev_line(x2, y1, x2, y2, p1,p2, gmode_mask_gline,world->portPixMap ); dev_line(x1, y2, x2, y2, p1,p2, gmode_mask_gline,world->portPixMap ); break; case 2: //filled rect if( p2==WRD_NOARG ) p2= p1; rect.right++; rect.bottom++; dev_box(world->portPixMap, rect, p2, gmode_mask_gline); if( p1!=p2 ){ dev_line(x1, y1, x2, y1, p1,0xFF, gmode_mask_gline,world->portPixMap ); dev_line(x1, y1, x1, y2, p1,0xFF, gmode_mask_gline,world->portPixMap ); dev_line(x2, y1, x2, y2, p1,0xFF, gmode_mask_gline,world->portPixMap ); dev_line(x1, y2, x2, y2, p1,0xFF, gmode_mask_gline,world->portPixMap ); } break; } SetGWorld(oldGW, oldGD); UnlockPixels(world->portPixMap); if( graphicWorld[dispGraphics]==world ){ rect.right++; rect.bottom++; dev_remake_disp(rect); if( pallette_exist) dev_redisp(rect); }}static void dev_gcircle(int x, int y, int r, int p1, int sw, int p2){ //int onbit; Rect rect; GDHandle oldGD; GWorldPtr oldGW; GetGWorld(&oldGW, &oldGD); LockPixels(GACTIVE_PIX); SetGWorld(graphicWorld[activeGraphics],0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -