Skip to content

Commit

Permalink
Major improvements; bug fixes
Browse files Browse the repository at this point in the history
- Fixes to monochrome TRLE encoder
- Color builds now run on B&W Macs
- Added keyboard support
- Added headless mode
- Added menu bar
- Added about dialog box
  • Loading branch information
marciot committed Mar 10, 2022
1 parent ac103fd commit 9874088
Show file tree
Hide file tree
Showing 29 changed files with 1,118 additions and 1,037 deletions.
1 change: 0 additions & 1 deletion mac-cpp-source/ChainedTCPHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include "ChainedTCPHelper.h"


/* Opens the TCP driver and allocates a parameter block for
* subsequent calls.
*/
Expand Down
Binary file modified mac-cpp-source/MiniVNC.µ.bin
Binary file not shown.
Binary file modified mac-cpp-source/MiniVNC.µ.rsrc.bin
Binary file not shown.
54 changes: 12 additions & 42 deletions mac-cpp-source/VNCConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,23 @@
* location: <http://www.gnu.org/licenses/>. *
****************************************************************************/

#pragma once

/**
* Specify a compression level for the color TTRL encoder,
* from 0 to 4
*/

#define COMPRESSION_LEVEL 4
#define VNC_COMPRESSION_LEVEL 2

/**
* If the following is defined, MiniVNC will automatically
* start the server if it finds the application is in the
* "Startup Items" folder. It also will return to listening
* for connections after a client disconnects, allowing
* MiniVNC to be used in headless server mode.
*/
//#define VNC_HEADLESS_MODE

/**
* To build for a specific resolution, uncomment one of
Expand All @@ -42,45 +53,4 @@
//#define VNC_FB_16_COLORS
//#define VNC_FB_256_COLORS

// Derived values, don't change anything below this line

#if defined(VNC_FB_RES_512_342)
// Plus, SE, Classic, SE/30
#define VNC_FB_WIDTH 512
#define VNC_FB_HEIGHT 342
#define VNC_FB_MONOCHROME
#elif defined(VNC_FB_RES_512_384)
// Classic II, all others
#define VNC_FB_WIDTH 512
#define VNC_FB_HEIGHT 384

#elif defined(VNC_FB_RES_640_480)
// Mac II, LC, etc
#define VNC_FB_WIDTH 640
#define VNC_FB_HEIGHT 480

#elif defined(VNC_FB_RES_1024_768)
#define VNC_FB_WIDTH 1024
#define VNC_FB_HEIGHT 768
#endif

#if defined(VNC_FB_MONOCHROME)
#define VNC_FB_BITS_PER_PIX 1

#elif defined(VNC_FB_4_COLORS)
#define VNC_FB_BITS_PER_PIX 2

#elif defined(VNC_FB_16_COLORS)
#define VNC_FB_BITS_PER_PIX 4

#elif defined(VNC_FB_256_COLORS)
#define VNC_FB_BITS_PER_PIX 8
#endif

#define VNC_FB_PIX_PER_BYTE (8 / VNC_FB_BITS_PER_PIX)
#define VNC_FB_PALETTE_SIZE (1 << VNC_FB_BITS_PER_PIX)
#define BYTES_PER_TILE_ROW (2 * VNC_FB_BITS_PER_PIX)

#ifdef VNC_FB_WIDTH
#define VNC_BYTES_PER_LINE (VNC_FB_WIDTH / VNC_FB_PIX_PER_BYTE)
#endif
18 changes: 10 additions & 8 deletions mac-cpp-source/VNCEncodeTRLE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
****************************************************************************/
#include <string.h>

#include "VNCConfig.h"
#include "VNCServer.h"
#include "VNCFrameBuffer.h"
#include "VNCEncodeTRLE.h"

Expand All @@ -28,20 +28,22 @@
//#define USE_NATIVE_COLOR_TILES
//#define DEBUG_TILE_TYPES

