123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650 |
- {$MACRO ON}
- {$DEFINE DEFAULT_WIDTH:=320}
- {$DEFINE DEFAULT_HEIGHT:=200}
- {$DEFINE DEFAULT_FORMAT:=TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF)}
- Constructor TextFX2Console.Create;
- Var
- I : Integer;
- Begin
- m_160x100buffer := Nil;
- m_primary := Nil;
- m_keyboard := Nil;
- m_copy := Nil;
- m_default_format := Nil;
- m_open := False;
- m_locked := False;
- FillChar(m_modes, SizeOf(m_modes), 0);
- m_title[0] := #0;
- m_information[0] := #0;
- m_default_width := DEFAULT_WIDTH;
- m_default_height := DEFAULT_HEIGHT;
- m_default_format := DEFAULT_FORMAT;
- For I := Low(m_modes) To High(m_modes) Do
- m_modes[I] := TPTCMode.Create;
- calcpal := @calcpal_colorbase;
- use_charset := @charset_b7asc;
- build_colormap(0);
- m_copy := TPTCCopy.Create;
- configure('ptc.cfg');
- End;
- Destructor TextFX2Console.Destroy;
- Var
- I : Integer;
- Begin
- close;
- If m_160x100buffer <> Nil Then
- m_160x100buffer.Destroy;
- If m_primary <> Nil Then
- m_primary.Destroy;
- For I := Low(m_modes) To High(m_modes) Do
- If m_modes[I] <> Nil Then
- m_modes[I].Destroy;
- If m_keyboard <> Nil Then
- m_keyboard.Destroy;
- If m_copy <> Nil Then
- m_copy.Destroy;
- If m_default_format <> Nil Then
- m_default_format.Destroy;
- dispose_colormap;
- Inherited Destroy;
- End;
- Procedure TextFX2Console.configure(Const _file : String);
- Var
- F : Text;
- S : String;
- Begin
- ASSign(F, _file);
- Try
- Reset(F);
- Except
- Exit;
- End;
- Try
- While Not EoF(F) Do
- Begin
- Readln(F, S);
- option(S);
- End;
- Finally
- CloseFile(F);
- End;
- End;
- Function TextFX2Console.option(Const _option : String) : Boolean;
- Begin
- {...}
- option := True;
- If _option = 'charset_b8ibm' Then
- Begin
- use_charset := @charset_b8ibm;
- Exit;
- End;
- If _option = 'charset_b7asc' Then
- Begin
- use_charset := @charset_b7asc;
- Exit;
- End;
- If _option = 'charset_b7sml' Then
- Begin
- use_charset := @charset_b7sml;
- Exit;
- End;
- If _option = 'charset_b8gry' Then
- Begin
- use_charset := @charset_b8gry;
- Exit;
- End;
- If _option = 'charset_b7nws' Then
- Begin
- use_charset := @charset_b7nws;
- Exit;
- End;
- If _option = 'calcpal_colorbase' Then
- Begin
- calcpal := @calcpal_colorbase;
- build_colormap(0);
- Exit;
- End;
- If _option = 'calcpal_lightbase' Then
- Begin
- calcpal := @calcpal_lightbase;
- build_colormap(0);
- Exit;
- End;
- If _option = 'calcpal_lightbase_g' Then
- Begin
- calcpal := @calcpal_lightbase_g;
- build_colormap(0);
- Exit;
- End;
- option := m_copy.option(_option);
- End;
- Function TextFX2Console.modes : PPTCMode;
- Begin
- {todo...}
- modes := @m_modes;
- End;
- Procedure TextFX2Console.open(Const _title : String; _pages : Integer); Overload;
- Begin
- open(_title, m_default_format, _pages);
- End;
- Procedure TextFX2Console.open(Const _title : String; Const _format : TPTCFormat;
- _pages : Integer); Overload;
- Begin
- open(_title, m_default_width, m_default_height, _format, _pages);
- End;
- Procedure TextFX2Console.open(Const _title : String; _width, _height : Integer;
- Const _format : TPTCFormat; _pages : Integer); Overload;
- Var
- m : TPTCMode;
- Begin
- m := TPTCMode.Create(_width, _height, _format);
- open(_title, m, _pages);
- m.Destroy;
- End;
- Procedure TextFX2Console.open(Const _title : String; Const _mode : TPTCMode;
- _pages : Integer); Overload;
- Var
- _width, _height : Integer;
- _format : TPTCFormat;
- Begin
- If Not _mode.valid Then
- Raise TPTCError.Create('invalid mode');
- _width := _mode.width;
- _height := _mode.height;
- _format := _mode.format;
- internal_pre_open_setup(_title);
- internal_open_fullscreen_start;
- internal_open_fullscreen(_width, _height, _format);
- internal_open_fullscreen_finish(_pages);
- internal_post_open_setup;
- End;
- Procedure TextFX2Console.close;
- Begin
- If m_open Then
- Begin
- If m_locked Then
- Raise TPTCError.Create('console is still locked');
- {flush all key presses}
- While KeyPressed Do ReadKey;
- internal_close;
- m_open := False;
- End;
- End;
- Procedure TextFX2Console.flush;
- Begin
- check_open;
- check_unlocked;
- End;
- Procedure TextFX2Console.finish;
- Begin
- check_open;
- check_unlocked;
- End;
- Procedure TextFX2Console.update;
- Var
- framebuffer : PInteger;
- Begin
- check_open;
- check_unlocked;
- { m_primary.clear;}
- m_primary.copy(m_160x100buffer);
- framebuffer := m_160x100buffer.lock;
- vrc;
- dump_160x(0, 50, framebuffer);
- m_160x100buffer.unlock;
- End;
- Procedure TextFX2Console.update(Const _area : TPTCArea);
- Begin
- update;
- End;
- Procedure TextFX2Console.internal_ReadKey(k : TPTCKey);
- Begin
- check_open;
- m_keyboard.internal_ReadKey(k);
- End;
- Function TextFX2Console.internal_PeekKey(k : TPTCKey) : Boolean;
- Begin
- check_open;
- Result := m_keyboard.internal_PeekKey(k);
- End;
- Procedure TextFX2Console.copy(Var surface : TPTCBaseSurface);
- Var
- pixels : Pointer;
- Begin
- check_open;
- check_unlocked;
- pixels := lock;
- Try
- surface.load(pixels, width, height, pitch, format, palette);
- unlock;
- Except
- On error : TPTCError Do
- Begin
- unlock;
- Raise TPTCError.Create('failed to copy console to surface', error);
- End;
- End;
- End;
- Procedure TextFX2Console.copy(Var surface : TPTCBaseSurface;
- Const source, destination : TPTCArea);
- Begin
- End;
- Function TextFX2Console.lock : Pointer;
- Var
- pixels : Pointer;
- Begin
- check_open;
- If m_locked Then
- Raise TPTCError.Create('console is already locked');
- pixels := m_primary.lock;
- m_locked := True;
- lock := pixels;
- End;
- Procedure TextFX2Console.unlock;
- Begin
- check_open;
- If Not m_locked Then
- Raise TPTCError.Create('console is not locked');
- m_primary.unlock;
- m_locked := False;
- End;
- Procedure TextFX2Console.load(Const pixels : Pointer;
- _width, _height, _pitch : Integer;
- Const _format : TPTCFormat;
- Const _palette : TPTCPalette);
- Var
- Area_ : TPTCArea;
- console_pixels : Pointer;
- c, a : TPTCArea;
- Begin
- c := clip; a := area;
- If (c.left = a.left) And
- (c.top = a.top) And
- (c.right = a.right) And
- (c.bottom = a.bottom) Then
- Begin
- check_open;
- check_unlocked;
- console_pixels := lock;
- Try
- m_copy.request(_format, format);
- m_copy.palette(_palette, palette);
- m_copy.copy(pixels, 0, 0, _width, _height, _pitch, console_pixels, 0, 0,
- width, height, pitch);
- unlock;
- Except
- On error : TPTCError Do
- Begin
- unlock;
- Raise TPTCError.Create('failed to load pixels to console', error);
- End;
- End;
- End
- Else
- Begin
- Area_ := TPTCArea.Create(0, 0, width, height);
- load(pixels, _width, _height, _pitch, _format, _palette, Area_, area);
- Area_.Destroy;
- End;
- End;
- Procedure TextFX2Console.load(Const pixels : Pointer;
- _width, _height, _pitch : Integer;
- Const _format : TPTCFormat;
- Const _palette : TPTCPalette;
- Const source, destination : TPTCArea);
- Var
- console_pixels : Pointer;
- clipped_source, clipped_destination : TPTCArea;
- tmp : TPTCArea;
- Begin
- check_open;
- check_unlocked;
- console_pixels := lock;
- clipped_source := TPTCArea.Create;
- clipped_destination := TPTCArea.Create;
- Try
- tmp := TPTCArea.Create(0, 0, _width, _height);
- TPTCClipper.clip(source, tmp, clipped_source, destination, clip, clipped_destination);
- tmp.Destroy;
- m_copy.request(_format, format);
- m_copy.palette(_palette, palette);
- m_copy.copy(pixels, clipped_source.left, clipped_source.top, clipped_source.width, clipped_source.height, _pitch,
- console_pixels, clipped_destination.left, clipped_destination.top, clipped_destination.width, clipped_destination.height, pitch);
- unlock;
- Except
- On error:TPTCError Do
- Begin
- clipped_source.Destroy;
- clipped_destination.Destroy;
- unlock;
- Raise TPTCError.Create('failed to load pixels to console area', error);
- End;
- End;
- clipped_source.Destroy;
- clipped_destination.Destroy;
- End;
- Procedure TextFX2Console.save(pixels : Pointer;
- _width, _height, _pitch : Integer;
- Const _format : TPTCFormat;
- Const _palette : TPTCPalette);
- Var
- Area_ : TPTCArea;
- console_pixels : Pointer;
- c, a : TPTCArea;
- Begin
- c := clip; a := area;
- If (c.left = a.left) And
- (c.top = a.top) And
- (c.right = a.right) And
- (c.bottom = a.bottom) Then
- Begin
- check_open;
- check_unlocked;
- console_pixels := lock;
- Try
- m_copy.request(format, _format);
- m_copy.palette(palette, _palette);
- m_copy.copy(console_pixels, 0, 0, width, height, pitch, pixels, 0, 0,
- _width, _height, _pitch);
- unlock;
- Except
- On error : TPTCError Do
- Begin
- unlock;
- Raise TPTCError.Create('failed to save console pixels', error);
- End;
- End;
- End
- Else
- Begin
- Area_ := TPTCArea.Create(0, 0, width, height);
- save(pixels, _width, _height, _pitch, _format, _palette, area, Area_);
- Area_.Destroy;
- End;
- End;
- Procedure TextFX2Console.save(pixels : Pointer;
- _width, _height, _pitch : Integer;
- Const _format : TPTCFormat;
- Const _palette : TPTCPalette;
- Const source, destination : TPTCArea);
- Var
- console_pixels : Pointer;
- clipped_source, clipped_destination : TPTCArea;
- tmp : TPTCArea;
- Begin
- check_open;
- check_unlocked;
- console_pixels := lock;
- clipped_source := TPTCArea.Create;
- clipped_destination := TPTCArea.Create;
- Try
- tmp := TPTCArea.Create(0, 0, _width, _height);
- TPTCClipper.clip(source, clip, clipped_source, destination, tmp, clipped_destination);
- tmp.Destroy;
- m_copy.request(format, _format);
- m_copy.palette(palette, _palette);
- m_copy.copy(console_pixels, clipped_source.left, clipped_source.top, clipped_source.width, clipped_source.height, pitch,
- pixels, clipped_destination.left, clipped_destination.top, clipped_destination.width, clipped_destination.height, _pitch);
- unlock;
- Except
- On error:TPTCError Do
- Begin
- clipped_source.Destroy;
- clipped_destination.Destroy;
- unlock;
- Raise TPTCError.Create('failed to save console area pixels', error);
- End;
- End;
- clipped_source.Destroy;
- clipped_destination.Destroy;
- End;
- Procedure TextFX2Console.clear;
- Begin
- End;
- Procedure TextFX2Console.clear(Const color : TPTCColor);
- Begin
- End;
- Procedure TextFX2Console.clear(Const color : TPTCColor;
- Const _area : TPTCArea);
- Begin
- End;
- Procedure TextFX2Console.palette(Const _palette : TPTCPalette);
- Begin
- check_open;
- m_primary.palette(_palette);
- End;
- Function TextFX2Console.palette : TPTCPalette;
- Begin
- check_open;
- palette := m_primary.palette;
- End;
- Procedure TextFX2Console.clip(Const _area : TPTCArea);
- Begin
- check_open;
- m_primary.clip(_area);
- End;
- Function TextFX2Console.width : Integer;
- Begin
- check_open;
- width := m_primary.width;
- End;
- Function TextFX2Console.height : Integer;
- Begin
- check_open;
- height := m_primary.height;
- End;
- Function TextFX2Console.pitch : Integer;
- Begin
- check_open;
- pitch := m_primary.pitch;
- End;
- Function TextFX2Console.pages : Integer;
- Begin
- check_open;
- pages := 2;{m_primary.pages;}
- End;
- Function TextFX2Console.area : TPTCArea;
- Begin
- check_open;
- area := m_primary.area;
- End;
- Function TextFX2Console.clip : TPTCArea;
- Begin
- check_open;
- clip := m_primary.clip;
- End;
- Function TextFX2Console.format : TPTCFormat;
- Begin
- check_open;
- format := m_primary.format;
- End;
- Function TextFX2Console.name : String;
- Begin
- End;
- Function TextFX2Console.title : String;
- Begin
- End;
- Function TextFX2Console.information : String;
- Begin
- End;
- Procedure TextFX2Console.internal_pre_open_setup(Const _title : String);
- Begin
- End;
- Procedure TextFX2Console.internal_open_fullscreen_start;
- Var
- f : TPTCFormat;
- Begin
- f := TPTCFormat.Create(32, $0000FF, $00FF00, $FF0000);
- m_160x100buffer := TPTCSurface.Create(160, 100, f);
- f.Destroy;
- set80x50;
- End;
- Procedure TextFX2Console.internal_open_fullscreen(_width, _height : Integer; Const _format : TPTCFormat);
- Begin
- m_primary := TPTCSurface.Create(_width, _height, _format);
- End;
- Procedure TextFX2Console.internal_open_fullscreen_finish(_pages : Integer);
- Begin
- End;
- Procedure TextFX2Console.internal_post_open_setup;
- Begin
- If m_keyboard <> Nil Then
- m_keyboard.Destroy;
- m_keyboard := TDosKeyboard.Create;
- { create win32 keyboard
- m_keyboard = new DosKeyboard();//m_window->handle(),m_window->thread(),false);}
- { temporary platform dependent information fudge }
- {sprintf(m_information,"dos version x.xx.x\nvesa version x.xx\nvesa driver name xxxxx\ndisplay driver vendor xxxxx\ncertified driver? x\n");}
- { set open flag }
- m_open := True;
- End;
- Procedure TextFX2Console.internal_reset;
- Begin
- If m_primary <> Nil Then
- m_primary.Destroy;
- { m_keyboard.Destroy;}
- m_primary := Nil;
- { m_keyboard := Nil;}
- End;
- Procedure TextFX2Console.internal_close;
- Begin
- If m_primary <> Nil Then
- m_primary.Destroy;
- m_primary := Nil;
- If m_160x100buffer <> Nil Then
- m_160x100buffer.Destroy;
- m_160x100buffer := Nil;
- set80x25;
- { m_keyboard.Destroy;
- m_keyboard := Nil;}
- End;
- Procedure TextFX2Console.check_open;
- Begin
- {$IFDEF DEBUG}
- If Not m_open Then
- Raise TPTCError.Create('console is not open');
- {$ENDIF}
- End;
- Procedure TextFX2Console.check_unlocked;
- Begin
- {$IFDEF DEBUG}
- If m_locked Then
- Raise TPTCError.Create('console is not unlocked');
- {$ENDIF}
- End;
|