7 #include "src\lib\modex16.h"
10 byte far* VGA=(byte far*) 0xA0000000; /* this points to video memory. */
12 static void fadePalette(sbyte fade, sbyte start, word iter, byte *palette);
13 static byte tmppal[PAL_SIZE];
22 int86(VIDEO_INT, ®s, ®s);
26 /* -========================= Entry Points ==========================- */
30 dword far*ptr=(dword far*)VGA; /* used for faster screen clearing */
32 0x0d06, /* vertical total */
33 0x3e07, /* overflow (bit 8 of vertical counts) */
34 0x4109, /* cell height (2 to double-scan */
35 0xea10, /* v sync start */
36 0xac11, /* v sync end and protect cr0-cr7 */
37 0xdf12, /* vertical displayed */
38 0x0014, /* turn off dword mode */
39 0xe715, /* v blank start */
40 0x0616, /* v blank end */
41 0xe317 /* turn on byte mode */
43 int CRTParmCount = sizeof(CRTParms) / sizeof(CRTParms[0]);
45 /* TODO save current video mode and palette */
46 vgaSetMode(VGA_256_COLOR_MODE);
48 /* disable chain4 mode */
49 outpw(SC_INDEX, 0x0604);
51 /* synchronous reset while setting Misc Output */
52 outpw(SC_INDEX, 0x0100);
54 /* select 25 MHz dot clock & 60 Hz scanning rate */
55 outp(MISC_OUTPUT, 0xe3);
57 /* undo reset (restart sequencer) */
58 outpw(SC_INDEX, 0x0300);
60 /* reprogram the CRT controller */
61 outp(CRTC_INDEX, 0x11); /* VSync End reg contains register write prot */
62 outp(CRTC_DATA, 0x7f); /* get current write protect on varios regs */
64 /* send the CRTParms */
65 for(i=0; i<CRTParmCount; i++) {
66 outpw(CRTC_INDEX, CRTParms[i]);
69 /* clear video memory */
70 outpw(SC_INDEX, 0x0f02);
71 for(i=0; i<0x8000; i++) {
79 /* TODO restore original mode and palette */
80 vgaSetMode(TEXT_MODE);
88 /* default page values */
92 page.width = SCREEN_WIDTH;
93 page.height = SCREEN_HEIGHT;
98 /* returns the next page in contiguous memory
99 * the next page will be the same size as p, by default
102 modexNextPage(page_t *p) {
105 result.data = p->data + (p->width/4)*p->height; /* compute the offset */
108 result.width = p->width;
109 result.height = p->height;
116 modexShowPage(page_t *page) {
122 /* calculate offset */
123 offset = (word) page->data;
124 offset += page->dy * (page->width >> 2 );
125 offset += page->dx >> 2;
127 /* calculate crtcOffset according to virtual width */
128 crtcOffset = page->width >> 3;
130 high_address = HIGH_ADDRESS | (offset & 0xff00);
131 low_address = LOW_ADDRESS | (offset << 8);
133 /* wait for appropriate timing and then program CRTC */
134 while ((inp(INPUT_STATUS_1) & DISPLAY_ENABLE));
135 outpw(CRTC_INDEX, high_address);
136 outpw(CRTC_INDEX, low_address);
137 outp(CRTC_INDEX, 0x13);
138 outp(CRTC_DATA, crtcOffset);
140 /* wait for one retrace */
141 while (!(inp(INPUT_STATUS_1) & VRETRACE));
143 /* do PEL panning here */
144 outp(AC_INDEX, 0x33);
145 outp(AC_INDEX, (page->dx & 0x03) << 1);
150 modexPanPage(page_t *page, int dx, int dy) {
157 modexSelectPlane(byte plane) {
158 outp(SC_INDEX, MAP_MASK); /* select plane */
159 outp(SC_DATA, plane);
164 modexClearRegion(page_t *page, int x, int y, int w, int h, byte color) {
165 word pageOff = (word) page->data;
166 word xoff=x/4; /* xoffset that begins each row */
167 word scanCount=w/4; /* number of iterations per row (excluding right clip)*/
168 word poffset = pageOff + y*(page->width/4) + xoff; /* starting offset */
169 word nextRow = page->width/4-scanCount-1; /* loc of next row */
170 byte lclip[] = {0x0f, 0x0e, 0x0c, 0x08}; /* clips for rectangles not on 4s */
171 byte rclip[] = {0x00, 0x01, 0x03, 0x07};
172 byte left = lclip[x&0x03];
173 byte right = rclip[(x+w)&0x03];
175 /* handle the case which requires an extra group */
176 if((x & 0x03) && !((x+w) & 0x03)) {
181 MOV AX, SCREEN_SEG ; go to the VGA memory
183 MOV DI, poffset ; go to the first pixel
184 MOV DX, SC_INDEX ; point to the map mask
188 MOV AL, color ; get ready to write colors
190 MOV CX, scanCount ; count the line
191 MOV BL, AL ; remember color
192 MOV AL, left ; do the left clip
193 OUT DX, AL ; set the left clip
194 MOV AL, BL ; restore color
195 STOSB ; write the color
197 JZ SCAN_DONE ; handle 1 group stuff
199 ;-- write the main body of the scanline
200 MOV BL, AL ; remember color
201 MOV AL, 0x0f ; write to all pixels
203 MOV AL, BL ; restore color
204 REP STOSB ; write the color
206 MOV BL, AL ; remeber color
208 OUT DX, AL ; do the right clip
209 MOV AL, BL ; restore color
211 ADD DI, nextRow ; go to the next row
219 modexDrawBmp(page_t *page, int x, int y, bitmap_t *bmp) {
220 /* draw the region (the entire freakin bitmap) */
221 modexDrawBmpRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp);
226 modexDrawBmpRegion(page_t *page, int x, int y,
227 int rx, int ry, int rw, int rh, bitmap_t *bmp) {
228 word poffset = (word) page->data + y*(page->width/4) + x/4;
229 byte *data = bmp->data;//+bmp->offset;
230 word bmpOffset = (word) data + ry * bmp->width + rx;
233 byte plane = 1 << ((byte) x & 0x03);
234 word scanCount = width/4 + (width%4 ? 1 :0);
235 word nextPageRow = page->width/4 - scanCount;
236 word nextBmpRow = (word) bmp->width - width;
238 byte planeCounter = 4;
240 //code is a bit slow here
242 MOV AX, SCREEN_SEG ; go to the VGA memory
245 MOV DX, SC_INDEX ; point at the map mask register
250 MOV DX, SC_DATA ; select the current plane
254 ;-- begin plane painting
255 MOV AX, height ; start the row counter
257 MOV DI, poffset ; go to the first pixel
258 MOV SI, bmpOffset ; go to the bmp pixel
260 MOV CX, width ; count the columns
262 MOVSB ; copy the pixel
263 SUB CX, 3 ; we skip the next 3
264 ADD SI, 3 ; skip the bmp pixels
265 LOOP SCAN_LOOP ; finish the scan
268 ADD DI, AX ; go to the next row on screen
270 ADD SI, AX ; go to the next row on bmp
273 JNZ ROW_LOOP ; do all the rows
274 ;-- end plane painting
276 MOV AL, plane ; advance to the next plane
278 AND AL, 0x0f ; mask the plane properly
279 MOV plane, AL ; store the plane
281 INC bmpOffset ; start bmp at the right spot
284 JNZ PLANE_LOOP ; do all 4 planes
290 modexDrawPlanarBuf(page_t *page, int x, int y, planar_buf_t *bmp) {
291 /* TODO - adapt from test code */
293 for(plane=0; plane < 4; plane++)
301 modexDrawSprite(page_t *page, int x, int y, bitmap_t *bmp) {
302 /* draw the whole sprite */
303 modexDrawSpriteRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp);
307 modexDrawSpriteRegion(page_t *page, int x, int y,
308 int rx, int ry, int rw, int rh, bitmap_t *bmp) {
309 word poffset = (word)page->data + y*(page->width/4) + x/4;
310 byte *data = bmp->data;//+bmp->offset;
311 word bmpOffset = (word) data + ry * bmp->width + rx;
314 byte plane = 1 << ((byte) x & 0x03);
315 word scanCount = width/4 + (width%4 ? 1 :0);
316 word nextPageRow = page->width/4 - scanCount;
317 word nextBmpRow = (word) bmp->width - width;
319 byte planeCounter = 4;
322 MOV AX, SCREEN_SEG ; go to the VGA memory
325 MOV DX, SC_INDEX ; point at the map mask register
330 MOV DX, SC_DATA ; select the current plane
334 ;-- begin plane painting
335 MOV AX, height ; start the row counter
337 MOV DI, poffset ; go to the first pixel
338 MOV SI, bmpOffset ; go to the bmp pixel
340 MOV CX, width ; count the columns
345 JNE DRAW_PIXEL ; draw non-zero pixels
347 INC DI ; skip the transparent pixel
351 MOVSB ; copy the pixel
353 SUB CX, 3 ; we skip the next 3
354 ADD SI, 3 ; skip the bmp pixels
355 LOOP SCAN_LOOP ; finish the scan
358 ADD DI, AX ; go to the next row on screen
360 ADD SI, AX ; go to the next row on bmp
363 JNZ ROW_LOOP ; do all the rows
364 ;-- end plane painting
366 MOV AL, plane ; advance to the next plane
368 AND AL, 0x0f ; mask the plane properly
369 MOV plane, AL ; store the plane
371 INC bmpOffset ; start bmp at the right spot
374 JNZ PLANE_LOOP ; do all 4 planes
379 /* copy a region of video memory from one page to another.
380 * It assumes that the left edge of the tile is the same on both
381 * regions and the memory areas do not overlap.
384 modexCopyPageRegion(page_t *dest, page_t *src,
387 word width, word height)
389 word doffset = (word)dest->data + dy*(dest->width/4) + dx/4;
390 word soffset = (word)src->data + sy*(src->width/4) + sx/4;
391 word scans = width/4;
392 word nextSrcRow = src->width/4 - scans - 1;
393 word nextDestRow = dest->width/4 - scans - 1;
394 byte lclip[] = {0x0f, 0x0e, 0x0c, 0x08}; /* clips for rectangles not on 4s */
395 byte rclip[] = {0x0f, 0x01, 0x03, 0x07};
396 byte left = lclip[sx&0x03];
397 byte right = rclip[(sx+width)&0x03];
400 MOV AX, SCREEN_SEG ; work in the vga space
405 MOV DX, GC_INDEX ; turn off cpu bits
409 MOV AX, SC_INDEX ; point to the mask register
419 MOV CX, scans ; the number of latches
421 MOV AL, left ; do the left column
426 MOV AL, 0fh ; do the inner columns
428 REP MOVSB ; copy the pixels
430 MOV AL, right ; do the right column
435 MOV AX, SI ; go the start of the next row
439 ADD AX, nextDestRow ;
442 DEC height ; do the rest of the actions
445 MOV DX, GC_INDEX+1 ; go back to CPU data
446 MOV AL, 0ffh ; none from latches
454 modexFadeOn(word fade, byte *palette) {
455 fadePalette(-fade, 64, 64/fade+1, palette);
460 modexFadeOff(word fade, byte *palette) {
461 fadePalette(fade, 0, 64/fade+1, palette);
466 modexFlashOn(word fade, byte *palette) {
467 fadePalette(fade, -64, 64/fade+1, palette);
472 modexFlashOff(word fade, byte *palette) {
473 fadePalette(-fade, 0, 64/fade+1, palette);
478 fadePalette(sbyte fade, sbyte start, word iter, byte *palette) {
482 /* handle the case where we just update */
484 modexPalUpdate2(palette);
488 while(iter > 0) { /* FadeLoop */
489 for(i=0; i<PAL_SIZE; i++) { /* loadpal_loop */
490 tmppal[i] = palette[i] - dim;
491 if(tmppal[i] > 127) {
493 } else if(tmppal[i] > 63) {
497 modexPalUpdate2(tmppal);
506 modexPalSave(byte *palette) {
509 outp(PAL_READ_REG, 0); /* start at palette entry 0 */
510 for(i=0; i<PAL_SIZE; i++) {
511 palette[i] = inp(PAL_DATA_REG); /* read the palette data */
519 ptr = malloc(PAL_SIZE);
523 printf("Could not allocate palette.\n");
532 modexLoadPalFile(byte *filename, byte **palette) {
536 /* free the palette if it exists */
541 /* allocate the new palette */
542 *palette = modexNewPal();
545 file = fopen(filename, "rb");
547 printf("Could not open palette file: %s\n", filename);
554 *ptr++ = fgetc(file);
562 modexSavePalFile(char *filename, byte *pal) {
566 /* open the file for writing */
567 file = fopen(filename, "wb");
569 printf("Could not open %s for writing\n", filename);
573 /* write the data to the file */
574 fwrite(pal, 1, PAL_SIZE, file);
582 fadePalette(-1, 64, 1, tmppal);
588 fadePalette(-1, -64, 1, tmppal);
594 modexPalUpdate(bitmap_t *bmp, word *i, word qp, word qr)
596 byte *p = bmp->palette;
601 static word a[256] = { 0 };
603 word pp=0,aqpp=0,spee=0,ppee=0;
605 // if(qp>0) printf("(*i)=%02d\n", (*i));
607 if((*i)==0) outp(PAL_WRITE_REG, 0); /* start at the beginning of palette */
619 (*qqqq)=(*i)-(bmp->offset*3);
622 // printf("q: %02d\n", (q));
623 //printf("mxi1: %02d\n", mxi1);
624 // printf("qq: %02d\n", (qq));
625 //printf(" ((*i)-(bmp->offset*3))=%02d\n", ((*i)-(bmp->offset*3)));
626 //printf(" (*i)-q=%02d\n", (*i)-q);
627 // printf("qqqq: %d\n",(*qqqq));
628 // printf("================\n");
629 outp(PAL_WRITE_REG, qq); /* start at the beginning of palette */
631 if((*i)<PAL_SIZE/2 && w==0)
633 for(; (*i)<PAL_SIZE/2; (*i)++)
635 //if(i%3==0 && (p[i+5]==p[i+4] && p[i+4]==p[i+3] && p[i+3]==p[i+2] && p[i+2]==p[i+1] && p[i+1]==p[i] && p[i+5]==p[i]))
636 //____ if((qp>0)&&((*i)-q)%3==0 && (p[((*i)-q)]==p[((*i)-q)+3] && p[((*i)-q)+1]==p[((*i)-q)+4] && p[((*i)-q)+2]==p[((*i)-q)+5])) outp(PAL_DATA_REG, p[(*i)-q]); else
637 if((((*i)-q)%3==0 || ((qp>0)&&((*i)-(bmp->offset*3))%3==0)) && (p[((*i)-q)]==p[((*i)-q)+3] && p[((*i)-q)+1]==p[((*i)-q)+4] && p[((*i)-q)+2]==p[((*i)-q)+5]))
639 printf("[%d]", p[((*i)-q)]); printf("[%d]", p[((*i)-q)+1]); printf("[%d]", p[((*i)-q)+2]); printf("[%d]", p[((*i)-q)+3]); printf("[%d]", p[((*i)-q)+4]); printf("[%d]", p[((*i)-q)+5]); printf(" %d [%d]\n", (*i), p[((*i)-q)]);
647 printf(" ((*i)-(bmp->offset*3))=%02d\n", ((*i)-(bmp->offset*3)));
651 printf("(*i)-q=%02d", (*i)-q);
652 printf("[%d]", p[((*i)-q)]); printf("[%d]", p[((*i)-q)+1]); printf("[%d]", p[((*i)-q)+2]); printf("[%d]", p[((*i)-q)+3]); printf("[%d]", p[((*i)-q)+4]); printf("[%d]", p[((*i)-q)+5]); printf(" %d [%d]\n", (*i), p[((*i)-q)]);
654 if(qp==0) outp(PAL_DATA_REG, p[(*i)-q]);
655 else outp(PAL_DATA_REG, p[((*i)-(bmp->offset*3))]);
659 chkcolor(bmp, &q, &a, &aa, &z);
662 printf("%d qqqq\n", qq);
663 outp(PAL_DATA_REG, p[(*i)-q]);
668 outp(PAL_DATA_REG, p[(*i)-q]);
673 modexWaitBorder(); /* waits one retrace -- less flicker */
674 if((*i)>=PAL_SIZE/2 && w==0)
676 for(; (*i)<PAL_SIZE; (*i)++)
678 //____ if((qp>0)&&((*i)-q)%3==0 && (p[((*i)-q)]==p[((*i)-q)+3] && p[((*i)-q)+1]==p[((*i)-q)+4] && p[((*i)-q)+2]==p[((*i)-q)+5])) outp(PAL_DATA_REG, p[(*i)-q]); else
679 if((((*i)-q)%3==0 || ((qp>0)&&((*i)-(bmp->offset*3))%3==0)) && (p[((*i)-q)]==p[((*i)-q)+3] && p[((*i)-q)+1]==p[((*i)-q)+4] && p[((*i)-q)+2]==p[((*i)-q)+5]))
681 printf("[%d]", p[((*i)-q)]); printf("[%d]", p[((*i)-q)+1]); printf("[%d]", p[((*i)-q)+2]); printf("[%d]", p[((*i)-q)+3]); printf("[%d]", p[((*i)-q)+4]); printf("[%d]", p[((*i)-q)+5]); printf(" %d [%d]\n", (*i), p[((*i)-q)]);
689 printf(" ((*i)-(bmp->offset*3))=%02d\n", ((*i)-(bmp->offset*3)));
693 printf("(*i)-q=%02d", (*i)-q);
694 printf("[%d]", p[((*i)-q)]); printf("[%d]", p[((*i)-q)+1]); printf("[%d]", p[((*i)-q)+2]); printf("[%d]", p[((*i)-q)+3]); printf("[%d]", p[((*i)-q)+4]); printf("[%d]", p[((*i)-q)+5]); printf(" %d [%d]\n", (*i), p[((*i)-q)]);
696 if(qp==0) outp(PAL_DATA_REG, p[(*i)-q]);
697 else outp(PAL_DATA_REG, p[((*i)-(bmp->offset*3))]);
701 chkcolor(bmp, &q, &a, &aa, &z);
704 printf("%d qqqq\n", qq);
705 outp(PAL_DATA_REG, p[(*i)-q]);
710 outp(PAL_DATA_REG, p[(*i)-q]);
716 // if(qp>0) printf("(*i)=%02d\n", (*i));
719 if(q>0 && qp==0/* && qr==0*/)
723 long bufSize = (bmp->width * bmp->height);
724 chkcolor(bmp, &q, &a, &aa, &z);
726 printf("z=%d\n", z/3);
727 printf("q+z=%d\n", (q+z)/3);
728 printf("z-ppee=%d\n", (z-ppee)/3);
729 // printf("%d\n", (z-(z-ppee))/3);
730 printf("q=%d\n", q/3);
731 printf("aa=%d\n", aa);
733 aq=0; pp = q; ppee=q;//(aq)*3;
737 //printf("a[%02d]=(%d)", aq, a[aq]);
747 // printf("\naq=%02d\n", aq);
748 // printf("spee=%02d\n\n", spee);
749 //printf("aqpp=%02d\n\n", aqpp/3);
751 for(lq=0; lq<bufSize; lq++)
753 if(bmp->data[lq]+bmp->offset==aq)
755 //printf("%02d", bmp->data[lq]);
756 //printf("\n%02d\n", bmp->offset);
757 //printf("%02d\n", a[aq]);
758 bmp->data[lq]=((bmp->data[lq]+bmp->offset)-a[aq]);
760 else if(bmp->data[lq]+bmp->offset < z/3){ bmp->data[lq]+=bmp->offset; }
761 //printf("%02d ", bmp->data[lq]);
762 //if(lq > 0 && lq%bmp->width==0) printf("\n");
770 /*printf("pp=%02d ", pp/3);
771 printf("bmp: [%d]", bmp->palette[pp-ppee]);
772 printf("[%d]", bmp->palette[(pp-ppee)+1]);
773 printf("[%d]\n", bmp->palette[(pp-ppee)+2]);*/
774 if(((pp/3)==aq || spee>0))
776 printf("spee=%d\n", spee);
777 printf(" pp=%02d ", pp/3);
778 printf("old bmp: [%d]", bmp->palette[(pp-ppee)]);
779 printf("[%d]", bmp->palette[(pp-ppee)+1]);
780 printf("[%d]\n", bmp->palette[(pp-ppee)+2]);
781 //if(spee==0) printf("\npp=%02d\n\n", pp/3);
782 bmp->palette[(pp-ppee)]= bmp->palette[(pp-ppee)+3];
783 bmp->palette[(pp-ppee)+1]= bmp->palette[(pp-ppee)+4];
784 bmp->palette[(pp-ppee)+2]= bmp->palette[(pp-ppee)+5];
787 /* bmp->palette[pp]= bmp->palette[pp+3];
788 bmp->palette[pp+1]= bmp->palette[pp+4];
789 bmp->palette[pp+2]= bmp->palette[pp+5];*/
790 printf(" pp=%02d ", pp/3);
791 printf(" bmp: [%d]", bmp->palette[(pp-ppee)]);
792 printf("[%d]", bmp->palette[(pp-ppee)+1]);
793 printf("[%d]\n", bmp->palette[(pp-ppee)+2]);
794 /* printf("bmp: [%d]", bmp->palette[pp]);
795 printf("[%d]", bmp->palette[pp+1]);
796 printf("[%d]\n", bmp->palette[pp+2]);*/
798 //else if(pp==(z-1)) bmp->palette[pp]=0;
804 //printf("aqpp= %02d\n", aqpp/3);
805 //printf("pp= %02d\n", pp/3);
806 //printf("ppp= %02d\n", ppp/3);
807 //printf("&aqpp= %02d\n", &aqpp);
808 //printf("q= %02d\n", q/3);
809 //printf("z= %02d\n", z/3);
810 //printf("&q= %02d\n", &q);
811 //modexPalUpdate(bmp, &q, 1);
812 //modexPalUpdate(bmp, &, 1);
814 //modexPalUpdate(bmp, &ppp, 1);
815 modexPalUpdate(bmp, &aqpp, 1, aqpp);
816 printf("aqpp= %02d\n", aqpp/3);
817 printf("aq= %02d\n", aq);
818 printf("aa= %02d\n", aa);
821 // modexPalUpdate(bmp, 0, 1);
823 if(aq<aa){ printf("~~~~\n"); /*ppp=q; spee=0;*/ aq++; goto aqpee; }
829 modexPalUpdate2(byte *p)
833 outp(PAL_WRITE_REG, 0); /* start at the beginning of palette */
834 for(i=0; i<PAL_SIZE/2; i++)
836 outp(PAL_DATA_REG, p[i]);
838 modexWaitBorder(); /* waits one retrace -- less flicker */
839 for(; i<PAL_SIZE; i++)
841 outp(PAL_DATA_REG, p[(i)]);
845 void chkcolor(bitmap_t *bmp, word *q, word *a, word *aa, word *z)
852 //printf("q: %02d\n", (*q));
853 //check palette for dups
854 for((*z)=0; (*z)<PAL_SIZE; (*z)+=3)
856 // printf("\n z: %d\n", (*z));
857 // printf(" q: %d\n", (*q));
858 // printf(" z+q: %d\n\n", ((*z)+(*q)));
861 if(pal[(*z)]==pal[(*z)+3] && pal[(*z)+1]==pal[(*z)+4] && pal[(*z)+2]==pal[(*z)+5])
863 // printf("\n%d [%02d][%02d][%02d]\n", (*z), pal[(*z)], pal[(*z)+1], pal[(*z)+2]);
864 // printf("%d [%02d][%02d][%02d]\n\n", (*z)+3, pal[(*z)+3], pal[(*z)+4], pal[(*z)+5]);
867 else for(zz=0; zz<(*q); zz+=3)
870 //printf("zz: %02d\n", zz/3);
873 if(pal[((*z)+(*q))]==pal[((*z)+(*q))+3] && pal[((*z)+(*q))+1]==pal[((*z)+(*q))+4] && pal[((*z)+(*q))+2]==pal[((*z)+(*q))+5])
875 // printf("\nzq1:%d[%02d][%02d][%02d]\n", (zz+q), pal[(zz+q)], pal[(zz+q)+1], pal[(zz+q)+2]);
876 // printf("zq2:%d[%02d][%02d][%02d]\n\n", (zz+q)+3, pal[(zz+q)+3], pal[(zz+q)+4], pal[(zz+q)+5]);
879 else if(pal[zz]==pal[((*z)+(*q))] && pal[zz+1]==pal[((*z)+(*q))+1] && pal[zz+2]==pal[((*z)+(*q))+2])
881 // printf("\n\nwwwwwwwwwwwwwwww\n");
882 // printf(" zq: %d [%02d][%02d][%02d] value that is needing to be changed~\n", ((*z)+(*q))/3, pal[((*z)+(*q))], pal[((*z)+(*q))+1], pal[((*z)+(*q))+2]);
883 // printf(" zz: %d [%02d][%02d][%02d] value that the previous value is going to change to~\n", (zz)/3, pal[zz], pal[zz+1], pal[zz+2]);
884 // //printf(" zv: %d [%02d][%02d][%02d] wwww\n", (zz-z+q)/3, pal[(zz-z+q)], pal[(zz-z+q)+1], pal[(zz-z+q)+2]);
885 // printf(" z : %d [%02d][%02d][%02d] offset value~\n", (*z)/3, pal[(*z)], pal[(*z)+1], pal[(*z)+2]);
886 a[((*z)+(*q))/3]=zz/3;
888 // printf("\n aa: %d\n\n", (*aa));
889 // printf(" a[%02d]=(%02d) offset array i think the palette should be updated again~\n", ((*z)+(*q))/3, a[((*z)+(*q))/3]);
890 // printf("wwwwwwwwwwwwwwww\n\n");
894 printf("================\n");
895 printf("zq: %d [%02d][%02d][%02d]\n", ((*z)+(*q))/3, pal[((*z)+(*q))], pal[((*z)+(*q))+1], pal[((*z)+(*q))+2]);
896 printf("zz: %d [%02d][%02d][%02d]\n", (zz)/3, pal[zz], pal[zz+1], pal[zz+2]);
897 printf("z : %d [%02d][%02d][%02d]\n", (*z)/3, pal[(*z)], pal[(*z)+1], pal[(*z)+2]);
898 printf("================\n");
900 //printf("[%d]", (zz+q));
903 //printf("\nz: %d\n", z);
904 //printf("q: %d\n", q);
905 //printf("zz: %d\n", zz);
913 while(inp(INPUT_STATUS_1) & 8) {
917 while(!(inp(INPUT_STATUS_1) & 8)) {