fixed pix edit dups; new cosmic

This commit is contained in:
Steven Hugg 2018-08-12 23:29:05 -04:00
parent bb639a0820
commit 56aab0e6a5
4 changed files with 153 additions and 92 deletions

View File

@ -1,4 +1,4 @@

#include <string.h>
#include <conio.h>
#include <apple2.h>
@ -21,7 +21,7 @@ typedef unsigned short word;
#define LUT(x) (byte*)(0x2000|x)
static byte* vidmem[VHEIGHT] = {
static byte* const vidmem[VHEIGHT] = {
LUT(0x0000), LUT(0x0400), LUT(0x0800), LUT(0x0c00), LUT(0x1000), LUT(0x1400), LUT(0x1800), LUT(0x1c00),
LUT(0x0080), LUT(0x0480), LUT(0x0880), LUT(0x0c80), LUT(0x1080), LUT(0x1480), LUT(0x1880), LUT(0x1c80),
LUT(0x0100), LUT(0x0500), LUT(0x0900), LUT(0x0d00), LUT(0x1100), LUT(0x1500), LUT(0x1900), LUT(0x1d00),
@ -48,6 +48,44 @@ static byte* vidmem[VHEIGHT] = {
LUT(0x03d0), LUT(0x07d0), LUT(0x0bd0), LUT(0x0fd0), LUT(0x13d0), LUT(0x17d0), LUT(0x1bd0), LUT(0x1fd0)
};
const byte DIV7_140[140] = {
0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 8,
9, 9, 9,10,10,10,10,11,11,11,12,12,12,12,13,13,13,14,14,14,14,15,15,15,16,16,16,16,17,17,17,18,
18,18,18,19,19,19,20,20,20,20,21,21,21,22,22,22,22,23,23,23,24,24,24,24,25,25,25,26,26,26,26,27,
27,27,28,28,28,28,29,29,29,30,30,30,30,31,31,31,32,32,32,32,33,33,33,34,34,34,34,35,35,35,36,36,
36,36,37,37,37,38,38,38,38,39,39,39};
const byte MOD7_140[140] = {
0, 2, 4, 6, 1, 3, 5, 0, 2, 4, 6, 1, 3, 5, 0, 2, 4, 6, 1, 3, 5, 0, 2, 4, 6, 1, 3, 5, 0, 2, 4, 6,
1, 3, 5, 0, 2, 4, 6, 1, 3, 5, 0, 2, 4, 6, 1, 3, 5, 0, 2, 4, 6, 1, 3, 5, 0, 2, 4, 6, 1, 3, 5, 0,
2, 4, 6, 1, 3, 5, 0, 2, 4, 6, 1, 3, 5, 0, 2, 4, 6, 1, 3, 5, 0, 2, 4, 6, 1, 3, 5, 0, 2, 4, 6, 1,
3, 5, 0, 2, 4, 6, 1, 3, 5, 0, 2, 4, 6, 1, 3, 5, 0, 2, 4, 6, 1, 3, 5, 0, 2, 4, 6, 1, 3, 5, 0, 2,
4, 6, 1, 3, 5, 0, 2, 4, 6, 1, 3, 5};
const byte DIV7[256] = {
0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4,
4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 9,
9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,11,11,11,11,11,11,11,12,12,12,12,12,12,12,13,13,13,13,13,
13,13,14,14,14,14,14,14,14,15,15,15,15,15,15,15,16,16,16,16,16,16,16,17,17,17,17,17,17,17,18,18,
18,18,18,18,18,19,19,19,19,19,19,19,20,20,20,20,20,20,20,21,21,21,21,21,21,21,22,22,22,22,22,22,
22,23,23,23,23,23,23,23,24,24,24,24,24,24,24,25,25,25,25,25,25,25,26,26,26,26,26,26,26,27,27,27,
27,27,27,27,28,28,28,28,28,28,28,29,29,29,29,29,29,29,30,30,30,30,30,30,30,31,31,31,31,31,31,31,
32,32,32,32,32,32,32,33,33,33,33,33,33,33,34,34,34,34,34,34,34,35,35,35,35,35,35,35,36,36,36,36};
const byte MOD7[256] = {
0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3,
4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0,
1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4,
5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1,
2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5,
6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2,
3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6,
0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3};
const byte BIT7[7] = { 1, 2, 4, 8, 16, 32, 64 };
#pragma static-locals(on)
/// SOUND FUNCTIONS
void tone(byte freq, byte dur, sbyte mod) {
@ -70,79 +108,83 @@ void clrscr() {
}
void xor_pixel(byte x, byte y) {
byte* dest = &vidmem[x][y>>3];
*dest ^= 0x1 << (y&7);
byte xb = DIV7[x];
byte mask = BIT7[MOD7[x]];
byte* dest = &vidmem[y][xb];
*dest ^= mask;
}
void draw_vline(byte x, byte y1, byte y2) {
byte yb1 = y1/8;
byte yb2 = y2/8;
byte* dest = &vidmem[x][yb1];
signed char nbytes = yb2 - yb1;
*dest++ ^= 0xff << (y1&7);
if (nbytes > 0) {
while (--nbytes > 0) {
*dest++ ^= 0xff;
}
*dest ^= 0xff >> (~y2&7);
} else {
*--dest ^= 0xff << ((y2+1)&7);
byte xb = DIV7[x];
byte mask = BIT7[MOD7[x]];
byte y;
for (y=y1; y<y2; y++) {
byte* dest = &vidmem[y][xb];
*dest ^= mask;
}
}
#define LOCHAR 0x20
#define HICHAR 0x5e
#define HICHAR 0x7f
const byte font8x8[HICHAR-LOCHAR+1][8] = {/*{w:8,h:8,bpp:1,count:64,xform:"rotate(-90deg)"}*/
{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, { 0x00,0x00,0x00,0x79,0x79,0x00,0x00,0x00 }, { 0x00,0x70,0x70,0x00,0x00,0x70,0x70,0x00 }, { 0x14,0x7f,0x7f,0x14,0x14,0x7f,0x7f,0x14 }, { 0x00,0x12,0x3a,0x6b,0x6b,0x2e,0x24,0x00 }, { 0x00,0x63,0x66,0x0c,0x18,0x33,0x63,0x00 }, { 0x00,0x26,0x7f,0x59,0x59,0x77,0x27,0x05 }, { 0x00,0x00,0x00,0x10,0x30,0x60,0x40,0x00 }, { 0x00,0x00,0x1c,0x3e,0x63,0x41,0x00,0x00 }, { 0x00,0x00,0x41,0x63,0x3e,0x1c,0x00,0x00 }, { 0x08,0x2a,0x3e,0x1c,0x1c,0x3e,0x2a,0x08 }, { 0x00,0x08,0x08,0x3e,0x3e,0x08,0x08,0x00 }, { 0x00,0x00,0x00,0x03,0x03,0x00,0x00,0x00 }, { 0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x00 }, { 0x00,0x00,0x00,0x03,0x03,0x00,0x00,0x00 }, { 0x00,0x01,0x03,0x06,0x0c,0x18,0x30,0x20 }, { 0x00,0x3e,0x7f,0x49,0x51,0x7f,0x3e,0x00 }, { 0x00,0x01,0x11,0x7f,0x7f,0x01,0x01,0x00 }, { 0x00,0x23,0x67,0x45,0x49,0x79,0x31,0x00 }, { 0x00,0x22,0x63,0x49,0x49,0x7f,0x36,0x00 }, { 0x00,0x0c,0x0c,0x14,0x34,0x7f,0x7f,0x04 }, { 0x00,0x72,0x73,0x51,0x51,0x5f,0x4e,0x00 }, { 0x00,0x3e,0x7f,0x49,0x49,0x6f,0x26,0x00 }, { 0x00,0x60,0x60,0x4f,0x5f,0x70,0x60,0x00 }, { 0x00,0x36,0x7f,0x49,0x49,0x7f,0x36,0x00 }, { 0x00,0x32,0x7b,0x49,0x49,0x7f,0x3e,0x00 }, { 0x00,0x00,0x00,0x12,0x12,0x00,0x00,0x00 }, { 0x00,0x00,0x00,0x13,0x13,0x00,0x00,0x00 }, { 0x00,0x08,0x1c,0x36,0x63,0x41,0x41,0x00 }, { 0x00,0x14,0x14,0x14,0x14,0x14,0x14,0x00 }, { 0x00,0x41,0x41,0x63,0x36,0x1c,0x08,0x00 }, { 0x00,0x20,0x60,0x45,0x4d,0x78,0x30,0x00 }, { 0x00,0x3e,0x7f,0x41,0x59,0x79,0x3a,0x00 }, { 0x00,0x1f,0x3f,0x68,0x68,0x3f,0x1f,0x00 }, { 0x00,0x7f,0x7f,0x49,0x49,0x7f,0x36,0x00 }, { 0x00,0x3e,0x7f,0x41,0x41,0x63,0x22,0x00 }, { 0x00,0x7f,0x7f,0x41,0x63,0x3e,0x1c,0x00 }, { 0x00,0x7f,0x7f,0x49,0x49,0x41,0x41,0x00 }, { 0x00,0x7f,0x7f,0x48,0x48,0x40,0x40,0x00 }, { 0x00,0x3e,0x7f,0x41,0x49,0x6f,0x2e,0x00 }, { 0x00,0x7f,0x7f,0x08,0x08,0x7f,0x7f,0x00 }, { 0x00,0x00,0x41,0x7f,0x7f,0x41,0x00,0x00 }, { 0x00,0x02,0x03,0x41,0x7f,0x7e,0x40,0x00 }, { 0x00,0x7f,0x7f,0x1c,0x36,0x63,0x41,0x00 }, { 0x00,0x7f,0x7f,0x01,0x01,0x01,0x01,0x00 }, { 0x00,0x7f,0x7f,0x30,0x18,0x30,0x7f,0x7f }, { 0x00,0x7f,0x7f,0x38,0x1c,0x7f,0x7f,0x00 }, { 0x00,0x3e,0x7f,0x41,0x41,0x7f,0x3e,0x00 }, { 0x00,0x7f,0x7f,0x48,0x48,0x78,0x30,0x00 }, { 0x00,0x3c,0x7e,0x42,0x43,0x7f,0x3d,0x00 }, { 0x00,0x7f,0x7f,0x4c,0x4e,0x7b,0x31,0x00 }, { 0x00,0x32,0x7b,0x49,0x49,0x6f,0x26,0x00 }, { 0x00,0x40,0x40,0x7f,0x7f,0x40,0x40,0x00 }, { 0x00,0x7e,0x7f,0x01,0x01,0x7f,0x7e,0x00 }, { 0x00,0x7c,0x7e,0x03,0x03,0x7e,0x7c,0x00 }, { 0x00,0x7f,0x7f,0x06,0x0c,0x06,0x7f,0x7f }, { 0x00,0x63,0x77,0x1c,0x1c,0x77,0x63,0x00 }, { 0x00,0x70,0x78,0x0f,0x0f,0x78,0x70,0x00 }, { 0x00,0x43,0x47,0x4d,0x59,0x71,0x61,0x00 }, { 0x00,0x00,0x7f,0x7f,0x41,0x41,0x00,0x00 }, { 0x00,0x20,0x30,0x18,0x0c,0x06,0x03,0x01 }, { 0x00,0x00,0x41,0x41,0x7f,0x7f,0x00,0x00 }, { 0x00,0x08,0x18,0x3f,0x3f,0x18,0x08,0x00 }
const byte font8x8[HICHAR-LOCHAR+1][8] = {/*{w:8,h:8,bpp:1,count:96}*/
{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, { 0x18,0x18,0x18,0x18,0x00,0x00,0x18,0x00 }, { 0x66,0x66,0x66,0x00,0x00,0x00,0x00,0x00 }, { 0x66,0x66,0xff,0x66,0xff,0x66,0x66,0x00 }, { 0x18,0x7c,0x06,0x3c,0x60,0x3e,0x18,0x00 }, { 0x46,0x66,0x30,0x18,0x0c,0x66,0x62,0x00 }, { 0x3c,0x66,0x3c,0x1c,0xe6,0x66,0xfc,0x00 }, { 0x60,0x30,0x18,0x00,0x00,0x00,0x00,0x00 }, { 0x30,0x18,0x0c,0x0c,0x0c,0x18,0x30,0x00 }, { 0x0c,0x18,0x30,0x30,0x30,0x18,0x0c,0x00 }, { 0x00,0x66,0x3c,0xff,0x3c,0x66,0x00,0x00 }, { 0x00,0x18,0x18,0x7e,0x18,0x18,0x00,0x00 }, { 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x0c }, { 0x00,0x00,0x00,0x7e,0x00,0x00,0x00,0x00 }, { 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00 }, { 0x00,0xc0,0x60,0x30,0x18,0x0c,0x06,0x00 }, { 0x3c,0x66,0x76,0x6e,0x66,0x66,0x3c,0x00 }, { 0x18,0x18,0x1c,0x18,0x18,0x18,0x7e,0x00 }, { 0x3c,0x66,0x60,0x30,0x0c,0x06,0x7e,0x00 }, { 0x3c,0x66,0x60,0x38,0x60,0x66,0x3c,0x00 }, { 0x60,0x70,0x78,0x66,0xfe,0x60,0x60,0x00 }, { 0x7e,0x06,0x3e,0x60,0x60,0x66,0x3c,0x00 }, { 0x3c,0x66,0x06,0x3e,0x66,0x66,0x3c,0x00 }, { 0x7e,0x66,0x30,0x18,0x18,0x18,0x18,0x00 }, { 0x3c,0x66,0x66,0x3c,0x66,0x66,0x3c,0x00 }, { 0x3c,0x66,0x66,0x7c,0x60,0x66,0x3c,0x00 }, { 0x00,0x00,0x18,0x00,0x00,0x18,0x00,0x00 }, { 0x00,0x00,0x18,0x00,0x00,0x18,0x18,0x0c }, { 0x70,0x18,0x0c,0x06,0x0c,0x18,0x70,0x00 }, { 0x00,0x00,0x7e,0x00,0x7e,0x00,0x00,0x00 }, { 0x0e,0x18,0x30,0x60,0x30,0x18,0x0e,0x00 }, { 0x3c,0x66,0x60,0x30,0x18,0x00,0x18,0x00 }, { 0x3c,0x66,0x76,0x76,0x06,0x46,0x3c,0x00 }, { 0x18,0x3c,0x66,0x7e,0x66,0x66,0x66,0x00 }, { 0x3e,0x66,0x66,0x3e,0x66,0x66,0x3e,0x00 }, { 0x3c,0x66,0x06,0x06,0x06,0x66,0x3c,0x00 }, { 0x1e,0x36,0x66,0x66,0x66,0x36,0x1e,0x00 }, { 0x7e,0x06,0x06,0x1e,0x06,0x06,0x7e,0x00 }, { 0x7e,0x06,0x06,0x1e,0x06,0x06,0x06,0x00 }, { 0x3c,0x66,0x06,0x76,0x66,0x66,0x3c,0x00 }, { 0x66,0x66,0x66,0x7e,0x66,0x66,0x66,0x00 }, { 0x3c,0x18,0x18,0x18,0x18,0x18,0x3c,0x00 }, { 0x78,0x30,0x30,0x30,0x30,0x36,0x1c,0x00 }, { 0x66,0x36,0x1e,0x0e,0x1e,0x36,0x66,0x00 }, { 0x06,0x06,0x06,0x06,0x06,0x06,0x7e,0x00 }, { 0xc6,0xee,0xfe,0xd6,0xc6,0xc6,0xc6,0x00 }, { 0x66,0x6e,0x7e,0x7e,0x76,0x66,0x66,0x00 }, { 0x3c,0x66,0x66,0x66,0x66,0x66,0x3c,0x00 }, { 0x3e,0x66,0x66,0x3e,0x06,0x06,0x06,0x00 }, { 0x3c,0x66,0x66,0x66,0x66,0x3c,0x70,0x00 }, { 0x3e,0x66,0x66,0x3e,0x1e,0x36,0x66,0x00 }, { 0x3c,0x66,0x06,0x3c,0x60,0x66,0x3c,0x00 }, { 0x7e,0x18,0x18,0x18,0x18,0x18,0x18,0x00 }, { 0x66,0x66,0x66,0x66,0x66,0x66,0x3c,0x00 }, { 0x66,0x66,0x66,0x66,0x66,0x3c,0x18,0x00 }, { 0xc6,0xc6,0xc6,0xd6,0xfe,0xee,0xc6,0x00 }, { 0x66,0x66,0x3c,0x18,0x3c,0x66,0x66,0x00 }, { 0x66,0x66,0x66,0x3c,0x18,0x18,0x18,0x00 }, { 0x7e,0x60,0x30,0x18,0x0c,0x06,0x7e,0x00 }, { 0x3c,0x0c,0x0c,0x0c,0x0c,0x0c,0x3c,0x00 }, { 0x00,0x06,0x0c,0x18,0x30,0x60,0xc0,0x00 }, { 0x3c,0x30,0x30,0x30,0x30,0x30,0x3c,0x00 }, { 0x00,0x18,0x3c,0x7e,0x18,0x18,0x18,0x18 }, { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff }, { 0x06,0x0c,0x18,0x00,0x00,0x00,0x00,0x00 }, { 0x00,0x00,0x3c,0x60,0x7c,0x66,0x7c,0x00 }, { 0x00,0x06,0x06,0x3e,0x66,0x66,0x3e,0x00 }, { 0x00,0x00,0x3c,0x06,0x06,0x06,0x3c,0x00 }, { 0x00,0x60,0x60,0x7c,0x66,0x66,0x7c,0x00 }, { 0x00,0x00,0x3c,0x66,0x7e,0x06,0x3c,0x00 }, { 0x00,0x70,0x18,0x7c,0x18,0x18,0x18,0x00 }, { 0x00,0x00,0x7c,0x66,0x66,0x7c,0x60,0x3e }, { 0x00,0x06,0x06,0x3e,0x66,0x66,0x66,0x00 }, { 0x00,0x18,0x00,0x1c,0x18,0x18,0x3c,0x00 }, { 0x00,0x60,0x00,0x60,0x60,0x60,0x60,0x3c }, { 0x00,0x06,0x06,0x36,0x1e,0x36,0x66,0x00 }, { 0x00,0x1c,0x18,0x18,0x18,0x18,0x3c,0x00 }, { 0x00,0x00,0x66,0xfe,0xfe,0xd6,0xc6,0x00 }, { 0x00,0x00,0x3e,0x66,0x66,0x66,0x66,0x00 }, { 0x00,0x00,0x3c,0x66,0x66,0x66,0x3c,0x00 }, { 0x00,0x00,0x3e,0x66,0x66,0x3e,0x06,0x06 }, { 0x00,0x00,0x7c,0x66,0x66,0x7c,0x60,0x60 }, { 0x00,0x00,0x3e,0x66,0x06,0x06,0x06,0x00 }, { 0x00,0x00,0x7c,0x06,0x3c,0x60,0x3e,0x00 }, { 0x00,0x18,0x7e,0x18,0x18,0x18,0x70,0x00 }, { 0x00,0x00,0x66,0x66,0x66,0x66,0x7c,0x00 }, { 0x00,0x00,0x66,0x66,0x66,0x3c,0x18,0x00 }, { 0x00,0x00,0xc6,0xd6,0xfe,0x7c,0x6c,0x00 }, { 0x00,0x00,0x66,0x3c,0x18,0x3c,0x66,0x00 }, { 0x00,0x00,0x66,0x66,0x66,0x7c,0x30,0x1e }, { 0x00,0x00,0x7e,0x30,0x18,0x0c,0x7e,0x00 }, { 0x38,0x0c,0x0c,0x06,0x0c,0x0c,0x38,0x00 }, { 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18 }, { 0x1c,0x30,0x30,0x60,0x30,0x30,0x1c,0x00 }, { 0x00,0x4c,0x32,0x00,0x00,0x00,0x00,0x00 }, { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },
};
void draw_sprite(const byte* src, byte x, byte y) {
byte i,j;
byte w = *src++;
byte h = *src++;
for (j=0; j<h; j++) {
byte* dest = &vidmem[x++][y];
for (i=0; i<w; i++) {
*dest++ = *src++;
}
}
}
typedef enum {
OP_DRAW, OP_XOR, OP_ERASE
};
byte xor_sprite(const byte* src, byte x, byte y) {
byte render_sprite(const byte* src, byte x, byte y, byte op) {
byte i,j;
byte result = 0;
byte w = *src++;
byte h = *src++;
byte xb = DIV7[x];
byte xs = MOD7[x];
byte result = 0;
for (j=0; j<h; j++) {
byte* dest = &vidmem[x++][y];
byte* dest = &vidmem[y++][xb];
byte rest = 0;
for (i=0; i<w; i++) {
result |= (*dest++ ^= *src++);
byte data = *src++;
byte next = (data << xs) | rest;
switch (op) {
case OP_DRAW: *dest++ = next; break;
case OP_XOR: result |= (*dest++ ^= next); break;
case OP_ERASE: *dest++ &= ~next; break;
}
rest = data >> (7-xs);
}
switch (op) {
case OP_DRAW: *dest = rest; break;
case OP_XOR: result |= (*dest ^= rest); break;
case OP_ERASE: *dest &= ~rest; break;
}
}
return result;
}
void draw_sprite(const byte* src, byte x, byte y) {
render_sprite(src, x, y, OP_DRAW);
}
byte xor_sprite(const byte* src, byte x, byte y) {
return render_sprite(src, x, y, OP_XOR);
}
void erase_sprite(const byte* src, byte x, byte y) {
byte i,j;
byte w = *src++;
byte h = *src++;
for (j=0; j<h; j++) {
byte* dest = &vidmem[x++][y];
for (i=0; i<w; i++) {
*dest++ &= ~(*src++);
}
}
render_sprite(src, x, y, OP_ERASE);
}
void clear_sprite(const byte* src, byte x, byte y) {
byte i,j;
byte w = *src++;
byte h = *src++;
byte xb = DIV7[x];
for (j=0; j<h; j++) {
byte* dest = &vidmem[x++][y];
for (i=0; i<w; i++) {
*dest++ = 0;
byte* dest = &vidmem[y++][xb];
for (i=0; i<=w; i++) {
dest[i] = 0;
}
}
}
@ -190,19 +232,19 @@ word bcd_add(word a, word b) {
//
const byte player_bitmap[] =
{2,27,/*{w:16,h:27,bpp:1,xform:"rotate(-90deg)"}*/0x0,0x0,0x0,0x0,0x0f,0x00,0x3e,0x00,0xf4,0x07,0xec,0x00,0x76,0x00,0x2b,0x00,0x33,0x00,0x75,0x00,0xf5,0x00,0xeb,0x31,0xbf,0xef,0x3f,0xcf,0xbf,0xef,0xeb,0x31,0xf5,0x00,0x75,0x00,0x33,0x00,0x2b,0x00,0x76,0x00,0xec,0x00,0xf4,0x07,0x3e,0x00,0x0f,0x00,0x00,0x00,0x0,0x0};
{3,16,/*{w:24,h:16,bpp:1}*/0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x3C,0x00,0x04,0x18,0x20,0x04,0x18,0x20,0x0C,0x3C,0x30,0x3C,0x3C,0x3C,0xCC,0xE7,0x33,0x0C,0x66,0x30,0xC4,0xE7,0x23,0x34,0xE7,0x2C,0x0C,0x7E,0x30,0xCC,0xFF,0x33,0x3C,0x18,0x3C,0x0C,0x18,0x30,0x04,0x18,0x20};
const byte bomb_bitmap[] =
{1,5,/*{w:8,h:5,bpp:1,xform:"rotate(-90deg)"}*/0x88,0x55,0x77,0x55,0x88};
{1,5,/*{w:8,h:5,bpp:1}*/0x88,0x55,0x77,0x55,0x88};
const byte bullet_bitmap[] =
{2,2,/*{w:16,h:2,bpp:1,xform:"rotate(-90deg)"}*/0x88,0x88,0x44,0x44};
{1,5,/*{w:8,h:5,bpp:1}*/0x14,0x28,0x14,0x14,0x28};
const byte enemy1_bitmap[] =
{2,17,/*{w:16,h:17,bpp:1,xform:"rotate(-90deg)"}*/0x00,0x00,0x00,0x0c,0x04,0x1e,0x46,0x3f,0xb8,0x7f,0xb0,0x7f,0xba,0x7f,0xfd,0x3f,0xfc,0x07,0xfc,0x07,0xfd,0x3f,0xba,0x7f,0xb0,0x7f,0xb8,0x7f,0x46,0x3f,0x04,0x1e,0x00,0x0c};
{2,16,/*{w:16,h:16,bpp:1}*/0x00,0x00,0x70,0x38,0xF8,0x7C,0xFC,0xFC,0xFE,0xFC,0xFE,0xFF,0xFC,0xFF,0xF8,0x7F,0xF0,0x3F,0x88,0x47,0xF0,0x3F,0xF0,0x3F,0xD0,0x2F,0x8C,0xC7,0x48,0x48,0x80,0x04};
const byte enemy2_bitmap[] =
{2,16,/*{w:16,h:16,bpp:1,xform:"rotate(-90deg)"}*/0x26,0x00,0x59,0x10,0x10,0x30,0x33,0x18,0xe6,0x61,0xc4,0x56,0x03,0x03,0xdc,0x03,0xdc,0x03,0x03,0x03,0xc4,0x56,0xe6,0x61,0x33,0x18,0x10,0x30,0x59,0x10,0x26,0x00};
{2,16,/*{w:16,h:16,bpp:1}*/0x00,0x00,0x30,0x0C,0x14,0x28,0x2E,0x74,0x08,0x10,0x20,0x04,0xE0,0x07,0xD0,0x0B,0xB0,0x0D,0xB2,0x4D,0x19,0x98,0x8E,0x71,0x82,0x41,0xB1,0x8D,0x59,0x9A,0x4A,0x52};
const byte enemy3_bitmap[] =
{2,16,/*{w:16,h:16,bpp:1,xform:"rotate(-90deg)"}*/0x80,0x1f,0xc0,0x03,0xf8,0x3f,0x70,0x00,0xf0,0x01,0xfc,0x07,0xe8,0x01,0xf8,0x03,0xf8,0x03,0xe8,0x01,0xf8,0x07,0xf0,0x01,0x70,0x00,0xf8,0x3f,0xc0,0x03,0x80,0x1f};
{2,16,/*{w:16,h:16,bpp:1}*/0x00,0x00,0x00,0x00,0x04,0x20,0x05,0xA0,0x05,0xA0,0x25,0xA4,0xA7,0xE5,0xF7,0xEF,0xF7,0xEF,0xFE,0x7F,0xFC,0x3F,0xBC,0x3D,0xE4,0x27,0x20,0x00,0x00,0x00,0x00,0x00};
const byte enemy4_bitmap[] =
{2,16,/*{w:16,h:16,bpp:1,xform:"rotate(-90deg)"}*/0x06,0x00,0x0c,0x00,0x28,0x00,0x70,0x1f,0x84,0x3f,0xde,0x37,0xbb,0x3f,0xf0,0x3f,0xf0,0x3f,0xbb,0x3f,0xde,0x37,0x84,0x3f,0x70,0x1f,0x28,0x00,0x0c,0x00,0x06,0x00};
{2,16,/*{w:16,h:16,bpp:1}*/0x00,0x00,0x00,0x00,0xF0,0x0F,0xF8,0x1F,0xD8,0x1B,0xF8,0x1F,0xF8,0x1F,0xF8,0x1F,0xF0,0x0F,0xA8,0x15,0xCC,0x33,0xE8,0x17,0x66,0x66,0x33,0xCC,0x61,0x86,0x40,0x02};
const byte* const enemy_bitmaps[4] = {
enemy1_bitmap,
@ -273,12 +315,12 @@ void add_score(word pts) {
void xor_player_derez() {
byte i,j;
byte x = player_x+13;
byte y = 8;
byte y = 190;
byte* rand = (byte*) &clrscr; // use code as random #'s
for (j=1; j<=0x1f; j++) {
for (i=0; i<50; i++) {
signed char xx = x + (*rand++ & 0x1f) - 15;
signed char yy = y + (*rand++ & j);
signed char yy = y - (*rand++ & j);
xor_pixel(xx, yy);
if ((xx & 0x1f) > j) { CLICK; }
}
@ -287,7 +329,7 @@ void xor_player_derez() {
void destroy_player() {
xor_player_derez(); // xor derez pattern
xor_sprite(player_bitmap, player_x, 1); // erase ship via xor
xor_sprite(player_bitmap, player_x, 192-17); // erase ship via xor
xor_player_derez(); // xor 2x to erase derez pattern
player_x = 0xff;
lives--;
@ -296,7 +338,7 @@ void destroy_player() {
void init_enemies() {
byte i,x,y,bm;
x=0;
y=26;
y=10;
bm=0;
for (i=0; i<MAX_ENEMIES; i++) {
Enemy* e = &enemies[i];
@ -304,9 +346,9 @@ void init_enemies() {
e->y = y;
e->shape = enemy_bitmaps[bm];
x += 28;
if (x >= VHEIGHT-32) {
if (x >= 28*7) {
x = 0;
y -= 3;
y += 20;
bm++;
}
}
@ -335,8 +377,9 @@ void update_next_enemy() {
e = &enemies[enemy_index];
clear_sprite(e->shape, e->x, e->y);
if (this_mode.down) {
e->y += 4;
// if too close to ground, end game
if (--e->y < 5) {
if (e->y > 170) {
destroy_player();
lives = 0;
}
@ -344,7 +387,7 @@ void update_next_enemy() {
} else {
if (this_mode.right) {
e->x += 2;
if (e->x >= VHEIGHT-32) {
if (e->x >= 255-16) {
next_mode.down = 1;
next_mode.right = 0;
}
@ -361,13 +404,15 @@ void update_next_enemy() {
}
void draw_bunker(byte x, byte y, byte y2, byte h, byte w) {
byte i;
byte i,a,b;
for (i=0; i<h; i++) {
draw_vline(x+i, y+i, y+y2+i*2);
draw_vline(x+h*2+w-i-1, y+i, y+y2+i*2);
a = y-y2-i*2;
b = y-i;
draw_vline(x+i, a, b);
draw_vline(x+h*2+w-i-1, a, b);
}
for (i=0; i<w; i++) {
draw_vline(x+h+i, y+h, y+y2+h*2);
draw_vline(x+h+i, a, b);
}
}
@ -375,17 +420,18 @@ void draw_playfield() {
byte i;
clrscr();
draw_string("PLAYER 1", 0, VBWIDTH-1);
draw_string("USE A/Z/SPACE", 11, VBWIDTH-1);
draw_score(0);
draw_lives(0);
for (i=0; i<VHEIGHT; i++)
vidmem[i][0] = 0x7f & 0x55;
draw_bunker(20, 40, 15, 15, 20);
draw_bunker(125, 40, 15, 15, 20);
for (i=0; i<VBWIDTH-4; i++)
vidmem[191][i] = (i&1) ? 0x55 : 0x2a;
draw_bunker(20, 165, 15, 15, 20);
draw_bunker(160, 165, 15, 15, 20);
}
char in_rect(Enemy* e, byte x, byte y, byte w, byte h) {
byte eh = e->shape[0];
byte ew = e->shape[1];
byte ew = e->shape[0]*8;
byte eh = e->shape[1];
return (x >= e->x-w && x <= e->x+ew && y >= e->y-h && y <= e->y+eh);
}
@ -393,7 +439,7 @@ Enemy* find_enemy_at(byte x, byte y) {
byte i;
for (i=0; i<num_enemies; i++) {
Enemy* e = &enemies[i];
if (in_rect(e, x, y, 2, 0)) {
if (in_rect(e, x, y, 0, 2)) {
return e;
}
}
@ -410,18 +456,18 @@ void check_bullet_hit(byte x, byte y) {
void fire_bullet() {
bullet_x = player_x + 13;
bullet_y = 3;
bullet_y = 192-22;
xor_sprite(bullet_bitmap, bullet_x, bullet_y); // draw
}
void move_bullet() {
byte leftover = xor_sprite(bullet_bitmap, bullet_x, bullet_y); // erase
if (leftover || bullet_y > 26) {
if (leftover || bullet_y < 10) {
clear_sprite(bullet_bitmap, bullet_x, bullet_y);
check_bullet_hit(bullet_x, bullet_y+2);
bullet_y = 0;
} else {
bullet_y++;
bullet_y -= 4;
tone(bullet_y,3,0);
xor_sprite(bullet_bitmap, bullet_x, bullet_y); // draw
}
@ -430,23 +476,23 @@ void move_bullet() {
void drop_bomb() {
Enemy* e = &enemies[enemy_index];
bomb_x = e->x + 7;
bomb_y = e->y - 2;
bomb_y = e->y + 16;
xor_sprite(bomb_bitmap, bomb_x, bomb_y);
}
void move_bomb() {
byte leftover = xor_sprite(bomb_bitmap, bomb_x, bomb_y); // erase
if (bomb_y < 2) {
if (bomb_y < 192-10) {
bomb_y = 0;
} else if (leftover) {
erase_sprite(bomb_bitmap, bomb_x, bomb_y); // erase bunker
if (bomb_y < 3) {
if (bomb_y > 192-22) {
// player was hit (probably)
destroy_player();
}
bomb_y = 0;
} else {
bomb_y--;
bomb_y += 3;
xor_sprite(bomb_bitmap, bomb_x, bomb_y);
}
}
@ -457,16 +503,17 @@ signed char player_dir = 0;
void move_player() {
if (attract) {
if (bullet_y == 0) fire_bullet();
player_dir = 0;
} else {
char key;
// handle keyboard
if (kbhit()) {
key = cgetc();
switch (key) {
case 'A':
case 'Z':
player_dir = player_dir < 0 ? 0 : -2;
break;
case 'Z':
case 'X':
player_dir = player_dir > 0 ? 0 : 2;
break;
case ' ':
@ -476,13 +523,13 @@ void move_player() {
break;
}
}
// move player
if (player_dir < 0 && player_x > 0)
player_x += player_dir;
else if (player_dir > 0 && player_x < VHEIGHT-28)
player_x += player_dir;
}
draw_sprite(player_bitmap, player_x, 1);
// move player
if (player_dir < 0 && player_x > 0)
player_x += player_dir;
else if (player_dir > 0 && player_x < 255-28)
player_x += player_dir;
draw_sprite(player_bitmap, player_x, 192-17);
}
void play_round() {

View File

@ -504,6 +504,7 @@ function pixelEditorResize(e) {
function pixelEditorKeypress(e) {
if (!currentPixelEditor) return;
//console.log(e);
var c = e.charCode;
if (c >= 48 && c <= 57) {
currentPixelEditor.setCurrentColor(c-48);
@ -511,16 +512,16 @@ function pixelEditorKeypress(e) {
currentPixelEditor.setCurrentColor(c-97+10);
} else {
switch (e.keyCode) {
case 33: // PgUp
case 82: // 'R'
currentPixelEditor.rotate(-90);
break;
case 34: // PgDn
case 114: // 'r'
currentPixelEditor.rotate(90);
break;
case 35: // Home
case 84: // 'T'
currentPixelEditor.rotate(-45);
break;
case 36: // End
case 116: // 't'
currentPixelEditor.rotate(45);
break;
}

View File

@ -298,6 +298,7 @@ export class SourceEditor implements ProjectView {
if (e.data.close) {
$("#pixeditback").hide();
}
e.target.removeEventListener("message", handleWindowMessage);
}
$("#pixeditback").show();

View File

@ -11,7 +11,8 @@ parser.add_argument('-e', '--end', type=int, default=255, help="index of last ch
parser.add_argument('-H', '--height', type=int, default=8, help="character height")
parser.add_argument('-i', '--invert', action="store_true", help="invert bits")
parser.add_argument('-r', '--rotate', action="store_true", help="rotate bits")
parser.add_argument('-f', '--flip', action="store_true", help="flip bits (vertically")
parser.add_argument('-f', '--flip', action="store_true", help="flip bits (vertically)")
parser.add_argument('-m', '--mirror', action="store_true", help="mirror bits (horizontally)")
outfmtgroup = parser.add_mutually_exclusive_group()
outfmtgroup.add_argument("-A", "--asmhex", action="store_true", help="DASM-compatible hex")
outfmtgroup.add_argument("-B", "--asmdb", action="store_true", help="Z80ASM-compatible hex")
@ -27,6 +28,7 @@ hichar = args.end
invert = args.invert
flip = args.flip
rotate = args.rotate
mirror = args.mirror
chars = {}
inbitmap = 0
@ -54,6 +56,13 @@ with open(args.bdffile,'r') as f:
byte = int(toks[0],16)
bytes.append(byte)
def revbits(n):
r = 0
for i in range(0,8):
if (n & (1<<i)):
r |= (1<<(7-i))
return r
# output font table
x = 0
output = []
@ -66,6 +75,9 @@ for ch in range(lochar,hichar+1):
bytes = [0] * height
if flip:
bytes.reverse()
if mirror:
for i in range(0,height):
bytes[i] = revbits(bytes[i])
if rotate:
rotbytes = [0] * height
for x in range(0,height):