#include #include "aclib.h" #define EXIT_CLIPDEST(addr) if ((((word)addr)&0xfff) >= 0xe10) return // clear screen and set graphics mode void clrscr() { memset(vidmem, 0, VHEIGHT*VBWIDTH); // clear page 1 } // draw vertical line void vline(byte x, byte y1, byte y2, byte col, byte op) { byte xb = x>>2; // divide x by 4 byte* dest = &vmagic[y1][xb]; // destination address byte y; hw_magic = M_SHIFT(x) | op; // set magic register col <<= 6; // put color in high pixel for (y=y1; y<=y2; y++) { EXIT_CLIPDEST(dest); *dest = col; // shift + xor color dest += VBWIDTH; // dest address to next scanline } } // draw a pixel void pixel(byte x, byte y, byte col, byte op) { vline(x, y, y, col, op); // draw line with 1-pixel height } // render a sprite with the given graphics operation void render_sprite(const byte* src, byte x, byte y, byte op) { byte i,j; byte w = *src++; // get width from 1st byte of sprite byte h = *src++; // get height from 2nd byte of sprite byte xb = x>>2; // divide x by 4 byte* dest = &vmagic[y][xb]; // destination address hw_magic = M_SHIFT(x) | op; // set magic register for (j=0; j>2; // divide x by 4 byte* dest = &vidmem[y][xb]; // destination address for (j=0; j>2; // divide x by 4 byte* dest = &vmagic[y][xb]; // destination address hw_magic = M_SHIFT(x) | M_XPAND | op; for (byte i=0; i<8; i++) { char b = *src++; EXIT_CLIPDEST(dest); *dest++ = b; // expand lower nibble -> 1st byte *dest++ = b; // expand upper nibble -> 2nd byte *dest++ = 0; // leftover -> 3rd byte *dest = 0; // reset upper/lower flag dest += VBWIDTH-3; // we incremented 3 bytes for this line } } void draw_string(const char* str, byte x, byte y) { do { byte ch = *str++; if (!ch) break; draw_char(ch, x, y, M_MOVE); x += 8; } while (1); } void draw_bcd_word(word bcd, byte x, byte y, byte op) { byte j; x += 3*8; for (j=0; j<4; j++) { draw_char('0'+(bcd&0xf), x, y, op); x -= 8; bcd >>= 4; } } // add two 16-bit BCD values word bcd_add(word a, word b) { a; b; // to avoid warning __asm ld hl,#4 add hl,sp ld iy,#2 add iy,sp ld a,0 (iy) add a, (hl) daa ld c,a ld a,1 (iy) inc hl adc a, (hl) daa ld b,a ld l, c ld h, b __endasm; }