Demo entry 6364917

c

   

Submitted by anonymous on May 17, 2017 at 11:46
Language: C. Code size: 1.2 kB.

int row;

void mprintf(char* fmt, ...) {
	char* pos;
	int offset, num, para, n, a[10], flag;
	offset = 0;
	para = 0;
	flag = 1;

	for(pos = fmt; *pos != '\0'; pos++) {
		if(*pos == '%') {
			if(*(pos + 1) == 'd') {
				num = *(int *)(_BP + 6 + para * 2);
				
				n = 0;
				while(num) {
					a[n] = num % 10;
					if(a[n] < 0) {
						flag = 0;
						a[n] = -a[n];
					}
					num /= 10;
					n++;
				}

				if(flag == 0) {
					*(char far *)(0xb8000000 + 160 * row + offset * 2 + 80) = '-';
					*(char far *)(0xb8000000 + 160 * row + offset * 2 + 81) = 2;
					offset++;
				}

				while(n) {
					*(char far *)(0xb8000000 + 160 * row + offset * 2 + 80) = a[--n] + 0x30;
					*(char far *)(0xb8000000 + 160 * row + offset * 2 + 81) = 2;
					offset++;
				}
			}

			if(*(pos + 1) == 'c') {
				*(char far *)(0xb8000000 + 160 * row + offset * 2 + 80) = *(int *)(_BP + para * 2 + 6);
				*(char far *)(0xb8000000 + 160 * row + offset * 2 + 81) = 2;
				offset++;
			}
			para++;
		}

		if(*pos == ' ') {
			*(char far *)(0xb8000000 + 160 * row + offset * 2 + 80) = 0;
			offset++;
		}
	}
}

main() {
	row = 10;
	mprintf("%c %d\n", 'a', -32768);
	row++;
	mprintf("%c %d\n", 'z', 32767);
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).