aboutsummaryrefslogtreecommitdiff
path: root/engines/avalanche/ch_egats.cpp
blob: d96eb89b36d302f0e56506391d0cfc73a4999bbb (plain)
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
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

/*
 * This code is based on the original source code of Lord Avalot d'Argent version 1.3.
 * Copyright (c) 1994-1995 Mike, Mark and Thomas Thurman.
 */

#include "graph.h"

namespace Avalanche {

enum flavourtype {ch_ega, ch_bgi, last_flavourtype};

struct chunkblocktype {
	flavourtype flavour;
	integer x, y;
	integer xl, yl;
	longint size;
	boolean natural;

	boolean memorise; /* Hold it in memory? */
};

untyped_file f;
longint offset;
chunkblocktype ch;
integer gd, gm;
byte bit;
pointer p;

void mdrop(integer x, integer y, integer xl, integer yl, pointer p) /* assembler;
asm
  push ds;      { Strictly speaking, we shouldn't modify DS, so we'll save it.}
  push bp;      { Nor BP! }


  { DI holds the offset on this page. It starts at the top left-hand corner. }
  { (It should equal ch.y*80+ch.x. }

  mov ax,y;
  mov dl,80;
  mul dl; { Line offset now calculated. }
  mov di,ax; { Move it into DI. }
  mov ax,x;
  add di,ax; { Full offset now calculated. }

  mov bx,yl; { No. of times to repeat lineloop. }
  inc bx;        { "loop" doesn't execute the zeroth time. }
  mov bh,bl;     { Put it into BH. }

  { BP holds the length of the string to copy. It's equal to ch.xl.}

  mov ax,word(p);   { Data is held at DS:SI. }
  mov si,ax;
  mov ax,word(p+2); { This will be moved over into ds in just a tick... }

  mov bp,xl;

  mov ds,ax;


  cld;          { We're allowed to hack around with the flags! }

  mov ax,$A000; { Top of the first EGA page. }
  mov es,ax;    { Offset on this page is calculated below... }


{    port[$3c4]:=2; port[$3ce]:=4; }

  mov dx,$3c4;
  mov al,2;
  out dx,al;
  mov dx,$3ce;
  mov al,4;
  out dx,al;

  mov cx,4;  { This loop executes for 3, 2, 1, and 0. }
  mov bl,0;


 @mainloop:

    push di;
    push cx;

{    port[$3C5]:=1 shl bit; }
    mov dx,$3C5;
    mov al,1;
    mov cl,bl; { BL = bit. }
    shl al,cl;
    out dx,al;
{     port[$3CF]:=bit; }
    mov dx,$3CF;
    mov al,bl; { BL = bit. }
    out dx,al;

    xor ch,ch;
    mov cl,bh; { BH = ch.yl. }

   @lineloop:

     push cx;

     mov cx,bp;

     repz movsb; { Copy the data. }

     sub di,bp;
     add di,80;

     pop cx;

   loop @lineloop;

    inc bl; { One more on BL. }

    pop cx;
    pop di;

 loop @mainloop;

  pop bp;
  pop ds;       { Get DS back again. }
*/
{
}

int main(int argc, const char *argv[]) {
	pio_initialize(argc, argv);
	assign(f, "chunk21.avd");
	reset(f, 1);

	seek(f, 49);
	blockread(f, offset, 4);

	seek(f, offset);

	blockread(f, ch, sizeof(ch));

	gd = 3;
	gm = 0;
	initgraph(gd, gm, "c:\\bp\\bgi");

	getmem(p, ch.size);
	blockread(f, p, ch.size);
	/* putimage(0,0,p^,0);*/


	/* with ch do
	  for bit:=0 to 3 do
	  begin;
	   port[$3c4]:=2; port[$3ce]:=4; port[$3C5]:=1 shl bit; port[$3CF]:=bit;
	   for gm:=0 to yl do
	    blockread(f,mem[$A000*gm*80],(ch.xl+7) div 8);
	  end;*/

	mdrop(ch.x, ch.y, ch.xl, ch.yl, p);

	close(f);
	return EXIT_SUCCESS;
}

} // End of namespace Avalanche.