diff --git a/presets/apple2/cosmic.c b/presets/apple2/cosmic.c index 6472ba0e..2300ab9b 100644 --- a/presets/apple2/cosmic.c +++ b/presets/apple2/cosmic.c @@ -1,4 +1,4 @@ - + #include #include #include @@ -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> (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 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; iy = 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; ishape[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 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() { diff --git a/src/pixed/pixeleditor.ts b/src/pixed/pixeleditor.ts index 022d9ea8..147f0f71 100644 --- a/src/pixed/pixeleditor.ts +++ b/src/pixed/pixeleditor.ts @@ -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; } diff --git a/src/views.ts b/src/views.ts index 602c4bc6..0127f221 100644 --- a/src/views.ts +++ b/src/views.ts @@ -298,6 +298,7 @@ export class SourceEditor implements ProjectView { if (e.data.close) { $("#pixeditback").hide(); } + e.target.removeEventListener("message", handleWindowMessage); } $("#pixeditback").show(); diff --git a/tools/parsebdf8.py b/tools/parsebdf8.py index 3c5a94c3..f517e3bf 100755 --- a/tools/parsebdf8.py +++ b/tools/parsebdf8.py @@ -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<