-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrwxgf.pas
1679 lines (1436 loc) · 46.4 KB
/
rwxgf.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//{$MODE TP}
{$mode objfpc}{$H+}
{$PACKRECORDS 1}
Unit rwxgf;
Interface
uses SysUtils,LazFileUtils,rmcore,rmthumb,rmxgfcore,bits,gwbasic;
Const
NoLan = 0;
TPLan = 1;
TCLan = 2;
QCLan = 3;
QBLan = 4;
QB64Lan = 5;
PBLan = 6;
GWLan = 7; // also update GWLan in gbasic unit
FPLan = 8;
FBinQBModeLan = 9;
FBLan = 10; //modern mode - no legacy support for RGB/RGBA
ABLan = 11; //AmigaBasic
APLan = 12;
ACLan = 13;
AQBLan = 14; //Amiga APQBasic support - once we figure out how to access t_BitMap memory and stuff it with bitplane data
QPLan = 15; //Quick Pascal
gccLan = 16;
OWLan = 17; //Open Watcom C/C++ compiler
BAMLan = 18; //Basic Anywhere Machine
TMTLan = 19; // TMT Pascal Compiler - 32bit DOS
QBJSLan = 20; // QB to JS transpiler
JsonLan = 21; //for sprite sheet description
NoExportFormat = 0;
PutImageExportFormat = 1; //for all compilers the use put/putimage
AmigaBOBExportFormat = 2; //Amiga specific formats
AmigaVSpriteExportFormat = 3;
AmigaBitMap = 4; //for Amiga C/Pascal
XLibLBMExportFormat = 5; //Xlib format for TC/TP
XLibPBMExportFormat = 6;
RGBAFuchsiaExportFormat = 7;
RGBAIndex0ExportFormat = 8;
RGBExportFormat = 9;
MouseImageExportFormat = 10;
RayLibRGBAFuchsiaExportFormat = 11;
RayLibRGBAIndex0ExportFormat = 12;
RayLibRGBExportFormat = 13;
RGBACustomExportFormat = 14;
RayLibRGBACustomExportFormat = 15;
Binary2 = 1;
Binary4 = 2;
Binary8 = 3;
Binary16 = 4;
Binary32 = 5;
Binary256 = 6;
Source2 = 7;
Source4 = 8;
Source8 = 9;
Source16 = 10;
Source32 = 11;
Source256 = 12;
SPRBinary = 13;
SPRSource = 14;
PPRBinary = 15;
PPRSource = 16;
TEGLText = 17;
PALSource = 18;
type
BufferRec = Record
f : file;
fText : Text;
Error : word;
buflist : array[1..128] of Byte;
bufcount : integer;
ArraySize : longword;
ByteWriteCount : longword;
end;
//Action 0 = init ncounter/buffer,Action 1 = write byte to buffer, action 2= flush buffer
BitPlaneWriterProc = Procedure(inByte : Byte; var Buffer : BufferRec; action : integer);
Function WriteXgfToCode(x,y,x2,y2,LanType : word;filename:string):word;
Function WriteXgfToCodeEx(x,y,x2,y2,LanType, ExportFormat : word;filename:string):word;
Function WriteXgfWithMaskToCode(x,y,x2,y2,LanType : word;filename:string):word;
Function WriteXgfToFile(x,y,x2,y2,LanType : word;filename:string):word;
procedure WriteXgfToBuffer(x,y,x2,y2,LanType,Mask : word;var data : BufferRec); // to binary file
procedure WriteXgfToBufferFP(x,y,x2,y2,Mask : word;var data : BufferRec);
procedure WriteXgfToBufferFB(x,y,x2,y2,Mask : word;var data : BufferRec);
procedure WriteXgfToBufferOW(x,y,x2,y2,Mask : word;var data : BufferRec);
function WriteXGFCodeToBuffer(var data : BufferRec;x,y,x2,y2,LanType,Mask : word; imagename:string):word;
function WriteRGBXGFCodeToBuffer(var data : BufferRec;x,y,x2,y2,LanType,Mask : word; imagename:string):word;
function GetXImageSize(width,height,ncolors : integer) : longint;
function GetXImageSizeFB(width,height : integer) : longint;
function GetXImageSizeFP(width,height : integer) : longint;
function GetXImageSizeOW(width,height,ncolors : integer) : longint;
function GetXImageSizeBAM(width,height,ncolors : integer) : longint;
function GetRGBXImageSizeBAM(width,height : integer) : longint;
function GetXImageSizeTMT(width,height,ncolors : integer) : longint;
procedure BitplaneWriterFile(inByte : Byte; var Buffer : BufferRec;action : integer);
procedure BitplaneWriterPascalCode(inByte : Byte; var Buffer : BufferRec;action : integer);
procedure BitplaneWriterCCode(inByte : Byte; var Buffer : BufferRec;action : integer);
procedure BitplaneWriterBasicCode(inByte : Byte; var Buffer : BufferRec;action : integer);
procedure BitplaneWriterGWBasicCode(inByte : Byte; var Buffer : BufferRec;action : integer);
Implementation
type
linebuftype = array[0..2047] of byte;
ColorMap = Array[0..15] of Byte;
XgfHead = Packed Record
Width : Word;
Height : Word;
End;
//Open Watcom XGF header - slightly different than borland/MS
XgfHeadOW = Packed Record
Width : Word;
Height : Word;
Colors : Word; // 1 = Monochrome, 2 = 4 color/GGA modes, 4 = 16 color modes, 8 = 256 color modes
End;
//free pascal graph - each pixel takes a Word
XGFHeadFP = Packed Record
Width,Height : LongInt;
reserved : LongInt;
end;
XGFHeadFB = Packed Record
Width,Height : word;
end;
const
BorlandColorMap : ColorMap = (0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15); //Borland and Open Watcom 16 color remap
// MSColorMap: ColorMap = (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
function nColorsToColorBits(nColors : integer) : integer;
var
CB : integer;
begin
CB:=0;
Case nColors of 2:CB:=1;
4:CB:=2;
16:CB:=4;
256:CB:=8;
end;
nColorsToColorBits:=CB;
end;
Procedure spTOmp(var singlePlane : LineBufType ;
var multiplane : LineBufType;
BytesPerPlane,nPlanes : Word);
var
BitPlane1 : Word;
BitPlane2 : Word;
BitPlane3 : Word;
BitPlane4 : Word;
BitPlane5 : Word;
pixelpos : Word;
color : Word;
xoffset : Word;
x,j : Word;
begin
Fillchar(multiplane,sizeof(multiplane),0);
BitPlane1:=0;
BitPlane2:=bytesPerPlane;
BitPlane3:=BytesPerPlane*2;
BitPlane4:=BytesPerPlane*3;
BitPlane5:=BytesPerPlane*4; //32 colors
xoffset:=0;
pixelpos:=0;
for x:=0 to bytesPerPlane-1 do
begin
for j:=0 to 7 do
begin
color:=SinglePlane[xoffset+j];
if (nPlanes > 4) AND biton(4,color) then setbit((7-j),1,multiplane[BitPlane5+pixelpos]);
if (nPlanes > 3) AND biton(3,color) then setbit((7-j),1,multiplane[BitPlane4+pixelpos]);
if (nPlanes > 2) AND biton(2,color) then setbit((7-j),1,multiplane[BitPlane3+pixelpos]);
if (nPlanes > 1) AND biton(1,color) then setbit((7-j),1,multiplane[BitPlane2+pixelpos]);
if (nPlanes > 0) AND biton(0,color) then setbit((7-j),1,multiplane[BitPlane1+pixelpos]);
end;
inc(pixelpos);
inc(xoffset,8);
end;
end;
//4 color packed - 4 pixels per byte
Procedure spToPacked4(var SinglePlane : LineBufType ;
var PackedPlane : LineBufType;
BytesPerLine : word);
var
x,i : word;
begin
Fillchar(PackedPlane,sizeof(PackedPlane),0);
x:=0;
For i:=0 to BytesPerLine-1 do
begin
PackedPlane[i] := (SinglePlane[x] shl 6) + (SinglePlane[x+1] shl 4) + (SinglePlane[x+2] shl 2) + SinglePlane[x+3];
inc(x,4);
end;
end;
//16 color packed - 2 pixels per byte
Procedure spToPacked16(var SinglePlane : LineBufType ;
var PackedPlane : LineBufType;
BytesPerLine : word);
var
x,i : word;
begin
Fillchar(PackedPlane,sizeof(PackedPlane),0);
x:=0;
For i:=0 to BytesPerLine-1 do
begin
PackedPlane[i] := (SinglePlane[x] shl 4) + SinglePlane[x+1];
inc(x,2);
end;
end;
Function WriteXgfFP(x,y,x2,y2 : word;filename:string):word;
type
linebufFP = array[0..1023] of Word;
var
Header : XGFHeadFP;
lineBuf:linebufFP;
counter : integer;
F : File;
Error : Word;
j,i : integer;
begin
Header.Width:=x2-x+1;
Header.Height:=y2-y+1;
Header.reserved:=0;
{$I+}
Assign(F,filename);
Rewrite(F,1);
Blockwrite(F,Header,sizeof(Header));
{$I-}
Error:=IOResult;
if Error <> 0 then
begin
close(F);
WriteXgfFP:=Error;
exit;
end;
For j:=y to y2 do
begin
counter:=0;
for i:=x to x2 do
begin
linebuf[counter]:=RMCoreBase.GetPixel(i,j);
inc(counter);
end;
blockwrite(F,linebuf,header.Width*sizeof(word));
end;
Close(F);
{$I+}
WriteXgfFP:=IOResult;
end;
Function WriteXgfFB(x,y,x2,y2 : word;filename:string):word;
type
//free takes a Word
linebufFB = array[0..1023] of Byte;
var
Header : XGFHeadFB;
lineBuf:linebufFB;
counter : integer;
F : File;
Error : Word;
j,i : integer;
width,height : word;
begin
width:=x2-x+1;
Height:=y2-y+1;
Header.Width:=width SHL 3;
Header.Height:=height;
{$I+}
Assign(F,filename);
Rewrite(F,1);
Blockwrite(F,Header,sizeof(Header));
Error:=IOResult;
if Error <> 0 then
begin
close(F);
WriteXgfFB:=Error;
exit;
end;
For j:=y to y2 do
begin
counter:=0;
for i:=x to x2 do
begin
linebuf[counter]:=RMCoreBase.GetPixel(i,j);
inc(counter);
end;
blockwrite(F,linebuf,width);
end;
Close(F);
WriteXgfFB:=IOResult;
{$I+}
end;
Procedure RemapToBorland(var SinglePlane : LineBufType; width : word) ;
var
i : word;
begin
for i:=0 to width-1 do
begin
SinglePlane[i]:=BorlandColorMap[SinglePlane[i]];
end;
end;
function GetBPLSize(width,ncolors : word) : word;
begin
GetBPLSize:=0;
case nColors of 2,16:GetBPLSize:=(width+7) div 8; (* note to self - this is correct, Bytes per line for one bitplane is the same for 2 and 16 colors, but 16 colors has 4 bitplanes *)
4:GetBPLSize:=(width+3) div 4;
256:GetBPLSize:=width;
end;
end;
function GetBPLSizeTMT(width,ncolors : word) : word;
begin
GetBPLSizeTMT:=width;
end;
function GetBPLSizeBAM(width,ncolors : word) : word;
begin
GetBPLSizeBAM:=0;
case nColors of 2:GetBPLSizeBAM:=(width+7) div 8; (* note to self - this is correct, Bytes per line for one bitplane is the same for 2 and 16 colors, but 16 colors has 4 bitplanes *)
4:GetBPLSizeBAM:=(width+3) div 4;
16:GetBPLSizeBAM:=(width+1) div 2;
256:GetBPLSizeBAM:=width;
end;
end;
function GetXImageSizeBAM(width,height,ncolors : integer) : longint;
begin
GetXImageSizeBAM:=GetBPLSizeBAM(width,ncolors)*height+4;
end;
function GetRGBXImageSizeBAM(width,height : integer) : longint;
begin
GetRGBXImageSizeBAM:=width*3*height+4;
end;
function GetXImageSizeTMT(width,height,ncolors : integer) : longint;
begin
GetXImageSizeTMT:=GetBPLSizeTMT(width,ncolors)*height+4;
end;
function GetXImageSize(width,height,ncolors : integer) : longint;
var
BPL : word;
begin
GetXImageSize:=0;
BPL:=GetBPLSize(width,ncolors);
case nColors of 2,4,256:GetXImageSize:=BPL*height+4;
16:GetXImageSize:=BPL*4*height+4; (* GetBPLSize give us size for one bitplane line - 16 colors have 4 bitplanes*)
end;
end;
function GetXImageSizeOW(width,height,ncolors : integer) : longint;
begin
GetXImageSizeOW:=GetXImageSize(width,height,ncolors)+2; //OW header contains 2 more bytes to specy Color Bits
end;
function GetXImageSizeFP(width,height : integer) : longint;
begin
//all FP simulated Graph modes up 256 colors take word per pixel
GetXImageSizeFP:=sizeof(XGFHeadFP)+(width*2)*height;
end;
function GetXImageSizeFB(width,height : integer) : longint;
begin
GetXImageSizeFB:=sizeof(XGFHeadFB)+width*height;
end;
// depensing on the compiler the width/height is different
Procedure FixHead(var head : XgfHead;width,height, LanType : word);
var
numColors : word;
begin
numColors:=GetMaxColor+1;
Case LanType of TPLan,TCLan,TMTLan: begin
head.Width:=width-1;
head.Height:=height-1;
end;
PBLan: begin
head.Width:=width;
head.Height:=height;
end;
BAMLan: begin
head.Width:=width;
head.Height:=height;
If NumColors=4 then head.Width:=width*2
end;
GWLan,QBLan,QCLan,QPLan: begin
If NumColors=4 then head.Width:=width*2
else If NumColors=256 then head.Width:=width SHL 3
else head.Width:=width;
head.Height:=height;
end;
end;
end;
Procedure WriteXGFBufferFP(BitPlaneWriter : BitPlaneWriterProc;var data :BufferRec; x,y,x2,y2 : word);
var
myHead : XgfHeadFP;
mywidth : word;
myheight : word;
i,j,n : word;
tempBuf : array[1..12] of byte;
PixelCol : word;
wordbuf : array[1..2] of byte;
begin
myWidth:=x2-x+1;
myHeight:=y2-y+1;
myHead.Width:=myWidth;
myHead.Height:=myHeight;
myHead.reserved:=0;
Move(myHead,tempBuf,sizeof(tempBuf));
for n:=1 to 12 do
begin
BitplaneWriter(tempBuf[n],data,1);
end;
for j:=0 to myheight-1 do
begin
for i:=0 to myWidth-1 do
begin
pixelCol:=GetPixel(x+i,y+j);
move(PixelCol,wordbuf,sizeof(wordbuf));
BitplaneWriter(wordbuf[1],data,1);
BitplaneWriter(wordbuf[2],data,1);
end;
end;
BitplaneWriter(0,data,2); //flush it
end;
Procedure WriteXGFBufferFB(BitPlaneWriter : BitPlaneWriterProc;var data :BufferRec; x,y,x2,y2 : word);
var
myHead : XgfHeadFB;
mywidth : word;
myheight : word;
i,j,n : word;
tempBuf : array[1..4] of byte;
PixelCol : byte;
begin
myWidth:=x2-x+1;
myHeight:=y2-y+1;
myHead.Width:=mywidth SHL 3;
myHead.Height:=myHeight;
Move(myHead,tempBuf,sizeof(tempBuf));
for n:=1 to 4 do
begin
BitplaneWriter(tempBuf[n],data,1);
end;
for j:=0 to myheight-1 do
begin
for i:=0 to myWidth-1 do
begin
pixelCol:=GetPixel(x+i,y+j);
BitplaneWriter(pixelCol,data,1);
end;
end;
BitplaneWriter(0,data,2); //flush it
end;
Procedure WriteXGFBufferOW(BitPlaneWriter : BitPlaneWriterProc;var data :BufferRec; x,y,x2,y2 : word);
Var
sourcelinebuf : Linebuftype;
destlinebuf : Linebuftype;
Head : XgfHeadOW;
width : word;
height : word;
BPL : Word; //bytes per line for one bitplane
BTW : word; //bytes to write to buffer
i,j,n : Word;
nColors : Word;
tempBuf : array[1..6] of byte;
begin
width:=x2-x+1;
Height:=y2-y+1;
nColors:=GetMaxColor+1;
BPL:=GetBPLSize(Width,nColors);
BTW:=BPL;
if nColors = 16 then BTW:=BPL*4;
Head.Width:=width;
Head.Height:=height;
Head.Colors:=nColorsToColorBits(nColors);
Move(Head,tempBuf,sizeof(tempBuf));
for n:=1 to 6 do
begin
BitplaneWriter(tempBuf[n],data,1);
end;
for j:=0 to height-1 do
begin
for i:=0 to Width-1 do
begin
sourceLineBuf[i]:=GetPixel(x+i,y+j);
end;
case nColors of 2:spTOmp(sourcelinebuf,destlinebuf,BPL,1);
4:spToPacked4(sourcelinebuf,destlinebuf,BPL);
16:begin
RemapToBorland(sourcelinebuf,Width); //OW uses the same bit plane format as Borland for 16 colors
spTOmp(sourcelinebuf,destlinebuf,BPL,4);
end;
256:destlinebuf:=sourcelinebuf;
end;
for n:=0 to BTW-1 do
begin
BitplaneWriter(destlinebuf[n],data,1);
end;
end;
BitplaneWriter(0,data,2); //flush it
end;
Procedure WriteRGBXGFBufferBAM(BitPlaneWriter : BitPlaneWriterProc;var data :BufferRec; x,y,x2,y2,LanType : word);
Var
destlinebuf: Linebuftype;
Head : XgfHead;
Width : word;
Height : word;
BTW : word; //bytes to write to buffer
i,j,n : Word;
tempBuf : array[1..4] of byte;
PixelIndex : integer;
cr : TRMColorRec;
begin
Width:=x2-x+1;
Height:=y2-y+1;
BTW:=Width*3;
FixHead(Head,Width,Height,LanType);
Move(Head,tempBuf,sizeof(tempBuf));
for n:=1 to 4 do
begin
BitplaneWriter(tempBuf[n],data,1);
end;
for j:=0 to Height-1 do
begin
for i:=0 to Width-1 do
begin
PixelIndex:=GetPixel(x+i,y+j);
GetColor(PixelIndex,cr);
destLineBuf[i*3]:=cr.r;
destLineBuf[i*3+1]:=cr.g;
destLineBuf[i*3+2]:=cr.b;
end;
for n:=0 to BTW-1 do
begin
BitplaneWriter(destlinebuf[n],data,1);
end;
end;
BitplaneWriter(0,data,2); //flush it
end;
Procedure WriteXGFBufferBAM(BitPlaneWriter : BitPlaneWriterProc;var data :BufferRec; x,y,x2,y2,LanType : word);
Var
sourcelinebuf : Linebuftype;
destlinebuf : Linebuftype;
Head : XgfHead;
width : word;
height : word;
BPL : Word;
BTW : word; //bytes to write to buffer
i,j,n : Word;
nColors : Word;
tempBuf : array[1..4] of byte;
begin
width:=x2-x+1;
Height:=y2-y+1;
nColors:=GetMaxColor+1;
BPL:=GetBPLSizeBAM(Width,nColors);
BTW:=BPL;
FixHead(Head,Width,Height,LanType);
Move(Head,tempBuf,sizeof(tempBuf));
for n:=1 to 4 do
begin
BitplaneWriter(tempBuf[n],data,1);
end;
for j:=0 to height-1 do
begin
for i:=0 to Width-1 do
begin
sourceLineBuf[i]:=GetPixel(x+i,y+j);
end;
case nColors of 2:spTOmp(sourcelinebuf,destlinebuf,BPL,1);
4:spToPacked4(sourcelinebuf,destlinebuf,BPL);
16:spToPacked16(sourcelinebuf,destlinebuf,BPL);
256:destlinebuf:=sourcelinebuf;
end;
for n:=0 to BTW-1 do
begin
BitplaneWriter(destlinebuf[n],data,1);
end;
end;
BitplaneWriter(0,data,2); //flush it
end;
Procedure WriteXGFBufferTMT(BitPlaneWriter : BitPlaneWriterProc;var data :BufferRec; x,y,x2,y2 : word);
Var
// sourcelinebuf : Linebuftype;
destlinebuf : Linebuftype;
Head : XgfHead;
Width : Word;
Height : Word;
BPL : Word; //bytes per line for one bitplane
BTW : Word; //bytes to write to buffer
i,j,n : Word;
nColors : Word;
tempBuf : array[1..4] of byte;
begin
width:=x2-x+1;
Height:=y2-y+1;
nColors:=GetMaxColor+1;
BPL:=GetBPLSizeTMT(Width,nColors);
BTW:=BPL;
//patch correct widht height for language/compiler - Microsoft and Borland did some wierd things to a simple bitmap format
FixHead(Head,Width,Height,TMTLan);
Move(Head,tempBuf,sizeof(tempBuf));
for n:=1 to 4 do
begin
BitplaneWriter(tempBuf[n],data,1);
end;
for j:=0 to height-1 do
begin
for i:=0 to Width-1 do
begin
destLineBuf[i]:=GetPixel(x+i,y+j);
end;
for n:=0 to BTW-1 do
begin
BitplaneWriter(destlinebuf[n],data,1);
end;
end;
BitplaneWriter(0,data,2); //flush it
end;
Procedure WriteXGFBuffer(BitPlaneWriter : BitPlaneWriterProc;var data :BufferRec; x,y,x2,y2,LanType : word);
Var
sourcelinebuf : Linebuftype;
destlinebuf : Linebuftype;
Head : XgfHead;
width : word;
height : word;
BPL : Word; //bytes per line for one bitplane
BTW : word; //bytes to write to buffer
i,j,n : Word;
nColors : Word;
tempBuf : array[1..4] of byte;
begin
width:=x2-x+1;
Height:=y2-y+1;
nColors:=GetMaxColor+1;
BPL:=GetBPLSize(Width,nColors);
BTW:=BPL;
if nColors = 16 then BTW:=BPL*4;
//BitplaneWriter(0,data,0);
//patch correct widht height for language/compiler - Microsoft and Borland did some wierd things to a simple bitmap format
FixHead(Head,Width,Height,LanType);
Move(Head,tempBuf,sizeof(tempBuf));
for n:=1 to 4 do
begin
BitplaneWriter(tempBuf[n],data,1);
end;
for j:=0 to height-1 do
begin
for i:=0 to Width-1 do
begin
sourceLineBuf[i]:=GetPixel(x+i,y+j);
end;
case nColors of 2:spTOmp(sourcelinebuf,destlinebuf,BPL,1);
4:spToPacked4(sourcelinebuf,destlinebuf,BPL);
16:begin
If (LanType=TPLan) OR (LanType=TCLan) OR (LanType=PBLan) then RemapToBorland(sourcelinebuf,Width);
spTOmp(sourcelinebuf,destlinebuf,BPL,4);
end;
256:destlinebuf:=sourcelinebuf;
end;
for n:=0 to BTW-1 do
begin
BitplaneWriter(destlinebuf[n],data,1);
end;
end;
BitplaneWriter(0,data,2); //flush it
end;
procedure BitplaneWriterFile(inByte : Byte; var Buffer : BufferRec;action : integer);
begin
{$I-}
if action = 0 then
begin
buffer.bufCount:=0;
buffer.error:=0;
end
else if action = 1 then
begin
inc(Buffer.bufcount);
buffer.buflist[Buffer.bufcount]:=inByte;
if Buffer.bufcount = 128 then
begin
Blockwrite(buffer.f,Buffer.buflist,128);
Buffer.bufcount:=0;
end;
end
else if action = 2 then
begin
if Buffer.bufcount > 0 then
begin
Blockwrite(buffer.f,Buffer.buflist,buffer.bufcount);
Buffer.bufcount:=0;
end;
end;
{$I+}
buffer.Error:=IORESULT;
end;
procedure BitplaneWriterPascalCode(inByte : Byte; var Buffer : BufferRec;action : integer);
var
i : integer;
begin
{$I-}
if action = 0 then
begin
buffer.bufCount:=0;
buffer.arraysize:=0;
buffer.ByteWriteCount:=0;
buffer.error:=0;
end
else if action = 1 then
begin
inc(buffer.bufcount);
buffer.buflist[buffer.bufcount]:=inbyte;
if buffer.bufcount = 20 then //every 20 bytes write to const line
begin
//write the const value
write(buffer.ftext,' ');
for i:=1 to 20 do
begin
write(buffer.ftext,'$',HexStr(buffer.buflist[i],2));
inc(buffer.ByteWriteCount);
if buffer.ByteWriteCount < buffer.ArraySize then write(buffer.ftext,',');
end;
if buffer.ByteWriteCount < buffer.ArraySize then writeln(buffer.ftext);
buffer.bufcount:=0;
end;
end
else if action = 2 then //write the remaining data
begin
if buffer.bufcount > 0 then write(buffer.ftext,' ');
for i:=1 to buffer.bufcount do
begin
write(buffer.ftext,'$',HexStr(buffer.buflist[i],2));
inc(buffer.ByteWriteCount);
if buffer.ByteWriteCount < buffer.ArraySize then write(buffer.ftext,',');
end;
write(buffer.ftext,');');
writeln(buffer.ftext);
buffer.bufcount:=0;
end;
{$I+}
buffer.Error:=IORESULT;
end;
procedure BitplaneWriterCCode(inByte : Byte; var Buffer : BufferRec;action : integer);
var
i : integer;
begin
{$I-}
if action = 0 then
begin
buffer.bufCount:=0;
buffer.arraysize:=0;
buffer.ByteWriteCount:=0;
buffer.error:=0;
end
else if action = 1 then
begin
inc(buffer.bufcount);
buffer.buflist[buffer.bufcount]:=inbyte;
if buffer.bufcount = 20 then //every 20 bytes write to const line
begin
//write the const value
write(buffer.ftext,' ');
for i:=1 to 20 do
begin
write(buffer.ftext,'0x',LowerCase(HexStr(buffer.buflist[i],2)));
inc(buffer.ByteWriteCount);
if buffer.ByteWriteCount < buffer.ArraySize then write(buffer.ftext,',');
end;
if buffer.ByteWriteCount < buffer.ArraySize then writeln(buffer.ftext);
buffer.bufcount:=0;
end;
end
else if action = 2 then //write the remaining data
begin
if buffer.bufcount > 0 then write(buffer.ftext,' ');
for i:=1 to buffer.bufcount do
begin
write(buffer.ftext,'0x',LowerCase(HexStr(buffer.buflist[i],2)));
inc(buffer.ByteWriteCount);
if buffer.ByteWriteCount < buffer.ArraySize then write(buffer.ftext,',');
end;
write(buffer.ftext,'};');
writeln(buffer.ftext);
buffer.bufcount:=0;
end;
{$I+}
buffer.Error:=IORESULT;
end;
procedure BitplaneWriterGWBasicCode(inByte : Byte; var Buffer : BufferRec;action : integer);
var
i : integer;
begin
{$I-}
if action = 0 then
begin
buffer.bufCount:=0;
buffer.error:=0;
end
else if action = 1 then
begin
inc(buffer.bufcount);
buffer.buflist[buffer.bufcount]:=inbyte;
if buffer.bufcount = 20 then //every 10 bytes write to data statement
begin
//write the data statement
write(buffer.ftext,GetGWNextLineNumber,' DATA ');
for i:=0 to 9 do
begin
write(buffer.ftext,'&H',HexStr(buffer.buflist[i*2+2],2),HexStr(buffer.buflist[i*2+1],2));
if i < 9 then write(buffer.ftext,',');
end;
writeln(buffer.ftext);
buffer.bufcount:=0;
end;
end
else if action = 2 then //write the remaining data
begin
if buffer.bufcount > 0 then
begin
write(buffer.ftext,GetGWNextLineNumber,' DATA ');
for i:=0 to ((buffer.bufcount+1) div 2)-1 do
begin
write(buffer.ftext,'&H',HexStr(buffer.buflist[i*2+2],2),HexStr(buffer.buflist[i*2+1],2));
if i < (((buffer.bufcount+1) div 2)-1) then write(buffer.ftext,',');
end;
writeln(buffer.ftext);
buffer.bufcount:=0;
end;
end;
{$I+}
buffer.Error:=IORESULT;
end;
// word size data statements - byte strean is converted to words
procedure BitplaneWriterBasicCode(inByte : Byte; var Buffer : BufferRec;action : integer);
var
i : integer;
begin
{$I-}
if action = 0 then
begin
buffer.bufCount:=0;
buffer.error:=0;
end
else if action = 1 then
begin
inc(buffer.bufcount);
buffer.buflist[buffer.bufcount]:=inbyte;
if buffer.bufcount = 20 then //every 10 bytes write to data statement
begin
//write the data statement
write(buffer.ftext,'DATA ');
for i:=0 to 9 do
begin
write(buffer.ftext,'&H',HexStr(buffer.buflist[i*2+2],2),HexStr(buffer.buflist[i*2+1],2));
if i < 9 then write(buffer.ftext,',');
end;
writeln(buffer.ftext);
buffer.bufcount:=0;
end;
end
else if action = 2 then //write the remaining data
begin
if buffer.bufcount > 0 then
begin
write(buffer.ftext,'DATA ');
for i:=0 to ((buffer.bufcount+1) div 2)-1 do
begin
write(buffer.ftext,'&H',HexStr(buffer.buflist[i*2+2],2),HexStr(buffer.buflist[i*2+1],2));
if i < (((buffer.bufcount+1) div 2)-1) then write(buffer.ftext,',');
end;
writeln(buffer.ftext);
buffer.bufcount:=0;
end;
end;
{$I+}
buffer.Error:=IORESULT;
end;
procedure BitplaneWriterBAMBasicCode(inByte : Byte; var Buffer : BufferRec;action : integer);
var
i : integer;
BAMInt : smallint;
begin
{$I-}
if action = 0 then
begin
buffer.bufCount:=0;
buffer.error:=0;
end
else if action = 1 then
begin
inc(buffer.bufcount);
buffer.buflist[buffer.bufcount]:=inbyte;
if buffer.bufcount = 20 then //every 10 bytes write to data statement
begin
//write the data statement
write(buffer.ftext,'DATA ');
for i:=0 to 9 do
begin
BAMInt:=(buffer.buflist[i*2+2] shl 8) + buffer.buflist[i*2+1];
//write(buffer.ftext,buffer.buflist[i*2+2],2),HexStr(buffer.buflist[i*2+1],2));