38 static Uint16 lpt_a, lpt_set, ld1, ld2;
39 static int slot, visible, scanlines, max_scanlines;
41 static Uint32 *
pixels, *pixels_init, *pixels_limit_up, *pixels_limit_bottom, *pixels_limit_vsync_shortest, *pixels_limit_vsync_long_force;
42 static int pixels_gap;
47 static Uint8 nick_last_byte;
48 static int reload, vres;
49 static int all_rasters;
56 static int chs, msbalt, lsbalt;
57 static Uint8 balt_mask, chm, chb, altind;
61 #define RASTER_FIRST_VISIBLE 25
62 #define RASTER_LAST_VISIBLE 312
63 #define RASTER_NO_VSYNC_BEFORE 300
64 #define RASTER_FORCE_VSYNC 326
67 static int nick_addressing_init (
Uint32 *pixels_buffer,
int line_size )
69 if (line_size < 736) {
70 ERROR_WINDOW(
"NICK: SDL: FATAL ERROR: target SDL surface has width (or pitch?) smaller than 736 pixels [%d]!", line_size);
74 ERROR_WINDOW(
"NICK: SDL: FATAL ERROR: line size bytes not 4 bytes aligned!");
79 pixels_limit_up = pixels_buffer;
94 ERROR_WINDOW(
"Cannot allocate memory for screen buffer.");
100 for (a = 0; a < 256; a++) {
103 r = (((a << 2) & 4) | ((a >> 2) & 2) | ((a >> 6) & 1)) * 255 / 7;
104 g = (((a << 1) & 4) | ((a >> 3) & 2) | ((a >> 7) & 1)) * 255 / 7;
105 b = ( ((a >> 1) & 2) | ((a >> 5) & 1)) * 255 / 3;
110 col4trans[a * 4 + 0] = ((a >> 2) & 2) | ((a >> 7) & 1);
111 col4trans[a * 4 + 1] = ((a >> 1) & 2) | ((a >> 6) & 1);
112 col4trans[a * 4 + 2] = ((a ) & 2) | ((a >> 5) & 1);
113 col4trans[a * 4 + 3] = ((a << 1) & 2) | ((a >> 4) & 1);
115 col16trans[a * 2 + 0] = ((a << 2) & 8) | ((a >> 3) & 4) | ((a >> 2) & 2) | ((a >> 7) & 1);
116 col16trans[a * 2 + 1] = ((a << 3) & 8) | ((a >> 2) & 4) | ((a >> 1) & 2) | ((a >> 6) & 1);
123 nick_last_byte = 0xFF;
131 DEBUG(
"NICK: initialized." NL);
139 return nick_last_byte;
146 border = full_palette[bcol];
157 for (a = 0; a < 8; a++)
158 palette_bias[a] = full_palette[
value++];
165 lpt_set = (lpt_set & 0xF000) | (
value << 4);
173 lpt_set = (lpt_set & 0x0FF0) | ((
value & 0xF) << 12);
174 DEBUG(
"NICK: LPT is set to %04Xh" NL, lpt_set);
175 if (!(
value & 128)) {
181 lpt_clk =
value & 64;
185 #define NICK_READ(a) (nick_last_byte = vram[a])
192 for(a = 0; a < 16; a++)
200 static inline void TODO(
void) {
201 FILL(full_palette[1]);
202 DEBUG(
"NO VM = %d CM = %d" NL, vm, cm);
207 static void _render_border (
void )
214 static void _render_pixel_2 (
void )
221 for (j = 0; j < 2; j ++) {
224 if (msbalt && (
data & 128)) {
229 if (lsbalt && (
data & 1)) {
233 for (a = 128; a; a >>= 1) {
234 *(
pixels++) = palette[(
data & a ? 1 : 0) | ps];
242 static void _render_lpixel_2 (
void )
250 if (msbalt && (
data & 128)) {
255 if (lsbalt && (
data & 1)) {
259 for (a = 128; a; a >>= 1) {
267 static void _render_pixel_256 (
void )
275 for (a = 0; a < 8; a++)
278 for (a = 0; a < 8; a++)
282 static void _render_lpixel_256 (
void )
290 for (a = 0; a < 16; a++)
297 static void _render_vsync(
void)
299 FILL(full_palette[4]);
304 static Uint8 _altind_modes[] = {
312 static void _render_char_2 (
void )
318 Uint32 c1 = _altind_modes[(altind &
data) >> 6];
335 static void _render_char_4 (
void )
342 col[0] = _altind_modes[(altind &
data) >> 6];
357 static void _render_invalid (
void )
359 FILL(full_palette[3]);
363 static void _render_attrib_2 (
void )
386 static void _render_pixel_4 (
void )
396 trans = col4trans + (
NICK_READ(ld1++) << 2);
405 static void _render_lpixel_4 (
void )
420 static void _render_pixel_16 (
void )
428 trans = col16trans + (
NICK_READ(ld1++) << 1);
435 static void _render_lpixel_16 (
void )
449 static void _render_char_16 (
void ) { TODO(); }
450 static void _render_char_256 (
void ) { TODO(); }
456 static void (*_render)(void);
457 static void (*render_modes[])(void) = {
493 static const int chb_for_modes[] = { 0, 0, 0, 8, 7, 6, 0, 0 };
505 static int frames = 0;
508 static inline void _update (
void )
520 static const char *_vm_names[] = {
"vsync",
"pixel",
"attrib",
"ch256",
"ch128",
"ch64",
"invalid",
"lpixel"};
521 static const char *_cm_names[] = {
"2c",
"4c",
"16c",
"256c"};
532 snprintf(buffer,
sizeof buffer,
"%04X SC=%3d VINT=%d CM=%d VRES=%d VM=%d RELOAD=%d LM=%2d RM=%2d LD1=%04X LD2=%04X %s/%s%s",
536 (vram[a + 1] >> 5) & 3,
537 (vram[a + 1] >> 4) & 1,
538 (vram[a + 1] >> 1) & 7,
542 vram[a + 4] | (vram[a + 5] << 8),
543 vram[a + 6] | (vram[a + 7] << 8),
544 _vm_names[(vram[a + 1] >> 1) & 7],
545 _cm_names[(vram[a + 1] >> 5) & 3],
548 p = realloc(p, p ? strlen(p) + strlen(buffer) + 256 : strlen(buffer) + 256);
553 scs += 256 - vram[a];
554 if (vram[a + 1] & 1) {
555 sprintf(buffer,
"Total scanlines = %d%s", scs, newline_seq);
559 a = (a + 16) & 0xFFFF;
560 }
while (a != lpt_set);
561 sprintf(buffer,
"ERROR: LPT is endless!%s", newline_seq);
577 if (scanlines >= max_scanlines) {
589 max_scanlines = 256 -
NICK_READ(lpt_a++);
599 if (
pixels >= pixels_limit_vsync_shortest)
604 if (
pixels >= pixels_limit_vsync_long_force)
608 FATAL(
"FATAL ERROR: NICK: render funcarray bound check failure!");
609 _render = render_modes[vm | ((a >> 2) & 0x18)];
616 balt_mask = lsbalt ? 0xFE : 0xFF;
617 if (msbalt) balt_mask &= 0x7F;
622 altind = ((a & 128) >> 1) | ((a & 64) << 1);
627 if ((!scanlines) || (!vres))
634 chb = chb_for_modes[vm];
669 case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
case 19:
case 20:
case 21:
case 22:
case 23:
case 24:
case 25:
case 26:
case 27:
case 28:
670 case 29:
case 30:
case 31:
case 32:
case 33:
case 34:
case 35:
case 36:
case 37:
case 38:
case 39:
case 40:
case 41:
case 42:
case 43:
case 44:
case 45:
case 46:
case 47:
case 48:
case 49:
671 case 50:
case 51:
case 52:
case 53:
673 if (slot < lm || slot >= rm) {
682 FATAL(
"NICK: FATAL ERROR: invalid slot number for rendering: %d", slot);