extra.c
上传用户:qddsws
上传日期:2022-06-22
资源大小:723k
文件大小:43k
- #include <extra/extra.h>
- #include "pointer.c"
- #include "header.c"
- #include <devices/psmouse.h>
- #include <devices/rtc.h>
- #include <initbuses.h>
-
- #include "dots.c"
- #include "zero.c"
- #include "one.c"
- #include "two.c"
- #include "three.c"
- #include "four.c"
- #include "five.c"
- #include "six.c"
- #include "seven.c"
- #include "eight.c"
- #include "nine.c"
- #include "memory.c"
- #include "dock.c"
- #include "write.c"
- #include "abouticon.c"
- #include "draw.c"
- #include "pong.c"
- #include "gnu.c"
- #include "halt.c"
- /* Plans */
- static unsigned long* plane_list[MAX_PLANES];
- static int last_plane;
- static int background_plane;
- /* Finestres */
- static struct Window root_win;
- static struct Window* focus_win;
- /* devices */
- static struct device* mouse;
- static struct device* rtc;
- static struct device* keyboard;
- void print_shade_plane(int x1, int y1, int x2, int y2, int dir,int plane) {
- int color=0x00;
- unsigned short* video=(unsigned short*)plane_list[plane];
- unsigned short* temp_plane=(unsigned char*)plane_list[plane];
- int col,fil;
- int sizex;
- int sizey;
- int act_plane;
- int r,g,b;
- float factor=0.1;
- unsigned short pixel;
- (x1>x2)?(sizex=x1-x2):(sizex=x2-x1);
- (y1>y2)?(sizey=y1-y2):(sizey=y2-y1);
- for (fil=0;fil<((sizey+y1>SCREEN_HEIGHT)?(SCREEN_HEIGHT-y1):(sizey));fil++)
- for (col=0;col<sizex*SCREEN_BPP;col=col+SCREEN_BPP) {
- act_plane=plane+1;
- pixel=ALPHA_COLOR;
- while (act_plane<=last_plane&&pixel==ALPHA_COLOR) {
- temp_plane=(unsigned short*)plane_list[act_plane];
- if (temp_plane!=0){
- pixel=(temp_plane[(y1+fil)*SCREEN_WIDTH+x1+col/SCREEN_BPP]);
- }
- else{
- pixel=ALPHA_COLOR;
- }
- act_plane++;
- }
- if (dir==LR_SHADE) {
- if (fil<(sizey/2)) factor=((float)(1/(float)((sizey/2)))*((sizey/2)-fil));
- else factor=((float)(1/(float)((sizey/2)))*(fil-(sizey/2)));
- factor=(0.6*factor)+((((float)(1/(float)(sizex*2))*(col))));
- factor=factor+0.2;
- }
- if (dir==TD_SHADE) {
- if (col<(sizex)) factor=((float)(1/(float)((sizex)))*((sizex)-col));
- else factor=((float)(1/(float)((sizex)))*(col-(sizex)));
- factor=(0.6*factor)+((((float)(1/(float)(sizey))*(fil))));
- factor=factor+0.2;
- }
- if (factor>1) factor=1;
- r=(pixel>>11)&0x1F;
- g=(pixel>>6)&0x1F;
- b=pixel&0x1F;
-
- r=r*factor;
- g=g*factor;
- b=b*factor;
-
- pixel=(r<<11)|(g<<6)|b;
-
-
- /* Fer transparencia */
- color=pixel;
-
- video[(y1+fil)*SCREEN_WIDTH+x1+col/SCREEN_BPP]=pixel;
- }
-
- }
- void init_windows () {
- INIT_LIST_HEAD (&(root_win.list));
- INIT_LIST_HEAD (&(root_win.events.list));
- }
- void draw_erase_function (struct Window* win) {
- paint_trans_rectangle_plane (win->x,win->y+15,win->x+win->sizex,win->y+win->sizey,win->bkgcolor,win->plane);
- paint_rectangle_plane (win->x,win->y+15, win->x+100, win->y+50, 0xFF00,win->plane) ;
- xyprint_plane(win->x+28,win->y+10+15,"ERASE",win->plane);
- print_composed_plane_region(win->x,win->y,win->x+win->sizex,win->mousey+win->sizey);
- }
- void draw_function (struct Window* win) {
- paint_rectangle_plane (win->mousex,win->mousey, win->mousex+5, win->mousey+5, 0x0000,win->plane) ;
- }
- void draw_init_function (struct Window* win) {
- struct mouse_event* events;
- win->icon=draw_16bpp;
- win->iconx=254;
- win->icony=545;
- /* Event draw function */
- events =(struct mouse_event*)kmalloc(sizeof(struct mouse_event));
- events->x1rel=0;
- events->y1rel=15;
- events->x2rel=win->sizex;
- events->y2rel=win->sizey;
- events->but=2;
- events->function=(void*)&draw_function;
- list_add(&(events->list),&(win->events.list));
- /* Event erase function */
- paint_rectangle_plane (win->x,win->y+15, win->x+100, win->y+50, 0xFF00,win->plane) ;
- xyprint_plane(win->x+28,win->y+10+15,"ERASE",win->plane);
- events =(struct mouse_event*)kmalloc(sizeof(struct mouse_event));
- events->x1rel=0;
- events->y1rel=15;
- events->x2rel=100;
- events->y2rel=50;
- events->but=1;
- events->function=(void*)&draw_erase_function;
- list_add(&(events->list),&(win->events.list));
- }
- /* PONG */
- static int pong_bar_x;
- static struct str_buffer* buffer_kbd;
- static int ballx, bally,bincx,bincy;
- static int points;
- void pong_repetitive_function (struct Window* win ) {
- //print_composed_plane();
- paint_rectangle_plane (win->x+ballx,win->y+bally,win->x+ballx+10,win->y+bally+10,win->bkgcolor,win->plane);
- print_composed_plane_region(win->x+ballx,win->y+bally,win->x+ballx+10,win->y+bally+10);
- if (ballx>=win->sizex-10) bincx=-2;
- if (bally>=win->sizey-10) bincy=-2;
- if (ballx<=10) bincx=2;
- if (bally<=35) bincy=2;
- if (bally>=win->sizey-20-11 && ballx>=pong_bar_x-10&&ballx<=pong_bar_x+30){
- bincy=-1;
- }
- else {
- if (bally>=win->sizey-10) {
- bincy=-2;
- points--;
- char text[20];
- paint_rectangle_plane (win->x+20,win->y+25,win->x+100,win->y+35,win->bkgcolor,win->plane);
- snprintf (text,"%d",points);
- xyprint_plane(win->x+20,win->y+25,text,win->plane);
- print_composed_plane_region(win->x+20,win->y+25,win->x+100,win->y+35);
- }
-
- }
-
-
- bally=bally+bincy;
- ballx=ballx+bincx;
-
- paint_rectangle_plane (win->x+ballx,win->y+bally,win->x+ballx+10,win->y+bally+10,0x00,win->plane);
-
- print_composed_plane_region(win->x+ballx,win->y+bally,win->x+ballx+10,win->y+bally+10);
-
- if (points==0) delete_self_window(win);
- }
- void pong_key_function ( struct Window* win ) {
- keyboard->command(GET_KBD_BUFFER,buffer_kbd);
- paint_rectangle_plane(win->x,win->y+win->sizey-20,win->x+win->sizex,win->y+win->sizey-10,win->bkgcolor,win->plane);
- if ( buffer_kbd->buffer[0] == 'a' ) pong_bar_x=pong_bar_x-18;
- if ( buffer_kbd->buffer[0] == 's' ) pong_bar_x=pong_bar_x+18;
- if (pong_bar_x<0) pong_bar_x=0;
- if (pong_bar_x>win->sizex-30) pong_bar_x=win->sizex-30;
- paint_rectangle_plane(win->x+pong_bar_x,win->y+win->sizey-20,win->x+pong_bar_x+30,win->y+win->sizey-10,0x0000,win->plane);
- print_composed_plane_region(win->x,win->y+win->sizey-20,win->x+win->sizex,win->y+win->sizey-10);
- // kprint_plane (buffer_kbd->buffer,focus_win->plane);
- }
- void pong_init_function (struct Window* win) {
- struct mouse_event* events;
- char text[20];
- points=100;
- bincx=-3;
- bincy=3;
- ballx=40;
- bally=40;
-
- win->icon=pong_16bpp;
- win->iconx=314;
- win->icony=545;
- pong_bar_x=(win->sizex/2)-15;
- paint_rectangle_plane (win->x,win->y+15,win->x+win->sizex,win->y+win->sizey,win->bkgcolor,win->plane);
-
- buffer_kbd->buffer=(char*)kmalloc(sizeof(char)*100);
-
- win->userwrite=1;
- /* Event any key function */
- events =(struct mouse_event*)kmalloc(sizeof(struct mouse_event));
- events->x1rel=0;
- events->y1rel=0;
- events->x2rel=0;
- events->y2rel=0;
- events->kbd_event=1;
- events->but=0;
- events->function=(void*)&pong_key_function;
- list_add(&(events->list),&(win->events.list));
- /* Event repetitive function */
- events =(struct mouse_event*)kmalloc(sizeof(struct mouse_event));
- events->x1rel=0;
- events->y1rel=0;
- events->x2rel=0;
- events->y2rel=0;
- events->repetitive_event=600;
- events->but=0;
- events->function=(void*)&pong_repetitive_function;
- list_add(&(events->list),&(win->events.list));
- paint_rectangle_plane (win->x+20,win->y+25,win->x+100,win->y+35,win->bkgcolor,win->plane);
- snprintf (text,"%d",points);
- xyprint_plane(win->x+20,win->y+25,text,win->plane);
- print_composed_plane_region(win->x+20,win->y+25,win->x+100,win->y+35);
-
-
- }
- /* FI PONG */
- /**************/
- #include "small-gnu.c"
- #include "gnu-text.c"
- void gnu_init_function (struct Window* win) {
- char text[200];
- win->icon=gnu_16bpp;
- win->iconx=494;
- win->icony=545;
- snprintf (text,"nnnnnnnnn");
- kprint_plane(text,win->plane);
- snprintf (text,"This program is free software; you can redistribute it n");
- kprint_plane(text,win->plane);
- snprintf (text,"and/ or modify it under the terms of the GNU General n");
- kprint_plane(text,win->plane);
- snprintf (text,"Public License as published by the Free Software n");
- kprint_plane(text,win->plane);
- snprintf (text,"Foundation; either version 2 of the License, n");
- kprint_plane(text,win->plane);
- snprintf (text,"or (at your option) any later version. nn");
- kprint_plane(text,win->plane);
- snprintf (text,"This program is distributed in the hope that it nwill be useful, ");
- kprint_plane(text,win->plane);
- snprintf (text,"but WITHOUT ANY WARRANTY; nwithout even the implied warranty ");
- kprint_plane(text,win->plane);
- snprintf (text,"of MERCHANTABILITY nor FITNESS FOR A PARTICULAR PURPOSE.n");
- kprint_plane(text,win->plane);
- snprintf (text,"See the GNU General Public nLicense for more details. ");
- kprint_plane(text,win->plane);
- snprintf (text,"nnYou should have received a copy of the GNU Generaln");
- kprint_plane(text,win->plane);
- snprintf (text,"Public License along with this program;n");
- kprint_plane(text,win->plane);
- snprintf (text,"if not, write to the Free Software Foundation, Inc.,n");
- kprint_plane(text,win->plane);
- snprintf (text,"51 Franklin Street, Fifth Floor,n");
- kprint_plane(text,win->plane);
- snprintf (text,"Boston, MA 02110-1301, USAn");
- kprint_plane(text,win->plane);
-
- print_bmp_alpha_plane(win->x+20,win->y+25,small_gnu_16bpp,ALPHA_COLOR,win->plane);
- print_bmp_alpha_plane(win->x+100,win->y+25,gnu_text_16bpp,ALPHA_COLOR,win->plane);
- }
- void notepad_key_function ( struct Window* win ) {
- struct str_buffer* buffer_kbd;
- buffer_kbd->buffer=(char*)kmalloc(sizeof(char)*100);
- keyboard->command(GET_KBD_BUFFER,buffer_kbd);
- kprint_plane (buffer_kbd->buffer,focus_win->plane);
- }
- void notepad_init_function (struct Window* win) {
- struct mouse_event* events;
- win->userwrite=1;
- win->icon=write_16bpp;
- win->iconx=194;
- win->icony=545;
- /* Event any key function */
- events =(struct mouse_event*)kmalloc(sizeof(struct mouse_event));
- events->x1rel=0;
- events->y1rel=0;
- events->x2rel=0;
- events->y2rel=0;
- events->kbd_event=1;
- events->but=0;
- events->function=(void*)¬epad_key_function;
- list_add(&(events->list),&(win->events.list));
-
- }
- void about_init_function (struct Window* win) {
- win->icon=abouticon_16bpp;
- win->iconx=434;
- win->icony=545;
- }
- void memory_init_function (struct Window* win) {
- /* Event any key function */
- struct bus_driver* root_bus;
- struct bus_driver* p_bus;
- struct list_node_head* p_list;
- struct list_node_head* r_list;
- struct device* p_dev;
- struct device* a_dev;
- char text[200];
- win->icon=memory_16bpp;
- win->iconx=374;
- win->icony=545;
- /* List buses */
- kprint_plane (" System Devices nn",win->plane);
- kprint_plane (" -------------- nnn",win->plane);
- root_bus=ret_root_bus();
- snprintf(text,"Root bus: %sn",root_bus->name);
- kprint_plane(text,win->plane);
- p_dev=root_bus->dev_root;
- snprintf(text,"| |---vdev: %sn",p_dev->name);
- kprint_plane(text,win->plane);
- list_for_each(r_list,&(p_dev->dev_list)) {
- a_dev=list_entry(r_list, struct device, dev_list);
- if (a_dev!=0){
- snprintf(text,"| |---vdev: %sn",a_dev->name);
- kprint_plane(text,win->plane);
- }
- }
- list_for_each(p_list,&(root_bus->bus_list)) {
- p_bus=list_entry(p_list, struct bus_driver, bus_list);
- if (p_bus!=0) {
- snprintf(text,"|---bus: %sn",p_bus->name);
- kprint_plane(text,win->plane);
- p_dev=p_bus->dev_root;
- //if (!strcmp(p_bus->name,"ISA0")) {
- if (p_dev!=0) {
- snprintf(text,"| |---dev: %sn",p_dev->name);
- kprint_plane(text,win->plane);
-
- list_for_each(r_list,&(p_dev->dev_list)) {
- a_dev=list_entry(r_list, struct device, dev_list);
- if (a_dev!=0){
- snprintf(text,"| |---dev: %sn",a_dev->name);
- kprint_plane(text,win->plane);
- }
- }
- }
- }
- }
- kprint_plane(" n",win->plane);
- kprint_plane(" n",win->plane);
- kprint_plane(" n",win->plane);
- extern int avmem;
- kprint_plane (" Memory Info n n",win->plane);
- kprint_plane (" -------------- n n n",win->plane);
- snprintf (text,"Installed Ram: %d Mbn",avmem);
- kprint_plane (text,win->plane);
-
-
- }
- void move_self_window( struct Window* win) {
- set_self_focus( win) ;
- if (win->selfcopy==0) {
- win->selfcopy=(unsigned short*)kmalloc((win->sizex*win->sizey*SCREEN_BPP)+2);
- }
- copy_region_plane(win->selfcopy,win->x,win->y,win->x+win->sizex,win->y+win->sizey,win->plane);
- win->drag=1;
- }
-
- void copy_region_plane( unsigned short* area, int x1, int y1, int x2, int y2, int plane) {
- unsigned char* video=(unsigned char*)plane_list[plane];
- int col,fil;
- unsigned short pixel;
- int sizex;
- int sizey;
- (x1>x2)?(sizex=x1-x2):(sizex=x2-x1);
- (y1>y2)?(sizey=y1-y2):(sizey=y2-y1);
- for (fil=0;fil<((sizey+y1>SCREEN_HEIGHT)?(SCREEN_HEIGHT-y1):(sizey));fil++)
- for (col=0;col<sizex*SCREEN_BPP;col=col+SCREEN_BPP) {
- pixel=video[((y1+fil)*SCREEN_WIDTH*SCREEN_BPP)+col+(x1*SCREEN_BPP)]&0xFF;
- pixel=pixel|((video[((y1+fil)*SCREEN_WIDTH*SCREEN_BPP)+col+1+(x1*SCREEN_BPP)]<<8)&0xFF00);
- area[(sizey-fil-1)*sizex+(col/SCREEN_BPP)+2]=pixel;
-
- }
- area[0]=sizex;
- area[1]=sizey;
- }
- void set_self_focus( struct Window* win) {
-
- int act_plane=win->plane;
- struct Window* max_win=0;
- struct Window* temp_win;
- struct list_node_head *p;
-
- if (win!=0) {
- /* Buscar quina finestra te el pla == 1 */
- list_for_each (p,&(root_win.list)) {
- temp_win = (struct Window*)list_entry (p, struct Window, list);
- //if (temp_win!=0&&temp_win->plane>0&&temp_win->plane<max_win) {
- if (temp_win!=0&&temp_win->plane==1) {
- max_win=temp_win;
- act_plane=temp_win->plane;
- }
- }
- /*Switch planes*/
- /* char text[200];
- paint_rectangle_plane(0,500,800,550,0xFFFF,1);
- snprintf (text,"Win %d, Max %d, lastplane: %d, backplane: %d",win->plane,max_win->plane,last_plane,background_plane);
- xyprint_plane(0,500,text,1);
- print_composed_plane_region(0,500,800,600);*/
- if (win!=focus_win&&max_win!=0&&max_win->plane<last_plane) {
- act_plane=max_win->plane;
- unsigned long plane_add;
- plane_add=(unsigned long)plane_list[act_plane];
- plane_list[act_plane]=plane_list[win->plane];
- plane_list[win->plane]=(unsigned long*)plane_add;
- max_win->plane=win->plane;
- win->plane=act_plane;
- print_composed_plane_region(max_win->x,max_win->y,max_win->x+max_win->sizex,max_win->y+max_win->sizey);
- }
- focus_win=win;
- print_composed_plane_region(win->x,win->y,win->x+win->sizex,win->y+win->sizey);
- if (focus_win->text_win==1&&focus_win->userwrite==1) {
- keyboard->command(POLL_KBD_DEVICE,(void*)0);
- keyboard->command(DEL_KBD_BUFFER,(void*)0);
- }
-
- }
- }
- void delete_self_window( struct Window* win) {
-
- set_background_plane(ALPHA_COLOR,win->plane);
- win->created=0;
- if (win->icon!=0) print_bmp_alpha_plane(win->iconx,win->icony,win->icon,ALPHA_COLOR,background_plane-1);
- delete_plane (win->plane);
-
- struct Window* temp_win;
- struct list_node_head *p;
- list_for_each (p,&(root_win.list)) {
- temp_win = (struct Window*)list_entry (p, struct Window, list);
- if (temp_win!=0&&temp_win->created==1&&temp_win->plane==1) break;
- }
- if (temp_win->plane==1) focus_win=temp_win;
- else focus_win=0;
-
- // focus_win=0;
- /* Delete the window from the list */
- list_del(&win->list);
-
-
- print_composed_plane();
- }
- void create_window (char* id, int x, int y, int sizex, int sizey, int bkgcolor, int plane, void (*start_function) (struct Window* win) ) {
- //char text[200];
- struct Window* newwin;
- struct mouse_event* events;
- struct Window* temp_win;
- struct list_node_head *p;
- int new=0;
-
- /* Check if the window exists */
- list_for_each (p,&(root_win.list)) {
- temp_win = (struct Window*)list_entry (p, struct Window, list);
- if (temp_win!=0&&temp_win->id!=0&&!(strncmp(temp_win->id,id,7))){
- /* Window already exists */
-
- /* set_background_plane(ALPHA_COLOR,0);
- snprintf (text,"CACA: %s == %s",temp_win->id,id);
- xyprint_plane(0,10,text,0);
- print_composed_plane();*/
- new=1;
- break ;
- }
- else temp_win=0;
- //if (temp_win!=0&&temp_win->id!=0);// break ;
- //snprintf (text,"CACA: %c == %s",(temp_win!=0)?(temp_win->id[0]):("NO"),id);
- }
-
-
-
- /* Window is not in the list, we can create it */
- if (new==0) {
- insert_plane(plane);
-
- newwin =(struct Window*)kmalloc(sizeof(struct Window));
- newwin->id=(char*)kmalloc(sizeof(char)*strlen(id)+1);
- strcpy (newwin->id,id);
- newwin->created=1;
- newwin->x=x;
- newwin->y=y;
- newwin->drag=0;
- newwin->sizex=sizex;
- newwin->sizey=sizey;
- newwin->plane=plane;
- newwin->cursorx=20;
- newwin->initialx=20;
- newwin->finalx=sizex-20;
- newwin->cursory=20;
- newwin->selfcopy=0;
- newwin->bkgcolor=bkgcolor;
- paint_trans_rectangle_plane (x,y,x+sizex,y+sizey,bkgcolor,plane);
- paint_rectangle_plane (x,y,x+sizex,y+15, 0x020F,plane);
- paint_rectangle_plane (x+sizex-15,y,x+sizex,y+15, 0xFC00,plane);
- xyprint_plane(x+(sizex/2)-(strlen(id)*FONT_W)/2,y+5,newwin->id,plane);
- list_add(&(newwin->list),&(root_win.list));
-
- INIT_LIST_HEAD(&(newwin->events.list));
- /* Event Close Window*/
- events =(struct mouse_event*)kmalloc(sizeof(struct mouse_event));
- events->x1rel=newwin->sizex-15;
- events->y1rel=0;
- events->x2rel=newwin->sizex;
- events->y2rel=15;
- events->kbd_event=0;
- events->but=2;
- events->function=(void*)&delete_self_window;
- list_add(&(events->list),&(newwin->events.list));
-
- /* Event SetFocus Window*/
- events =(struct mouse_event*)kmalloc(sizeof(struct mouse_event));
- events->x1rel=0;
- events->y1rel=0;
- events->x2rel=newwin->sizex;
- events->y2rel=15;
- events->but=2;
- events->kbd_event=0;
- events->function=(void*)&set_self_focus;
- list_add(&(events->list),&(newwin->events.list));
-
- /* Event Move Window*/
- events =(struct mouse_event*)kmalloc(sizeof(struct mouse_event));
- events->x1rel=0;
- events->y1rel=0;
- events->x2rel=newwin->sizex;
- events->y2rel=15;
- events->but=1;
- events->kbd_event=0;
- events->function=(void*)&move_self_window;
- list_add(&(events->list),&(newwin->events.list));
-
- newwin->text_win=1;
- newwin->userwrite=0;
- //set_self_focus( newwin) ;
- focus_win=newwin;
-
- if (start_function!=0) {
- start_function(newwin);
- }
- //set_self_focus (newwin);
- print_composed_plane ();
- }
- }
- static int counter_event;
- void mouse_event (int x, int y, int but) {
- intoff();
- struct list_node_head *p;
- struct Window* win;
- struct mouse_event* event;
-
- //char text[200];
- counter_event++;
- /* Keyboard event */
- if (x==-1&&y==-1) {
- win=focus_win;
- list_for_each (p,&(win->events.list)) {
- event = (struct mouse_event*)list_entry (p, struct mouse_event, list);
- if ( event->kbd_event==1 ) {
- event->function(win);
- }
- }
- }
-
- /* Repetitive event */
- if (focus_win!=0&&but==0&&focus_win->drag==0) {
- win=focus_win;
- list_for_each (p,&(win->events.list)) {
- event = (struct mouse_event*)list_entry (p, struct mouse_event, list);
- if ( event->repetitive_event!=0 && counter_event%event->repetitive_event==0 ) {
- event->function(win);
- }
- }
- }
-
- if (x!=-1&& y!=-1 && but!= 0) {
- int plane_id=plane_from_pixel(x,y);
- if (focus_win==0||(focus_win!=0&&focus_win->drag==0)) {
- list_for_each (p,&(root_win.list)) {
- win = (struct Window*)list_entry (p, struct Window, list);
- if (win->plane==plane_id) break;
- }
-
- if (win->plane==plane_id) {
- list_for_each (p,&(win->events.list)) {
- event = (struct mouse_event*)list_entry (p, struct mouse_event, list);
- if ( (but == event->but)&& (x > (event->x1rel+win->x)) && (x < (event->x2rel+win->x)) &&
- (y > (event->y1rel+win->y)) && (y < (event->y2rel+win->y)) ) {
- win->mousex=x;
- win->mousey=y;
- event->function(win);
- }
- }
- }
- }
- if (but==2&&focus_win!=0&&focus_win->drag==1) {
- set_background_plane(ALPHA_COLOR,MOUSE_PLANE);
- set_background_plane(ALPHA_COLOR,focus_win->plane);
- focus_win->x=x;
- focus_win->y=y;
- focus_win->drag=0;
- print_bmp_alpha_plane(x,y,focus_win->selfcopy,ALPHA_COLOR,focus_win->plane);
- print_composed_plane();
-
- }
- if (x>194&&x<194+48&&y>545&&y<593) {
- circle_fill_plane_alpha(194+24,545+24,21,0xfeca,background_plane-1,0.6);
- print_composed_plane_region(175,540,625,600);
- create_window("notepad",500,100,300,300,0x0ff0,1,(void*)¬epad_init_function);
- }
- if (x>374&&x<374+48&&y>545&&y<593) {
- circle_fill_plane_alpha(374+24,545+24,21,0xfeca,background_plane-1,0.6);
- print_composed_plane_region(175,540,625,600);
- create_window("system info",100,100,300,300,0xFC00,1,(void*)&memory_init_function);
- }
- if (x>434&&x<434+48&&y>545&&y<593) {
- circle_fill_plane_alpha(434+24,545+24,21,0xfeca,background_plane-1,0.6);
- print_composed_plane_region(175,540,625,600);
- create_window("about",300,200,200,350,0xcc0f,1,(void*)&about_init_function);
- print_composed_plane();
- }
- if (x>254&&x<254+48&&y>545&&y<593) {
- circle_fill_plane_alpha(254+24,545+24,21,0xfeca,background_plane-1,0.6);
- print_composed_plane_region(175,540,625,600);
- create_window("draw",150,50,400,200,0x1c1f,1,(void*)&draw_init_function);
- }
- if (x>314&&x<314+48&&y>545&&y<593) {
- circle_fill_plane_alpha(314+24,545+24,21,0xfeca,background_plane-1,0.6);
- print_composed_plane_region(175,540,625,600);
- create_window("pong",500,100,200,400,0xac1a,1,(void*)&pong_init_function);
- }
- if (x>494&&x<494+48&&y>545&&y<593) {
- circle_fill_plane_alpha(494+24,545+24,21,0xfeca,background_plane-1,0.6);
- print_composed_plane_region(175,540,625,600);
- create_window("gnu",200,300,500,250,0x7f77,1,(void*)&gnu_init_function);
- }
- if (x>554&&x<554+48&&y>545&&y<593) {
- halt_computer();
- }
-
- }
- }
- #include "bye.c"
- void fade_plane(float factor, int plane_id) {
-
- int col,fil;
- unsigned short* video;
- if (plane_id==-1) video=(unsigned short*)0xD0800000;
- else video=(unsigned short*)plane_list[plane_id];
- unsigned short pixel;
- int r,g,b;
- for (fil=0;fil<SCREEN_HEIGHT;fil++)
- for (col=0;col<SCREEN_WIDTH;col=col+1) {
- pixel=video[fil*SCREEN_WIDTH+col+0];
- r=(pixel>>11)&0x1F;
- g=(pixel>>6)&0x1F;
- b=pixel&0x1F;
-
- r=r*factor;
- g=g*factor;
- b=b*factor;
-
- pixel=(r<<11)|(g<<6)|b;
- video[fil*SCREEN_WIDTH+col+0]=pixel;
- }
-
- }
- void halt_computer() {
- intoff();
- set_background_plane(0x0000,0);
- print_bmp_plane(250,200,bye_16bpp,ALPHA_COLOR,0);
- print_composed_plane();
- while (1>0){
- fade_plane(0.9998,0);
- print_composed_plane_region(250,200,550,400);
- }
- }
- /* Returns which plane the pixel belogns */
- int plane_from_pixel (int x, int y) {
- unsigned long pixel;
- unsigned short* plane;
- int act_plane=1;
-
- plane=(unsigned short*)plane_list[act_plane];
- pixel=(plane[y*SCREEN_WIDTH+x]);
- act_plane++;
- while (act_plane<=last_plane&&pixel==ALPHA_COLOR) {
- plane=(unsigned short*)plane_list[act_plane];
- if (plane!=0){
- pixel=(plane[y*SCREEN_WIDTH+x]);
- }
- act_plane++;
- }
-
- if (pixel != ALPHA_COLOR) return act_plane-1;
- if (pixel == ALPHA_COLOR) return -1;
- return 0;
- }
- void init_planes () {
- int i=0;
- for (i=0;i<MAX_PLANES;i++) {
- plane_list[i]=0;
- }
- last_plane=0;
- create_plane(0);
- create_plane(1);
- create_plane(2);
- background_plane=2;
- }
- void delete_plane (int id) {
- unsigned long* plane_list_temp[MAX_PLANES];
- int i,j;
- struct list_node_head *p;
- struct Window* win;
- /* Separar tots els plans a partir de id */
-
- if (id<last_plane) {
- // kfree(plane_list[id]);
- j=0;
- for (i=id+1;i<=last_plane;i++) {
- plane_list_temp[j]=plane_list[i];
- j++;
- }
- j=0;
- for (i=id;i<last_plane;i++) {
- plane_list[i]=plane_list_temp[j];
- j++;
- }
- list_for_each (p,&(root_win.list)) {
- win = (struct Window*)list_entry (p, struct Window, list);
- if (win!=0&&win->plane>=id) {
- win->plane=win->plane-1;
- }
- }
- /* Incrementar last_plane, background_plane, ... */
- last_plane--;
- background_plane--;
- }
- }
- void insert_plane ( int id ) {
- unsigned long* plane_list_temp[MAX_PLANES];
- int i,j;
- struct list_node_head *p;
- struct Window* win;
- /* Separar tots els plans a partir de id */
- if (id<last_plane) {
- j=0;
- for (i=id;i<=last_plane;i++) {
- plane_list_temp[j]=plane_list[i];
- j++;
- }
- j=0;
- for (i=id+1;i<=last_plane+1;i++) {
- plane_list[i]=plane_list_temp[j];
- j++;
- }
-
- plane_list[id]=0;
- /* Inicialitzar el pla */
- create_plane(id);
- /* Canviar tots els plane de les finestres */
- list_for_each (p,&(root_win.list)) {
- win = (struct Window*)list_entry (p, struct Window, list);
- if (win->plane>=id) {
- win->plane=win->plane+1;
- }
- }
-
-
-
- /* Incrementar last_plane, background_plane, ... */
- last_plane++;
- background_plane++;
- }
- //print_composed_plane ();
- }
-
- void create_plane ( int id ) {
- int x,y;
- unsigned short* plane;
- plane=(unsigned short*)kmalloc(sizeof (unsigned char)*SCREEN_WIDTH*SCREEN_HEIGHT*SCREEN_BPP);
- if (id<MAX_PLANES) {
- plane_list[id]=(unsigned long*)plane;
- if (id>last_plane) last_plane=id;
- for (y=0;y<SCREEN_HEIGHT;y++)
- for (x=0;x<SCREEN_WIDTH;x++)
- plane[y*SCREEN_WIDTH+x]=ALPHA_COLOR;
- }
- }
- void print_composed_plane_region (int x1, int y1, int x2, int y2) {
- unsigned char* video=(unsigned char*)0xD0800000;
- int col,fil;
- unsigned long pixel;
- unsigned short* plane;
- int act_plane=0;
- int sizex;
- int sizey;
- (x1>x2)?(sizex=x1-x2):(sizex=x2-x1);
- (y1>y2)?(sizey=y1-y2):(sizey=y2-y1);
-
-
- plane=(unsigned short*)plane_list[act_plane];
- for (fil=0;fil<((sizey+y1>SCREEN_HEIGHT)?(SCREEN_HEIGHT-y1):(sizey));fil++) {
- for (col=0;col<sizex*SCREEN_BPP;col=col+SCREEN_BPP) {
- pixel=(plane[(y1+fil)*SCREEN_WIDTH+x1+col/SCREEN_BPP]);
- act_plane++;
- while (act_plane<=last_plane&&pixel==ALPHA_COLOR) {
- plane=(unsigned short*)plane_list[act_plane];
- if (plane!=0){
- pixel=(plane[(y1+fil)*SCREEN_WIDTH+x1+col/SCREEN_BPP]);
- }
- else{
- pixel=ALPHA_COLOR;
- }
- act_plane++;
- }
- act_plane=0;
- plane=(unsigned short*)plane_list[act_plane];
- if (pixel!=ALPHA_COLOR) {
- video[((y1+fil)*SCREEN_WIDTH*SCREEN_BPP)+col+x1*2]=pixel&0xFF;
- video[((y1+fil)*SCREEN_WIDTH*SCREEN_BPP)+col+1+x1*2]=(pixel>>8)&0xFF;
- }
- }
- }
-
- }
- void print_composed_plane () {
- unsigned char* video=(unsigned char*)0xD0800000;
- int col,fil;
- unsigned long pixel;
- unsigned short* plane;
- int act_plane=0;
- plane=(unsigned short*)plane_list[act_plane];
- for (fil=0;fil<SCREEN_HEIGHT;fil++) {
- for (col=0;col<SCREEN_WIDTH*SCREEN_BPP;col=col+SCREEN_BPP) {
- pixel=(plane[(fil*SCREEN_WIDTH)+col/SCREEN_BPP]);
- act_plane++;
- while (act_plane<=last_plane&&pixel==ALPHA_COLOR) {
- plane=(unsigned short*)plane_list[act_plane];
- if (plane!=0){
- pixel=(plane[(fil*SCREEN_WIDTH)+col/SCREEN_BPP]);
- }
- else{
- pixel=ALPHA_COLOR;
- }
- act_plane++;
- }
- act_plane=0;
- plane=(unsigned short*)plane_list[act_plane];
- if (pixel!=ALPHA_COLOR) {
- video[((fil)*SCREEN_WIDTH*SCREEN_BPP)+col]=pixel&0xFF;
- video[((fil)*SCREEN_WIDTH*SCREEN_BPP)+col+1]=(pixel>>8)&0xFF;
- }
- }
- }
-
- }
- void print_mouse_plane (int x, int y,int plane) {
- print_bmp_alpha_plane (x,y,pointer_16bpp,0xffdf,plane);
- }
- void print_bmp_alpha_plane (int x, int y, unsigned short* data,unsigned short alpha,int plane) {
- unsigned char* video=(unsigned char*)plane_list[plane];
- int col,fil;
- unsigned long pixel;
- int sizex=data[0];
- int sizey=data[1];
- //if (y+sizey>SCREEN_HEIGHT) sizey=(y+sizey)-SCREEN_HEIGHT;
- for (fil=0;fil<((sizey+y>SCREEN_HEIGHT)?(SCREEN_HEIGHT-y):(sizey));fil++)
- for (col=0;col<sizex*SCREEN_BPP;col=col+SCREEN_BPP) {
- pixel=(data[((sizey-fil-1)*sizex)+(col/SCREEN_BPP)+2]);
- if (pixel != alpha) {
- video[((y+fil)*SCREEN_WIDTH*SCREEN_BPP)+col+1+(x*SCREEN_BPP)]=(pixel&0xFF00)>>8;
- video[((y+fil)*SCREEN_WIDTH*SCREEN_BPP)+col+0+(x*SCREEN_BPP)]=pixel&0x00FF;
- }
-
- }
- }
- void print_bmp_plane (int x, int y, unsigned short* data,unsigned short alpha,int plane) {
- unsigned char* video=(unsigned char*)plane_list[plane];
- int col,fil;
- unsigned long pixel;
- int sizex=data[0];
- int sizey=data[1];
- //if (y+sizey>SCREEN_HEIGHT) sizey=(y+sizey)-SCREEN_HEIGHT;
- for (fil=0;fil<((sizey+y>SCREEN_HEIGHT)?(SCREEN_HEIGHT-y):(sizey));fil++)
- for (col=0;col<sizex*SCREEN_BPP;col=col+SCREEN_BPP) {
- pixel=(data[((sizey-fil-1)*sizex)+(col/SCREEN_BPP)+2]);
- if (pixel != alpha) {
- video[((y+fil)*SCREEN_WIDTH*SCREEN_BPP)+col+1+(x*SCREEN_BPP)]=(pixel&0xFF00)>>8;
- video[((y+fil)*SCREEN_WIDTH*SCREEN_BPP)+col+0+(x*SCREEN_BPP)]=pixel&0x00FF;
- }
- else {
- video[((y+fil)*SCREEN_WIDTH*SCREEN_BPP)+col+1+(x*SCREEN_BPP)]=0xFF;
- video[((y+fil)*SCREEN_WIDTH*SCREEN_BPP)+col+0+(x*SCREEN_BPP)]=0xFF;
- }
-
- }
- }
- void set_background_plane (unsigned short color, int plane_id) {
- int col,fil;
- unsigned char* video=(unsigned char*)plane_list[plane_id];
- for (fil=0;fil<SCREEN_HEIGHT;fil++)
- for (col=0;col<SCREEN_WIDTH*2;col=col+2) {
- //video[fil*SCREEN_WIDTH+col]=(unsigned long) (color | color<<16);
- video[fil*SCREEN_WIDTH*2+col+1]=(unsigned long) ( color>>8)&0xFF;
- video[fil*SCREEN_WIDTH*2+col]=(unsigned long) (color)&0xFF;
- }
-
- }
- void paint_trans_rectangle_plane (int x1, int y1, int x2, int y2, unsigned short color,int plane) {
- unsigned char* video=(unsigned char*)plane_list[plane];
- int col,fil;
- int sizex;
- int sizey;
- unsigned short set_color=color;
- (x1>x2)?(sizex=x1-x2):(sizex=x2-x1);
- (y1>y2)?(sizey=y1-y2):(sizey=y2-y1);
- for (fil=0;fil<((sizey+y1>SCREEN_HEIGHT)?(SCREEN_HEIGHT-y1):(sizey));fil++)
- for (col=0;col<sizex*SCREEN_BPP;col=col+SCREEN_BPP) {
- if ((fil+col)%5==0) color=ALPHA_COLOR;
- else color=set_color;
- video[((y1+fil)*SCREEN_WIDTH*SCREEN_BPP)+col+1+(x1*SCREEN_BPP)]=(color&0xFF00)>>8;
- video[((y1+fil)*SCREEN_WIDTH*SCREEN_BPP)+col+0+(x1*SCREEN_BPP)]=color&0x00FF;
-
- }
- /*paint_rectangle_plane (x1,y1,x2,y1+15, 0x020F,plane);
- paint_rectangle_plane (x2-15,y1,x2,y1+15, 0xFC00,plane);*/
- }
- void paint_rectangle_plane (int x1, int y1, int x2, int y2, unsigned short color,int plane) {
- unsigned char* video=(unsigned char*)plane_list[plane];
- int col,fil;
- int sizex;
- int sizey;
- (x1>x2)?(sizex=x1-x2):(sizex=x2-x1);
- (y1>y2)?(sizey=y1-y2):(sizey=y2-y1);
- for (fil=0;fil<((sizey+y1>SCREEN_HEIGHT)?(SCREEN_HEIGHT-y1):(sizey));fil++)
- for (col=0;col<sizex*SCREEN_BPP;col=col+SCREEN_BPP) {
- video[((y1+fil)*SCREEN_WIDTH*SCREEN_BPP)+col+1+(x1*SCREEN_BPP)]=(color&0xFF00)>>8;
- video[((y1+fil)*SCREEN_WIDTH*SCREEN_BPP)+col+0+(x1*SCREEN_BPP)]=color&0x00FF;
- }
- }
- void start_presentacio() {
- struct Ps2Mouse* mousectx;
- struct str_buffer* buffer_kbd;
- mouse =((struct bus_driver*)ret_root_bus())->find_dev_in_bus(ISA0_STR,ISA_MOUSE_STR,(struct device*)((struct bus_driver*)ret_root_bus())->dev_root);
- rtc =((struct bus_driver*)ret_root_bus())->find_dev_in_bus(ISA0_STR,ISA_RTC_STR,(struct device*)((struct bus_driver*)ret_root_bus())->dev_root);
- keyboard =((struct bus_driver*)ret_root_bus())->find_dev_in_bus(ISA0_STR,ISA_PSKBD_STR,(struct device*)((struct bus_driver*)ret_root_bus())->dev_root);
- /* Proves amb create plane */
-
-
- init_planes ();
-
-
- mousectx=(struct Ps2Mouse*)kmalloc(sizeof(struct Ps2Mouse));
- mousectx->x=0;
- mousectx->y=0;
-
- rtc_time_of_day* rtc_clock=(rtc_time_of_day*)kmalloc(sizeof(rtc_time_of_day));
-
- buffer_kbd=(struct str_buffer*)kmalloc(sizeof(struct str_buffer));
- buffer_kbd->buffer=(char*)kmalloc(sizeof(char)*100);
- buffer_kbd->size=0;
- buffer_kbd->buffer[0]=0;
- set_background_plane(0xfffc,background_plane);
- print_bmp_alpha_plane (0,0,header_16bpp,0xffdf,background_plane-1);
- //print_bmp_alpha_plane (0,0,header_16bpp,0xffdf,0);
-
- int oldx,oldy,oldbut;
-
- int oldsec;
- int counter=0;
- oldx=300;
- oldy=300;
- oldbut=0;
- // print_composed_plane ();
-
- // Write Draw Pong Memory About GNU halt
- print_bmp_alpha_plane(175,540,dock_16bpp,0xffdf,background_plane-1);
- print_bmp_alpha_plane(194,545,write_16bpp,0xffdf,background_plane-1);
- print_bmp_alpha_plane(254,545,draw_16bpp,0xffdf,background_plane-1);
- print_bmp_alpha_plane(314,545,pong_16bpp,0xffdf,background_plane-1);
- print_bmp_alpha_plane(374,545,memory_16bpp,0xffdf,background_plane-1);
- print_bmp_alpha_plane(434,545,abouticon_16bpp,0xffdf,background_plane-1);
- print_bmp_alpha_plane(494,545,gnu_16bpp,0xffdf,background_plane-1);
- print_bmp_alpha_plane(554,545,halt_16bpp,0xffdf,background_plane-1);
-
- init_windows();
- // create_window("notepad",200,200,300,200,0x0ff0,2);
- // create_window("caca",200,50,300,400,0x00f0,3);
-
- print_composed_plane ();
- while (1>0) {
- intoff();
- keyboard->command(POLL_KBD_DEVICE,(void*)0);
- if (focus_win!=0&&focus_win->text_win==1&&focus_win->userwrite==1) {
- int pos;
- keyboard->command(ISEMPTY_KBD_BUFFER,&pos);
- if (pos==1) mouse_event(-1,-1,-1);
- // kprint_plane (buffer_kbd->buffer,focus_win->plane);
- }
- mouse->command(GET_MOUSE_COORDINATES,mousectx);
- if (counter%20000==0)rtc->command(GET_TIME,rtc_clock);
- if ((counter%20000==0)&&(rtc_clock->hour.sec!=oldsec)) {
- paint_rectangle_plane(0,100,800,230,ALPHA_COLOR,background_plane-1);
- print_bcd_bmp_plane(0,100,rtc_clock->hour.hour,2,background_plane-1);
- print_bmp_alpha_plane (200,100,dots_16bpp,ALPHA_COLOR,background_plane-1);
- print_bcd_bmp_plane(300,100,rtc_clock->hour.min,2,background_plane-1);
- print_bmp_alpha_plane (500,100,dots_16bpp,ALPHA_COLOR,background_plane-1);
- print_bcd_bmp_plane(600,100,rtc_clock->hour.sec,2,background_plane-1);
- oldsec=rtc_clock->hour.sec;
- print_composed_plane_region (0,100,800,230);
- }
-
-
- mouse_event (mousectx->x,mousectx->y,mousectx->buttons);
-
-
- if ((mousectx->x!=oldx)||(mousectx->y!=oldy)) {
-
- if (focus_win==0|| (focus_win!=0&&focus_win->drag==0)) {
- paint_rectangle_plane(oldx,oldy,oldx+30,(oldy+30>=SCREEN_HEIGHT)?(SCREEN_HEIGHT):(oldy+30),ALPHA_COLOR,MOUSE_PLANE);
- print_mouse_plane (mousectx->x,mousectx->y,MOUSE_PLANE);
- print_composed_plane_region (oldx,oldy,oldx+30,(oldy+30>=SCREEN_HEIGHT)?(SCREEN_HEIGHT):(oldy+30));
- oldx=mousectx->x;
- oldy=mousectx->y;
- print_composed_plane_region (oldx,oldy,oldx+30,(oldy+30>=SCREEN_HEIGHT)?(SCREEN_HEIGHT):(oldy+30));
- }
- if ((counter%700==0)&&(focus_win!=0&&focus_win->drag==1)) {
- paint_rectangle_plane(oldx,oldy,oldx+focus_win->sizex+20,oldy+focus_win->sizey+20,ALPHA_COLOR,MOUSE_PLANE);
- print_bmp_alpha_plane(mousectx->x,mousectx->y,focus_win->selfcopy,ALPHA_COLOR,MOUSE_PLANE);
- print_composed_plane_region (oldx,oldy,oldx+focus_win->sizex+20,oldy+focus_win->sizey+20);
- print_shade_plane(mousectx->x+focus_win->sizex,mousectx->y,mousectx->x+focus_win->sizex+20,mousectx->y+focus_win->sizey,LR_SHADE,MOUSE_PLANE);
- print_shade_plane(mousectx->x,mousectx->y+focus_win->sizey,mousectx->x+focus_win->sizex,mousectx->y+focus_win->sizey+20,TD_SHADE,MOUSE_PLANE);
- oldx=mousectx->x;
- oldy=mousectx->y;
- // print_composed_plane_region (oldx,oldy,oldx+focus_win->sizex,oldy+focus_win->sizey);
- print_composed_plane_region (oldx,oldy,oldx+focus_win->sizex+20,oldy+focus_win->sizey+20);
- //print_composed_plane();
-
- }
- }
- //circle_fill_plane(400,300,200, 0xfeca,2) ;
- //circle_fast_plane(400,300,300, 0x0000,2) ;
- counter++;
- inton();
- int c;
- for (c=0;c<800;c++) ;
- }
- }
- void kprint_plane( char * str , int plane) {
- int i=0;
- while (str[i]!=' ' && ((i*FONT_W)+focus_win->cursorx) < focus_win->finalx ) {
- switch (str[i]) {
- case 'n':
- str[i]=' ';
- xyprint_plane(focus_win->x+focus_win->cursorx,focus_win->y+focus_win->cursory,str,plane);
- print_composed_plane_region (focus_win->x+focus_win->cursorx,focus_win->y+focus_win->cursory,focus_win->x+focus_win->cursorx+(strlen(str)*FONT_W),focus_win->y+focus_win->cursory+FONT_H);
- focus_win->cursorx=focus_win->initialx;
- focus_win->cursory=focus_win->cursory+FONT_H;
- str=str+i+1 ;
- i=-1;
- break;
- }
- i++;
- if (i*FONT_W+focus_win->cursorx >= focus_win->finalx ) {
- str[i]=' ';
- xyprint_plane(focus_win->x+focus_win->cursorx,focus_win->y+focus_win->cursory,str,plane);
- print_composed_plane_region (focus_win->x+focus_win->cursorx,focus_win->y+focus_win->cursory,focus_win->x+focus_win->cursorx+(strlen(str)*FONT_W),focus_win->y+focus_win->cursory+FONT_H);
- focus_win->cursorx=focus_win->initialx;
- focus_win->cursory=focus_win->cursory+FONT_H;
- str=str+i+1 ;
- i=0;
- }
- }
- xyprint_plane(focus_win->x+focus_win->cursorx,focus_win->y+focus_win->cursory,str,plane);
- print_composed_plane_region (focus_win->x+focus_win->cursorx,focus_win->y+focus_win->cursory,focus_win->x+focus_win->cursorx+(strlen(str)*FONT_W),focus_win->y+focus_win->cursory+FONT_H);
- focus_win->cursorx=focus_win->cursorx+strlen(str)*FONT_W;
- }
- void xyprint_plane ( int x, int y, char* string, int plane) {
- xyprint_area (string, x,y,0x0000,5,(word*)plane_list[plane]);
- }
- static unsigned short* bmp_numbers[] = { zero_16bpp, one_16bpp, two_16bpp, three_16bpp, four_16bpp, five_16bpp, six_16bpp, seven_16bpp, eight_16bpp, nine_16bpp };
- void print_bcd_bmp_plane (int x, int y, int number, int digits,int plane) {
-
- int i;
- int k;
- for (i=digits-1;i>0;i--) {
- k=number/pow(10,i);
- print_bmp_alpha_plane (x+((digits-1-i)*100),y,bmp_numbers[k],ALPHA_COLOR,plane);
- }
- k=number%10;
- print_bmp_alpha_plane (x+((digits-i-1)*100),y,bmp_numbers[k],ALPHA_COLOR,plane);
-
- }
- //x^y
- int pow ( int x, int y) {
- int i;
- if (y==1) return x;
- if (y==0) return 1;
- i=x*pow(x,y-1);
-
- return i;
- }
- #include "sin_acos_table.c"
- void circle_fill_plane(int x,int y, int radius, unsigned short color,int plane) {
- unsigned short* VIDEO=(unsigned short*)0xD0800000;
- if (plane>-1) VIDEO=(unsigned short*)plane_list[plane];
- unsigned long n=0,invradius=(1/(float)radius)*0x10000L;
- int dx=0,dy=radius-1,i;
- while (dx<=dy) {
- for(i=dy;i>=dx;i--) {
- VIDEO[((y+dy+(i-dy))*SCREEN_WIDTH)+x+dx] = color; /* octant 0 */
- VIDEO[((y+dy+(i-dy))*SCREEN_WIDTH)+x-dx] = color; /* octant 0 */
- VIDEO[((y-dy-(i-dy))*SCREEN_WIDTH)+x-dx] = color; /* octant 0 */
- VIDEO[((y-dy-(i-dy))*SCREEN_WIDTH)+x+dx] = color; /* octant 0 */
- VIDEO[((y-dx)*SCREEN_WIDTH)+x+dy+(i-dy)] = color; /* octant 0 */
- VIDEO[((y+dx)*SCREEN_WIDTH)+x+dy+(i-dy)] = color; /* octant 0 */
- VIDEO[((y+dx)*SCREEN_WIDTH)+x-dy-(i-dy)] = color; /* octant 0 */
- VIDEO[((y-dx)*SCREEN_WIDTH)+x-dy-(i-dy)] = color; /* octant 0 */
- }
- dx++;
- n+=invradius;
- dy = (int)((radius * SIN_ACOS[(int)(n>>6)]) >> 16);
- }
- }
- void circle_fill_plane_alpha(int x,int y, int radius, unsigned short color,int plane, float factor){
- unsigned short* VIDEO=(unsigned short*)0xD0800000;
- if (plane>-1) VIDEO=(unsigned short*)plane_list[plane];
- unsigned long n=0,invradius=(1/(float)radius)*0x10000L;
- int dx=0,dy=radius-1,i;
- unsigned short orig_color;
- int O_r,O_g,O_b;
- int N_r,N_g,N_b;
- unsigned short new_color;
- O_r=(color>>11)&0x1F;
- O_g=(color>>6)&0x1F;
- O_b=color&0x1F;
- O_r=O_r*(1-factor);
- O_g=O_g*(1-factor);
- O_b=O_b*(1-factor);
- while (dx<=dy) {
- for(i=dy;i>=dx;i--) {
-
-
- orig_color=VIDEO[((y+dy+(i-dy))*SCREEN_WIDTH)+x+dx];
- N_r=(orig_color>>11)&0x1F;
- N_g=(orig_color>>6)&0x1F;
- N_b=orig_color&0x1F;
- N_r=N_r*factor+O_r;
- N_g=N_g*factor+O_g;
- N_b=N_b*factor+O_b;
- new_color=(N_r<<11)|(N_g<<6)|N_b;
- if (dx!=0&&dx!=i)
- VIDEO[((y+dy+(i-dy))*SCREEN_WIDTH)+x+dx] = new_color; /* octant 0 */
-
-
- orig_color= VIDEO[((y+dy+(i-dy))*SCREEN_WIDTH)+x-dx];
- N_r=(orig_color>>11)&0x1F;
- N_g=(orig_color>>6)&0x1F;
- N_b=orig_color&0x1F;
- N_r=N_r*factor+O_r;
- N_g=N_g*factor+O_g;
- N_b=N_b*factor+O_b;
- new_color=(N_r<<11)|(N_g<<6)|N_b;
- VIDEO[((y+dy+(i-dy))*SCREEN_WIDTH)+x-dx] = new_color; /* octant 0 */
- orig_color=VIDEO[((y-dy-(i-dy))*SCREEN_WIDTH)+x-dx];
- N_r=(orig_color>>11)&0x1F;
- N_g=(orig_color>>6)&0x1F;
- N_b=orig_color&0x1F;
- N_r=N_r*factor+O_r;
- N_g=N_g*factor+O_g;
- N_b=N_b*factor+O_b;
- new_color=(N_r<<11)|(N_g<<6)|N_b;
- if (dx!=0)
- VIDEO[((y-dy-(i-dy))*SCREEN_WIDTH)+x-dx] = new_color; /* octant 0 */
-
- orig_color=VIDEO[((y-dy-(i-dy))*SCREEN_WIDTH)+x+dx];
- N_r=(orig_color>>11)&0x1F;
- N_g=(orig_color>>6)&0x1F;
- N_b=orig_color&0x1F;
- N_r=N_r*factor+O_r;
- N_g=N_g*factor+O_g;
- N_b=N_b*factor+O_b;
- new_color=(N_r<<11)|(N_g<<6)|N_b;
- VIDEO[((y-dy-(i-dy))*SCREEN_WIDTH)+x+dx] = new_color; /* octant 0 */
- orig_color= VIDEO[((y-dx)*SCREEN_WIDTH)+x+dy+(i-dy)];
- N_r=(orig_color>>11)&0x1F;
- N_g=(orig_color>>6)&0x1F;
- N_b=orig_color&0x1F;
- N_r=N_r*factor+O_r;
- N_g=N_g*factor+O_g;
- N_b=N_b*factor+O_b;
- new_color=(N_r<<11)|(N_g<<6)|N_b;
- if (dx!=0&&dx!=i)
- VIDEO[((y-dx)*SCREEN_WIDTH)+x+dy+(i-dy)] = new_color; /* octant 0 */
-
- orig_color=VIDEO[((y+dx)*SCREEN_WIDTH)+x+dy+(i-dy)];
- N_r=(orig_color>>11)&0x1F;
- N_g=(orig_color>>6)&0x1F;
- N_b=orig_color&0x1F;
- N_r=N_r*factor+O_r;
- N_g=N_g*factor+O_g;
- N_b=N_b*factor+O_b;
- new_color=(N_r<<11)|(N_g<<6)|N_b;
- VIDEO[((y+dx)*SCREEN_WIDTH)+x+dy+(i-dy)] = new_color; /* octant 0 */
-
-
- /* Aquest no va del tot be */
- orig_color=VIDEO[((y+dx)*SCREEN_WIDTH)+x-dy-(i-dy)];
- N_r=(orig_color>>11)&0x1F;
- N_g=(orig_color>>6)&0x1F;
- N_b=orig_color&0x1F;
- N_r=N_r*factor+O_r;
- N_g=N_g*factor+O_g;
- N_b=N_b*factor+O_b;
- new_color=(N_r<<11)|(N_g<<6)|N_b;
- if (dx!=i)
- VIDEO[((y+dx)*SCREEN_WIDTH)+x-dy-(i-dy)] = new_color; /* octant 0 */
-
-
- orig_color=VIDEO[((y-dx)*SCREEN_WIDTH)+x-dy-(i-dy)];
- N_r=(orig_color>>11)&0x1F;
- N_g=(orig_color>>6)&0x1F;
- N_b=orig_color&0x1F;
- N_r=N_r*factor+O_r;
- N_g=N_g*factor+O_g;
- N_b=N_b*factor+O_b;
- new_color=(N_r<<11)|(N_g<<6)|N_b;
- if (dx!=0&&dx!=i)
- VIDEO[((y-dx)*SCREEN_WIDTH)+x-dy-(i-dy)] = new_color; /* octant 0 */
- }
- dx++;
- n+=invradius;
- dy = (int)((radius * SIN_ACOS[(int)(n>>6)]) >> 16);
- }
- }
- void circle_fast_plane(int x,int y, int radius, unsigned short color, int plane){
- unsigned short* VIDEO=(unsigned short*)0xD0800000;
- if (plane>-1) VIDEO=(unsigned short*)plane_list[plane];
- unsigned short n=0,invradius=(1/(float)radius)*0x10000L;
- int dx=0,dy=radius-1;
- while (dx<=dy){
- VIDEO[((y+dy)*SCREEN_WIDTH)+x+dx] = color; /* octant 0 */
- VIDEO[((y+dy)*SCREEN_WIDTH)+x-dx] = color; /* octant 0 */
- VIDEO[((y-dy)*SCREEN_WIDTH)+x-dx] = color; /* octant 0 */
- VIDEO[((y-dy)*SCREEN_WIDTH)+x+dx] = color; /* octant 0 */
-
- VIDEO[((y-dx)*SCREEN_WIDTH)+x+dy] = color; /* octant 0 */
- VIDEO[((y+dx)*SCREEN_WIDTH)+x+dy] = color; /* octant 0 */
- VIDEO[((y+dx)*SCREEN_WIDTH)+x-dy] = color; /* octant 0 */
- VIDEO[((y-dx)*SCREEN_WIDTH)+x-dy] = color; /* octant 0 */
- dx++;
- n+=invradius;
- dy = (int)((radius * SIN_ACOS[(int)(n>>6)]) >> 16);
- }
- }