#ifdef COMPRESSION_LEVEL
#if COMPRESSION_LEVEL == 0
#ifdef VNC_COMPRESSION_LEVEL
#if VNC_COMPRESSION_LEVEL == 0
#define USE_FAST_MONO_ENCODER
#define USE_NATIVE_COLOR_TILES
#elif COMPRESSION_LEVEL == 1
#elif VNC_COMPRESSION_LEVEL == 1
#define USE_FAST_MONO_ENCODER
#define USE_RLE_COLOR_TILES
#elif COMPRESSION_LEVEL == 2
#elif VNC_COMPRESSION_LEVEL == 2
#define USE_FAST_MONO_ENCODER
#define USE_RLE_COLOR_TILES
#define USE_NATIVE_COLOR_TILES
#elif COMPRESSION_LEVEL == 3
#elif VNC_COMPRESSION_LEVEL == 3
#define USE_RLE_COLOR_TILES
#define USE_NATIVE_COLOR_TILES
#define USE_2_COLOR_TILES
#elif COMPRESSION_LEVEL == 4
#elif VNC_COMPRESSION_LEVEL == 4
#define USE_RLE_COLOR_TILES
#define USE_NATIVE_COLOR_TILES
#define USE_2_COLOR_TILES
Expand Down Expand Up @@ -94,7 +96,7 @@ OSErr VNCEncoder::setup() {
#else
const unsigned long tilesPerRow = fbWidth / 16;
#endif
#ifdef USE_FAST_MONO_ENCODER
#if defined(VNC_FB_MONOCHROME) || defined(USE_FAST_MONO_ENCODER)
fbUpdateBuffer = (unsigned char*) NewPtr(tilesPerRow * PLAIN_PACKED_TILE_SIZE(1));
#else
fbUpdateBuffer = (unsigned char*) NewPtr(UPDATE_BUFFER_SIZE);
Expand Down
94 changes: 89 additions & 5 deletions mac-cpp-source/VNCEncodeTRLEMono.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
****************************************************************************/
#include <string.h>

#include "VNCConfig.h"
#include "VNCServer.h"
#include "VNCFrameBuffer.h"
#include "VNCEncodeTRLE.h"

#define DEBUG_SOLID_TILE 0 // Set to one to show solid tiles
#define USE_ENCODER 0 // 0: Assembly; 1: Hybrid; 2: C++

#define min(A,B) ((A) < (B) ? (A) : (B))

extern int tile_y;
extern unsigned char lastPaletteSize;
Expand Down Expand Up @@ -161,18 +164,19 @@ static asm unsigned short _encodeTile(const unsigned char *src:__A0, unsigned ch
#define GET_CHUNK VNCEncoder::getChunk
#else
#define GET_CHUNK getChunkMonochrome
#endif

#if USE_ENCODER == 0
asm Boolean getChunkMonochrome(int x, int y, int w, int h, wdsEntry *wdsPtr);
#endif

#if 1
asm Boolean GET_CHUNK(int x, int y, int w, int h, wdsEntry *wdsPtr) {
#define xArg 8(a6)
#define yArg 10(a6)
#define wArg 12(a6)
#define hArg 14(a6)
#define wdsArg 16(a6)

#define tmp d1
#define tiles d3
#define rows d4

Expand All @@ -194,6 +198,7 @@ static asm unsigned short _encodeTile(const unsigned char *src:__A0, unsigned ch
add.w tile_y,tmp
#if VNC_FB_WIDTH == 512
lsl.w #6,tmp
ext.l tmp
#else
#if !defined(VNC_FB_BITS_PER_PIX)
mulu fbStride,tmp
Expand All @@ -205,7 +210,8 @@ static asm unsigned short _encodeTile(const unsigned char *src:__A0, unsigned ch
// Add x/8
move.w xArg,tmp
lsr.w #3,tmp
adda.w tmp,src
ext.l tmp
adda.l tmp,src

// Compute tiles:
// tiles = w/16
Expand Down Expand Up @@ -248,8 +254,22 @@ static asm unsigned short _encodeTile(const unsigned char *src:__A0, unsigned ch
movem.l (a7)+,d3-d4/a2-a4 // Save registers
unlk a6
rts

#undef xArg
#undef yArg
#undef wArg
#undef hArg
#undef wdsArg

#undef tmp
#undef tiles
#undef rows

#undef src
#undef dst
#undef wds
}
#else
#elif USE_ENCODER == 1
/**
* With "src" pointing to the first byte of a 16x16 tile on the screen, this function will write
* "rows" as a two-color or solid tile and return the number of bytes written.
Expand All @@ -263,6 +283,8 @@ static asm unsigned short _encodeTile(const unsigned char *src:__A0, unsigned ch
rts
}

Boolean GET_CHUNK(int x, int y, int w, int h, wdsEntry *wds);

Boolean GET_CHUNK(int x, int y, int w, int h, wdsEntry *wds) {
const char rows = min(16, h - tile_y);
unsigned char *dst = fbUpdateBuffer;
Expand All @@ -279,6 +301,68 @@ static asm unsigned short _encodeTile(const unsigned char *src:__A0, unsigned ch
// Prepare for the next row
tile_y += 16;

return tile_y < h;
}
#else
// C++ Reference Encoder

#define TILE_LINE(ROW) if(rows == ROW) goto done; \
*dst++ = src[0 + ROW * VNC_BYTES_PER_LINE]; \
*dst++ = src[1 + ROW * VNC_BYTES_PER_LINE];

unsigned short encodeTile(const unsigned char *src, unsigned char *dst, unsigned short rows);

unsigned short encodeTile(const unsigned char *src, unsigned char *dst, unsigned short rows) {
unsigned char *start = dst;

if(tile_y && dst != fbUpdateBuffer) {
// Packed pallete type with pallete reused from previous tile
*dst++ = 127;
} else {
// Packed pallete type with palleteSize = 2
*dst++ = 2; // Packed pallete type
*dst++ = 0; // Black CPIXEL
*dst++ = 1; // White CPIXEL
}

// Encode the packed data for a 16x16 tile
TILE_LINE(0);
TILE_LINE(1);
TILE_LINE(2);
TILE_LINE(3);
TILE_LINE(4);
TILE_LINE(5);
TILE_LINE(6);
TILE_LINE(7);
TILE_LINE(8);
TILE_LINE(9);
TILE_LINE(10);
TILE_LINE(11);
TILE_LINE(12);
TILE_LINE(13);
TILE_LINE(14);
TILE_LINE(15);
done:

return dst - start;
}

Boolean VNCEncoder::getChunk(int x, int y, int w, int h, wdsEntry *wds) {
const char rows = min(16, h - tile_y);
unsigned char *dst = fbUpdateBuffer;
unsigned char *src = VNCFrameBuffer::getPixelAddr(x, y + tile_y);
unsigned char tiles = w/16;
while(tiles--) {
dst += encodeTile(src, dst, rows);
src += 2;
}

wds->length = dst - fbUpdateBuffer;
wds->ptr = (Ptr) fbUpdateBuffer;

// Prepare for the next row
tile_y += 16;

return tile_y < h;
}
#endif
Loading

0 comments on commit 9874088

Please sign in to comment.