/* Keep these headers */ #include #include #include #include #pragma asm "include \"ti84pce.inc\"" /* Standard headers - it's recommended to leave them included */ #include #include #include #include /* Other available headers */ // stdarg.h, setjmp.h, assert.h, ctype.h, float.h, iso646.h, limits.h, errno.h #include "int64.h" #include "tools.h" #define min(a,b) (((a)<(b))?(a):(b)) #define max(a,b) (((a)>(b))?(a):(b)) #define abs(x) (((x)<0)?-(x):(x)) #define SCR_WIDTH 320 #define SCR_HEIGHT 240 static const uint16_t* screen_buf = (uint16_t*)0xD40000; typedef uint16_t color_t; #define rgb2color(r, g, b) ((color_t)(((r << 8) & 0xf800) | ((g << 3) & 0x07e0) | (b >> 3))) void gc_drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1); void gc_fillRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h); void printTextSmall(const char *text, uint8_t xpos, uint8_t ypos); void getAns(); int64_t readInt(uint8_t** p_ptr); #define gc_drawPixel(x, y) *((uint16_t*)(screen_buf + x + y*SCR_WIDTH)) = globalColor; #define gc_setColorRGB(r, g, b) globalColor = rgb2color(r, g, b); color_t globalColor = 0; #define MAX_DIM SCR_HEIGHT /* Put all your code here */ void main(void) { uint32_t val_addr=0; int64_t val; uint8_t i = 0, val_type, *ptr = (uint8_t*) screen_buf, s; uint16_t n, c; int32_t x, y, x0, y0, d, d0, b, data[MAX_DIM]; /* This function cleans up the screen and gets everything ready for the OS */ pgrm_CleanUp(); /* uint64_t a=int32_to_int64(-523476189); uint64_t b=int32_to_int64(789652143); uint64_t r=int64_mul(a,b); // uquorem64_t q=uint64_divrem(a,b); printTextSmall(i64toa(a,0),0,0); printTextSmall(i64toa(b,0),0,12); printTextSmall(i64toa(r,0),0,24); printTextSmall(itoa(q.quo.lo,0),0,72); printTextSmall(itoa(q.quo.hi,0),0,84); printTextSmall(itoa(q.rem.lo,0),0,96); printTextSmall(itoa(q.rem.hi,0),0,108); */ getAns(); memcpy(&val_type,ptr,1); memcpy(&val_addr,ptr+1,3); val_type=val_type&0x1F; if(val_type==1 || val_type==0xD) { ptr[4]=0; ptr++; ptr=(uint8_t*)*((uint32_t*)ptr); n=*(uint16_t*)ptr; ptr+=2; if(n>4) { int64_t tmp64 = readInt(&ptr); x=int64_trunc_int32(tmp64); if(val_type==0xD) readInt(&ptr); //printTextSmall(i64toa(temp,0),0,0); tmp64 = readInt(&ptr); y=int64_trunc_int32(tmp64); if(val_type==0xD) readInt(&ptr); tmp64 = readInt(&ptr); b=int64_trunc_int32(tmp64); if(val_type==0xD) readInt(&ptr); tmp64 = readInt(&ptr); d=int64_trunc_int32(tmp64); if(val_type==0xD) readInt(&ptr); n=n-4; n=min(n,MAX_DIM); if(b<0) b=0; d0=SCR_HEIGHT/(n+2*b); if(d<1 || d>d0) d=d0; x0=(SCR_WIDTH-d*(n+2*b))/2; y0=(SCR_HEIGHT-d*(n+2*b))/2; if(x<0 || x+(n+2*b)*d>SCR_WIDTH-1) x=x0; if(y<0 || y+(n+2*b)*d>SCR_HEIGHT-1) y=y0; gc_setColorRGB(255, 255, 255); gc_fillRect(x, y, (n+2*b)*d, (n+2*b)*d); gc_setColorRGB(0, 0, 0); y+=b*d; for (i=0; i=0x80) { val=0; if(i<7) val=ptr[2+i]; tmp64=uint32_to_uint64(val>>4); r=uint64_mul(r,ten64); r=uint64_add(r,tmp64); exp--; if(exp>=0x80) { tmp64=uint32_to_uint64(val&0xF); r=uint64_mul(r,ten64); r=uint64_add(r,tmp64); exp--; } i++; } if(flags&0x80) r=int64_negate(r); *p_ptr=ptr+9; return r; } void getAns() { asm("CALL _AnsName"); asm("CALL _ChkFindSym"); asm("LD (D40000h),A"); asm("LD (D40001h),DE"); } void gc_drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { if (y1 == y0) { uint16_t *base = screen_buf + min(x0, x1) + y0*SCR_WIDTH; uint16_t end = abs(x0-x1)+1; uint16_t i; for (i = 0; i < end; i++) { *(base++) = globalColor; } } else { int dx = abs(x1-x0), sx = x0dy ? dx : -dy)/2, e2; for(;;) { gc_drawPixel(x0, y0); if (x0 == x1 && y0 == y1) break; e2 = err; if (e2 >-dx) { err -= dy; x0 += sx; } if (e2 < dy) { err += dx; y0 += sy; } } } } void gc_fillRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h) { uint16_t i, j; uint16_t* base = screen_buf + x + y*SCR_WIDTH; for(j=0; j