From: sparky4 Date: Tue, 24 Nov 2015 19:48:20 +0000 (-0600) Subject: wwww X-Git-Url: http://4ch.mooo.com/gitweb/?p=16.git;a=commitdiff_plain;h=ae047ad3be09d38573b5cab895472e31ef7d47c7 wwww --- diff --git a/16.exe b/16.exe index 76cd8d24..5eebd937 100755 Binary files a/16.exe and b/16.exe differ diff --git a/16/x/default.fnt b/16/x/default.fnt new file mode 100755 index 00000000..12eb22cb --- /dev/null +++ b/16/x/default.fnt @@ -0,0 +1,260 @@ +; +; MODEX library default font +; Copyright (c) 1993-1994 by Alessandro Scotti +; + DB 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h ; #0 + DB 07Eh, 081h, 0A5h, 081h, 0A5h, 099h, 081h, 07Eh ; #1 + DB 07Eh, 0FFh, 0DBh, 0FFh, 0DBh, 0E7h, 0FFh, 07Eh ; #2 + DB 06Ch, 0FEh, 0FEh, 0FEh, 07Ch, 038h, 010h, 000h ; #3 + DB 010h, 038h, 07Ch, 0FEh, 07Ch, 038h, 010h, 000h ; #4 + DB 010h, 038h, 010h, 054h, 0FEh, 054h, 010h, 0FEh ; #5 + DB 010h, 038h, 07Ch, 0FEh, 0FEh, 07Ch, 010h, 0FEh ; #6 + DB 000h, 018h, 03Ch, 07Eh, 07Eh, 03Ch, 018h, 000h ; #7 + DB 0FFh, 0E7h, 0C3h, 081h, 081h, 0C3h, 0E7h, 0FFh ; #8 + DB 000h, 03Ch, 066h, 042h, 042h, 066h, 03Ch, 000h ; #9 + DB 0FFh, 0C3h, 099h, 0BDh, 0BDh, 099h, 0C3h, 0FFh ; #10 + DB 007h, 003h, 005h, 078h, 084h, 084h, 084h, 078h ; #11 + DB 07Ch, 082h, 082h, 082h, 07Ch, 010h, 038h, 010h ; #12 + DB 01Ch, 010h, 01Ch, 010h, 010h, 010h, 030h, 030h ; #13 + DB 03Eh, 022h, 03Eh, 022h, 022h, 026h, 066h, 060h ; #14 + DB 099h, 05Ah, 03Ch, 0E7h, 0E7h, 03Ch, 05Ah, 099h ; #15 + DB 000h, 010h, 030h, 070h, 0F0h, 070h, 030h, 010h ; #16 + DB 000h, 080h, 0C0h, 0E0h, 0F0h, 0E0h, 0C0h, 080h ; #17 + DB 010h, 038h, 054h, 010h, 010h, 054h, 038h, 010h ; #18 + DB 048h, 048h, 048h, 048h, 048h, 000h, 048h, 000h ; #19 + DB 07Eh, 092h, 092h, 072h, 012h, 012h, 012h, 000h ; #20 + DB 03Ch, 022h, 018h, 024h, 024h, 018h, 044h, 03Ch ; #21 + DB 000h, 000h, 000h, 000h, 000h, 03Eh, 03Eh, 000h ; #22 + DB 038h, 054h, 010h, 010h, 010h, 054h, 038h, 0FEh ; #23 + DB 000h, 010h, 038h, 054h, 010h, 010h, 010h, 000h ; #24 + DB 000h, 010h, 010h, 010h, 054h, 038h, 010h, 000h ; #25 + DB 000h, 008h, 004h, 0FEh, 004h, 008h, 000h, 000h ; #26 + DB 000h, 020h, 040h, 0FEh, 040h, 020h, 000h, 000h ; #27 + DB 000h, 000h, 080h, 080h, 080h, 0FCh, 000h, 000h ; #28 + DB 000h, 024h, 042h, 0FFh, 042h, 024h, 000h, 000h ; #29 + DB 000h, 000h, 010h, 038h, 07Ch, 0FEh, 000h, 000h ; #30 + DB 000h, 000h, 0FEh, 07Ch, 038h, 010h, 000h, 000h ; #31 + DB 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h ; + DB 010h, 010h, 010h, 010h, 010h, 000h, 010h, 000h ; ! + DB 000h, 024h, 024h, 000h, 000h, 000h, 000h, 000h ; " + DB 024h, 024h, 07Eh, 024h, 07Eh, 024h, 024h, 000h ; # + DB 038h, 054h, 050h, 038h, 014h, 054h, 038h, 010h ; $ + DB 000h, 002h, 044h, 008h, 010h, 020h, 042h, 000h ; % + DB 038h, 044h, 038h, 060h, 094h, 088h, 074h, 000h ; & + DB 020h, 020h, 040h, 000h, 000h, 000h, 000h, 000h ; ' + DB 010h, 020h, 040h, 040h, 040h, 020h, 010h, 000h ; ( + DB 040h, 020h, 010h, 010h, 010h, 020h, 040h, 000h ; ) + DB 000h, 024h, 018h, 07Eh, 018h, 024h, 000h, 000h ; * + DB 000h, 010h, 010h, 07Ch, 010h, 010h, 000h, 000h ; + + DB 000h, 000h, 000h, 000h, 000h, 010h, 010h, 020h ; , + DB 000h, 000h, 000h, 0FCh, 000h, 000h, 000h, 000h ; - + DB 000h, 000h, 000h, 000h, 000h, 000h, 010h, 000h ; . + DB 000h, 004h, 008h, 010h, 020h, 040h, 080h, 000h ; / + DB 07Ch, 0C6h, 08Ah, 092h, 0A2h, 0C6h, 07Ch, 000h ; 0 + DB 010h, 030h, 010h, 010h, 010h, 010h, 038h, 000h ; 1 + DB 078h, 084h, 004h, 018h, 060h, 080h, 0FCh, 000h ; 2 + DB 078h, 084h, 004h, 038h, 004h, 084h, 078h, 000h ; 3 + DB 01Ch, 024h, 044h, 084h, 0FEh, 004h, 00Eh, 000h ; 4 + DB 0FCh, 080h, 0F8h, 004h, 004h, 084h, 078h, 000h ; 5 + DB 078h, 084h, 080h, 0F8h, 084h, 084h, 078h, 000h ; 6 + DB 0FCh, 004h, 004h, 008h, 010h, 020h, 020h, 000h ; 7 + DB 078h, 084h, 084h, 078h, 084h, 084h, 078h, 000h ; 8 + DB 078h, 084h, 084h, 07Ch, 004h, 084h, 078h, 000h ; 9 + DB 000h, 000h, 010h, 000h, 000h, 000h, 010h, 000h ; : + DB 000h, 000h, 010h, 000h, 000h, 010h, 010h, 020h ; ; + DB 008h, 010h, 020h, 040h, 020h, 010h, 008h, 000h ; < + DB 000h, 000h, 0FCh, 000h, 000h, 0FCh, 000h, 000h ; = + DB 040h, 020h, 010h, 008h, 010h, 020h, 040h, 000h ; > + DB 078h, 084h, 004h, 008h, 010h, 000h, 010h, 000h ; ? + DB 07Ch, 082h, 0BAh, 0A6h, 0BEh, 080h, 07Ch, 000h ; @ + DB 078h, 084h, 084h, 0FCh, 084h, 084h, 084h, 000h ; A + DB 0F8h, 084h, 084h, 0F8h, 084h, 084h, 0F8h, 000h ; B + DB 078h, 084h, 080h, 080h, 080h, 084h, 078h, 000h ; C + DB 0F0h, 088h, 084h, 084h, 084h, 088h, 0F0h, 000h ; D + DB 0FCh, 080h, 080h, 0F0h, 080h, 080h, 0FCh, 000h ; E + DB 0FCh, 080h, 080h, 0F0h, 080h, 080h, 080h, 000h ; F + DB 078h, 084h, 080h, 09Ch, 084h, 084h, 078h, 000h ; G + DB 084h, 084h, 084h, 0FCh, 084h, 084h, 084h, 000h ; H + DB 038h, 010h, 010h, 010h, 010h, 010h, 038h, 000h ; I + DB 01Ch, 008h, 008h, 008h, 088h, 088h, 070h, 000h ; J + DB 084h, 088h, 090h, 0E0h, 090h, 088h, 084h, 000h ; K + DB 080h, 080h, 080h, 080h, 080h, 080h, 0FCh, 000h ; L + DB 0C6h, 0AAh, 092h, 082h, 082h, 082h, 082h, 000h ; M + DB 082h, 0C2h, 0A2h, 092h, 08Ah, 086h, 082h, 000h ; N + DB 078h, 084h, 084h, 084h, 084h, 084h, 078h, 000h ; O + DB 0F8h, 084h, 084h, 0F8h, 080h, 080h, 080h, 000h ; P + DB 078h, 084h, 084h, 084h, 094h, 088h, 076h, 000h ; Q + DB 0F8h, 084h, 084h, 0F8h, 090h, 088h, 084h, 000h ; R + DB 078h, 084h, 080h, 078h, 004h, 084h, 078h, 000h ; S + DB 0FEh, 010h, 010h, 010h, 010h, 010h, 010h, 000h ; T + DB 084h, 084h, 084h, 084h, 084h, 084h, 078h, 000h ; U + DB 084h, 084h, 084h, 084h, 084h, 048h, 030h, 000h ; V + DB 082h, 082h, 082h, 082h, 092h, 0AAh, 0C6h, 000h ; W + DB 082h, 044h, 028h, 010h, 028h, 044h, 082h, 000h ; X + DB 044h, 044h, 044h, 038h, 010h, 010h, 010h, 000h ; Y + DB 0FEh, 004h, 008h, 010h, 020h, 040h, 0FEh, 000h ; Z + DB 078h, 040h, 040h, 040h, 040h, 040h, 078h, 000h ; [ + DB 000h, 080h, 040h, 020h, 010h, 008h, 004h, 000h ; \ + DB 078h, 008h, 008h, 008h, 008h, 008h, 078h, 000h ; ] + DB 010h, 028h, 044h, 082h, 000h, 000h, 000h, 000h ; ^ + DB 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0FFh ; _ + DB 020h, 020h, 010h, 000h, 000h, 000h, 000h, 000h ; ` + DB 000h, 000h, 038h, 004h, 03Ch, 044h, 07Ch, 000h ; a + DB 000h, 040h, 040h, 078h, 044h, 044h, 078h, 000h ; b + DB 000h, 000h, 03Ch, 040h, 040h, 040h, 03Ch, 000h ; c + DB 000h, 004h, 004h, 03Ch, 044h, 044h, 03Ch, 000h ; d + DB 000h, 000h, 038h, 044h, 07Ch, 040h, 03Ch, 000h ; e + DB 000h, 00Ch, 010h, 03Ch, 010h, 010h, 010h, 000h ; f + DB 000h, 000h, 03Ch, 044h, 044h, 03Ch, 004h, 038h ; g + DB 000h, 040h, 040h, 078h, 044h, 044h, 044h, 000h ; h + DB 000h, 010h, 000h, 010h, 010h, 010h, 010h, 000h ; i + DB 000h, 004h, 000h, 004h, 004h, 004h, 044h, 038h ; j + DB 000h, 040h, 040h, 050h, 060h, 050h, 048h, 000h ; k + DB 000h, 030h, 010h, 010h, 010h, 010h, 010h, 000h ; l + DB 000h, 000h, 068h, 054h, 054h, 044h, 044h, 000h ; m + DB 000h, 000h, 078h, 044h, 044h, 044h, 044h, 000h ; n + DB 000h, 000h, 038h, 044h, 044h, 044h, 038h, 000h ; o + DB 000h, 000h, 078h, 044h, 044h, 078h, 040h, 040h ; p + DB 000h, 000h, 03Ch, 044h, 044h, 03Ch, 004h, 004h ; q + DB 000h, 000h, 05Ch, 060h, 040h, 040h, 040h, 000h ; r + DB 000h, 000h, 038h, 040h, 07Ch, 004h, 07Ch, 000h ; s + DB 000h, 010h, 038h, 010h, 010h, 010h, 018h, 000h ; t + DB 000h, 000h, 044h, 044h, 044h, 044h, 038h, 000h ; u + DB 000h, 000h, 044h, 044h, 044h, 028h, 010h, 000h ; v + DB 000h, 000h, 044h, 044h, 054h, 054h, 06Ch, 000h ; w + DB 000h, 000h, 044h, 028h, 010h, 028h, 044h, 000h ; x + DB 000h, 000h, 044h, 044h, 044h, 03Ch, 004h, 07Ch ; y + DB 000h, 000h, 07Ch, 004h, 038h, 040h, 07Ch, 000h ; z + DB 000h, 008h, 010h, 010h, 030h, 010h, 010h, 008h ; { + DB 000h, 010h, 010h, 010h, 000h, 010h, 010h, 010h ; | + DB 000h, 020h, 010h, 010h, 018h, 010h, 010h, 020h ; } + DB 064h, 098h, 000h, 000h, 000h, 000h, 000h, 000h ; ~ + DB 000h, 010h, 028h, 044h, 082h, 082h, 0FEh, 000h ;  + DB 07Ch, 080h, 080h, 080h, 080h, 07Ch, 004h, 07Ch ; #128 + DB 000h, 028h, 000h, 044h, 044h, 044h, 038h, 000h ; #129 + DB 03Ch, 000h, 07Ch, 044h, 07Ch, 040h, 07Ch, 000h ; #130 + DB 07Eh, 081h, 038h, 004h, 03Ch, 044h, 07Ch, 000h ; #131 + DB 024h, 000h, 038h, 004h, 03Ch, 044h, 07Ch, 000h ; #132 + DB 078h, 000h, 038h, 004h, 03Ch, 044h, 07Ch, 000h ; #133 + DB 018h, 018h, 038h, 004h, 03Ch, 044h, 07Ch, 000h ; #134 + DB 000h, 000h, 078h, 080h, 080h, 078h, 008h, 038h ; #135 + DB 07Ch, 082h, 038h, 044h, 07Ch, 040h, 03Ch, 000h ; #136 + DB 048h, 000h, 038h, 044h, 07Ch, 040h, 03Ch, 000h ; #137 + DB 078h, 000h, 038h, 044h, 07Ch, 040h, 03Ch, 000h ; #138 + DB 000h, 028h, 000h, 010h, 010h, 010h, 010h, 000h ; #139 + DB 010h, 028h, 000h, 010h, 010h, 010h, 010h, 000h ; #140 + DB 000h, 030h, 000h, 010h, 010h, 010h, 010h, 000h ; #141 + DB 048h, 000h, 078h, 084h, 0FCh, 084h, 084h, 000h ; #142 + DB 030h, 030h, 078h, 084h, 0FCh, 084h, 084h, 000h ; #143 + DB 038h, 000h, 0FCh, 080h, 0F0h, 080h, 0FCh, 000h ; #144 + DB 000h, 000h, 07Eh, 008h, 07Eh, 048h, 07Eh, 000h ; #145 + DB 07Eh, 090h, 090h, 0FCh, 090h, 090h, 09Eh, 000h ; #146 + DB 07Ch, 082h, 038h, 044h, 044h, 044h, 038h, 000h ; #147 + DB 028h, 000h, 038h, 044h, 044h, 044h, 038h, 000h ; #148 + DB 070h, 000h, 038h, 044h, 044h, 044h, 038h, 000h ; #149 + DB 038h, 044h, 000h, 044h, 044h, 044h, 038h, 000h ; #150 + DB 070h, 000h, 044h, 044h, 044h, 044h, 038h, 000h ; #151 + DB 028h, 000h, 044h, 044h, 044h, 03Ch, 004h, 07Ch ; #152 + DB 048h, 000h, 078h, 084h, 084h, 084h, 078h, 000h ; #153 + DB 048h, 000h, 084h, 084h, 084h, 084h, 078h, 000h ; #154 + DB 000h, 010h, 038h, 040h, 040h, 040h, 038h, 010h ; #155 + DB 038h, 044h, 040h, 0E0h, 040h, 040h, 082h, 0FCh ; #156 + DB 044h, 07Ch, 010h, 07Ch, 010h, 07Ch, 010h, 000h ; #157 + DB 0F0h, 088h, 08Ah, 0F7h, 082h, 082h, 082h, 000h ; #158 + DB 00Ch, 012h, 010h, 018h, 030h, 010h, 090h, 060h ; #159 + DB 03Ch, 000h, 038h, 004h, 03Ch, 044h, 07Ch, 000h ; #160 + DB 000h, 018h, 000h, 010h, 010h, 010h, 010h, 000h ; #161 + DB 01Ch, 000h, 038h, 044h, 044h, 044h, 038h, 000h ; #162 + DB 01Ch, 000h, 044h, 044h, 044h, 044h, 038h, 000h ; #163 + DB 07Ch, 000h, 078h, 044h, 044h, 044h, 044h, 000h ; #164 + DB 07Ch, 000h, 044h, 064h, 054h, 04Ch, 044h, 000h ; #165 + DB 018h, 024h, 024h, 01Eh, 000h, 03Eh, 000h, 000h ; #166 + DB 01Ch, 022h, 022h, 01Ch, 000h, 03Eh, 000h, 000h ; #167 + DB 010h, 000h, 010h, 020h, 040h, 042h, 03Ch, 000h ; #168 + DB 000h, 000h, 000h, 0FCh, 080h, 080h, 000h, 000h ; #169 + DB 000h, 000h, 000h, 0FCh, 004h, 004h, 000h, 000h ; #170 + DB 040h, 044h, 048h, 057h, 021h, 047h, 004h, 007h ; #171 + DB 040h, 044h, 048h, 052h, 026h, 04Ah, 01Fh, 002h ; #172 + DB 010h, 000h, 010h, 010h, 010h, 010h, 010h, 000h ; #173 + DB 000h, 024h, 048h, 090h, 048h, 024h, 000h, 000h ; #174 + DB 000h, 048h, 024h, 012h, 024h, 048h, 000h, 000h ; #175 + DB 022h, 088h, 022h, 088h, 022h, 088h, 022h, 088h ; #176 + DB 055h, 0AAh, 055h, 0AAh, 055h, 0AAh, 055h, 0AAh ; #177 + DB 0DBh, 077h, 0DBh, 0EEh, 0DBh, 077h, 0DBh, 0EEh ; #178 + DB 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h ; #179 + DB 018h, 018h, 018h, 018h, 0F8h, 018h, 018h, 018h ; #180 + DB 018h, 018h, 0F8h, 018h, 0F8h, 018h, 018h, 018h ; #181 + DB 036h, 036h, 036h, 036h, 0F6h, 036h, 036h, 036h ; #182 + DB 000h, 000h, 000h, 000h, 0FEh, 036h, 036h, 036h ; #183 + DB 000h, 000h, 0F8h, 018h, 0F8h, 018h, 018h, 018h ; #184 + DB 036h, 036h, 0F6h, 006h, 0F6h, 036h, 036h, 036h ; #185 + DB 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h ; #186 + DB 000h, 000h, 0FEh, 006h, 0F6h, 036h, 036h, 036h ; #187 + DB 036h, 036h, 0F6h, 006h, 0FEh, 000h, 000h, 000h ; #188 + DB 036h, 036h, 036h, 036h, 0FEh, 000h, 000h, 000h ; #189 + DB 018h, 018h, 0F8h, 018h, 0F8h, 000h, 000h, 000h ; #190 + DB 000h, 000h, 000h, 000h, 0F8h, 018h, 018h, 018h ; #191 + DB 018h, 018h, 018h, 018h, 01Fh, 000h, 000h, 000h ; #192 + DB 018h, 018h, 018h, 018h, 0FFh, 000h, 000h, 000h ; #193 + DB 000h, 000h, 000h, 000h, 0FFh, 018h, 018h, 018h ; #194 + DB 018h, 018h, 018h, 018h, 01Fh, 018h, 018h, 018h ; #195 + DB 000h, 000h, 000h, 000h, 0FFh, 000h, 000h, 000h ; #196 + DB 018h, 018h, 018h, 018h, 0FFh, 018h, 018h, 018h ; #197 + DB 018h, 018h, 01Fh, 018h, 01Fh, 018h, 018h, 018h ; #198 + DB 036h, 036h, 036h, 036h, 037h, 036h, 036h, 036h ; #199 + DB 036h, 036h, 037h, 030h, 03Fh, 000h, 000h, 000h ; #200 + DB 000h, 000h, 03Fh, 030h, 037h, 036h, 036h, 036h ; #201 + DB 036h, 036h, 0F7h, 000h, 0FFh, 000h, 000h, 000h ; #202 + DB 000h, 000h, 0FFh, 000h, 0F7h, 036h, 036h, 036h ; #203 + DB 036h, 036h, 037h, 030h, 037h, 036h, 036h, 036h ; #204 + DB 000h, 000h, 0FFh, 000h, 0FFh, 000h, 000h, 000h ; #205 + DB 036h, 036h, 0F7h, 000h, 0F7h, 036h, 036h, 036h ; #206 + DB 018h, 018h, 0FFh, 000h, 0FFh, 000h, 000h, 000h ; #207 + DB 036h, 036h, 036h, 036h, 0FFh, 000h, 000h, 000h ; #208 + DB 000h, 000h, 0FFh, 000h, 0FFh, 018h, 018h, 018h ; #209 + DB 000h, 000h, 000h, 000h, 0FFh, 036h, 036h, 036h ; #210 + DB 036h, 036h, 036h, 036h, 03Fh, 000h, 000h, 000h ; #211 + DB 018h, 018h, 01Fh, 018h, 01Fh, 000h, 000h, 000h ; #212 + DB 000h, 000h, 01Fh, 018h, 01Fh, 018h, 018h, 018h ; #213 + DB 000h, 000h, 000h, 000h, 03Fh, 036h, 036h, 036h ; #214 + DB 036h, 036h, 036h, 036h, 0FFh, 036h, 036h, 036h ; #215 + DB 018h, 018h, 0FFh, 018h, 0FFh, 018h, 018h, 018h ; #216 + DB 018h, 018h, 018h, 018h, 0F8h, 000h, 000h, 000h ; #217 + DB 000h, 000h, 000h, 000h, 01Fh, 018h, 018h, 018h ; #218 + DB 0FFh, 0FFh, 0FFh, 0FFh, 0FFh, 0FFh, 0FFh, 0FFh ; #219 + DB 000h, 000h, 000h, 000h, 0FFh, 0FFh, 0FFh, 0FFh ; #220 + DB 0F0h, 0F0h, 0F0h, 0F0h, 0F0h, 0F0h, 0F0h, 0F0h ; #221 + DB 00Fh, 00Fh, 00Fh, 00Fh, 00Fh, 00Fh, 00Fh, 00Fh ; #222 + DB 0FFh, 0FFh, 0FFh, 0FFh, 000h, 000h, 000h, 000h ; #223 + DB 000h, 000h, 062h, 094h, 088h, 094h, 062h, 000h ; #224 + DB 000h, 0F0h, 088h, 0F0h, 088h, 088h, 0F0h, 080h ; #225 + DB 000h, 0F8h, 088h, 080h, 080h, 080h, 080h, 000h ; #226 + DB 000h, 0FCh, 048h, 048h, 048h, 048h, 048h, 000h ; #227 + DB 0FCh, 084h, 040h, 020h, 040h, 084h, 0FCh, 000h ; #228 + DB 03Ch, 040h, 038h, 044h, 044h, 044h, 038h, 000h ; #229 + DB 000h, 000h, 044h, 044h, 044h, 078h, 040h, 040h ; #230 + DB 000h, 036h, 048h, 008h, 008h, 008h, 008h, 000h ; #231 + DB 038h, 010h, 038h, 044h, 044h, 038h, 010h, 038h ; #232 + DB 078h, 084h, 084h, 0FCh, 084h, 084h, 078h, 000h ; #233 + DB 078h, 084h, 084h, 084h, 048h, 048h, 0CCh, 000h ; #234 + DB 078h, 004h, 038h, 044h, 044h, 044h, 038h, 000h ; #235 + DB 000h, 000h, 06Ch, 092h, 092h, 06Ch, 000h, 000h ; #236 + DB 000h, 000h, 03Ah, 044h, 05Ah, 022h, 05Ch, 000h ; #237 + DB 018h, 020h, 040h, 078h, 040h, 020h, 018h, 000h ; #238 + DB 078h, 084h, 084h, 084h, 084h, 084h, 084h, 000h ; #239 + DB 000h, 0FCh, 000h, 0FCh, 000h, 0FCh, 000h, 000h ; #240 + DB 020h, 020h, 0F8h, 020h, 020h, 000h, 0F8h, 000h ; #241 + DB 020h, 010h, 008h, 010h, 020h, 000h, 07Ch, 000h ; #242 + DB 008h, 010h, 020h, 010h, 008h, 000h, 07Ch, 000h ; #243 + DB 00Ch, 012h, 010h, 010h, 010h, 010h, 010h, 010h ; #244 + DB 010h, 010h, 010h, 010h, 010h, 010h, 090h, 060h ; #245 + DB 000h, 010h, 000h, 07Ch, 000h, 010h, 000h, 000h ; #246 + DB 000h, 032h, 04Ch, 000h, 032h, 04Ch, 000h, 000h ; #247 + DB 038h, 044h, 044h, 038h, 000h, 000h, 000h, 000h ; #248 + DB 000h, 000h, 000h, 018h, 018h, 000h, 000h, 000h ; #249 + DB 000h, 000h, 000h, 000h, 018h, 000h, 000h, 000h ; #250 + DB 00Eh, 008h, 008h, 008h, 048h, 028h, 018h, 008h ; #251 + DB 038h, 024h, 024h, 024h, 024h, 000h, 000h, 000h ; #252 + DB 03Ch, 004h, 03Ch, 020h, 03Ch, 000h, 000h, 000h ; #253 + DB 000h, 000h, 03Ch, 03Ch, 03Ch, 03Ch, 000h, 000h ; #254 + DB 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h ; #255 diff --git a/16/x/makefile b/16/x/makefile new file mode 100755 index 00000000..d3ad8b71 --- /dev/null +++ b/16/x/makefile @@ -0,0 +1,81 @@ +# +# MODEX library makefile (for Borland MAKE) +# Copyright (c) 1993,1994 by Alessandro Scotti +# +LIBINCS = MODEX.DEF + +LIBOBJS = MXBB.OBJ \ + MXCC.OBJ \ + MXCG.OBJ \ + MXCL.OBJ \ + MXCR.OBJ \ + MXFB.OBJ \ + MXFP.OBJ \ + MXGC.OBJ \ + MXGI.OBJ \ + MXGM.OBJ \ + MXGP.OBJ \ + MXGV.OBJ \ + MXHL.OBJ \ + MXIT.OBJ \ + MXLL.OBJ \ + MXLN.OBJ \ + MXOT.OBJ \ + MXPB.OBJ \ + MXPF.OBJ \ + MXPG.OBJ \ + MXPI.OBJ \ + MXPN.OBJ \ + MXPP.OBJ \ + MXRA.OBJ \ + MXRP.OBJ \ + MXSA.OBJ \ + MXSC.OBJ \ + MXSI.OBJ \ + MXSL.OBJ \ + MXSM.OBJ \ + MXSP.OBJ \ + MXSS.OBJ \ + MXTL.OBJ \ + MXVS.OBJ \ + MXWD.OBJ \ + MXWM.OBJ \ + MXWP.OBJ \ + MXWR.OBJ + +# +# ASM compiler +# +ASMC = tasm +ASMO = /m5 /p + +# +# PAS compiler +# +PASC = tpc +PASO = /m -$D- -$L- -$S- + +# +# LIB maker, uses response file +# +LIBC = tlib + +.asm.obj: + $(ASMC) $(ASMO) $< + +target: modex.lib +# modex.tpu modex.tpp + +#modex.tpu: $(LIBOBJS) modex.pas +# $(PASC) $(PASO) modex +# copy modex.tpu .. +# copy modex.pas .. + +#modex.tpp: $(LIBOBJS) modex.pas +# $(PASC) /cp $(PASO) modex +# copy modex.tpp .. + +modex.lib: modex.lbr $(LIBOBJS) + $(LIBC) modex.lib @modex.lbr + +$(LIBOBJS): modex.def diff --git a/16/x/modex.bak b/16/x/modex.bak new file mode 100755 index 00000000..560a1c68 Binary files /dev/null and b/16/x/modex.bak differ diff --git a/16/x/modex.def b/16/x/modex.def new file mode 100755 index 00000000..45bd900f --- /dev/null +++ b/16/x/modex.def @@ -0,0 +1,163 @@ +;------------------------------------------------------------ +; +; MODEX.DEF - Include file +; Copyright (c) 1993-1994 by Alessandro Scotti +; +JUMPS +LOCALS + +TRUE EQU 1 ; Boolean constants +FALSE EQU 0 + +USE286 = FALSE ; TRUE enables 80286 instructions +USE386 = FALSE ; TRUE enables 80386 (and 80286) instructions + +IF USE286 EQ TRUE + P286 +ENDIF + +IF USE386 EQ TRUE + P386 + USE286 = TRUE +ENDIF + +MXVERSION EQU 0128h ; Library version (1.40) + +;------------------------------------------------------------ +; +; VGA definitions +; +MISC EQU 3C2h ; Miscellaneous output +TS EQU 3C4h ; Timing Sequencer index register +GDC EQU 3CEh ; Graphics Data Controller index register +CRTC EQU 3D4h ; CRTC index register +STATUS EQU 3DAh ; Input Status register one + +;------------------------------------------------------------ +; +; Raster operators +; +OP_SET EQU 0 +OP_MOVE EQU 0 ; Same as OP_SET +OP_AND EQU 1 +OP_OR EQU 2 +OP_XOR EQU 3 +OP_TRANS EQU 4 +OP_ADD EQU 5 ; Must be last op + +;------------------------------------------------------------ +; +; Polygon fill functions +; +POLYSCANBUFSIZE EQU 4*1024 + +;------------------------------------------------------------ +; Macro to push registers, variables or flags onto the stack +; Usage: .push "loc16"[,"loc16"...] +; where "loc16" is a 16-bit register, a word-sized variable or the +; keyword "FLAGS". +; Exmpl: .push ax, flags, var1 +; .pop ax, flags, var1 +; +.push MACRO r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10 + IFNB + .ERROR <.PUSH has more than 10 arguments> + ENDIF + IRP $reg, + IFB <$reg> ;; Is argument blank? + EXITM ;; Yes, exit + ELSEIFIDNI <$reg>, ;; Is argument the keyword "FLAGS"? + pushf ;; Yes, push flags + ELSE + push $reg ;; Push argument + ENDIF + ENDM +ENDM + +;------------------------------------------------------------ +; Macro to pop registers, variables or flags from the stack +; Usage: .pop "loc16"[,"loc16"...] +; where "loc16" is a 16-bit register, a word-sized variable or the +; keyword "FLAGS". +; Exmpl: .push ax, flags, var1 +; .pop ax, flags, var1 +; +.pop MACRO r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10 + IFNB + .ERROR <.POP has more than 10 arguments> + ENDIF + IRP $reg, + IFNB <$reg> ;; Is argument non-blank? + IFIDNI <$reg>, ;; Yes, is it the keyword "FLAGS"? + popf ;; Yes, pop flags + ELSE + pop $reg ;; Pop argument + ENDIF + ENDIF + ENDM +ENDM + +;------------------------------------------------------------ +; +.enter MACRO localsize + IF USE286 EQ TRUE + enter localsize, 0 + ELSE + push bp + mov bp, sp + sub sp, localsize + ENDIF +ENDM + +;------------------------------------------------------------ +; +.leave MACRO argsize + IF USE286 EQ TRUE + leave + ELSE + mov sp, bp + pop bp + ENDIF + IFNB + ret argsize + ELSE + ret + ENDIF +ENDM + +;------------------------------------------------------------ +; +.shr MACRO arg, count + IF USE286 EQ TRUE + shr arg, count + ELSE + $temp = count + WHILE $temp GT 0 + shr arg, 1 + $temp = $temp-1 + ENDM + ENDIF +ENDM + +;------------------------------------------------------------ +; +.shl MACRO arg, count + IF USE286 EQ TRUE + shl arg, count + ELSE + $temp = count + WHILE $temp GT 0 + shl arg, 1 + $temp = $temp-1 + ENDM + ENDIF +ENDM + +;------------------------------------------------------------ +; +.chk386 MACRO name, jump + IF USE386 EQ FALSE + .OUT "Warning: ", , " needs a 386 or better to run!" + jmp @@jump + ENDIF +ENDM diff --git a/16/x/modex.h b/16/x/modex.h new file mode 100755 index 00000000..2c1f1ebe --- /dev/null +++ b/16/x/modex.h @@ -0,0 +1,153 @@ +/* + MODEX.H - C/C++ include file for the MODEX library + Copyright (c) 1994 Alessandro Scotti +*/ + +#ifndef _MODEX_H_ // Avoid nested inclusions +#define _MODEX_H_ + +// +// Video modes +// +#define MX_TEXT 0 // 80x25 text +#define MX_320x175 1 // 320x175x256 +#define MX_320x200 2 // 320x200x256, 4 pages, aspect 6:5 +#define MX_320x240 3 // 320x240x256, 3 pages, aspect 1:1 +#define MX_320x350 4 // 320x350x256 +#define MX_320x400 5 // 320x400x256, 2 pages +#define MX_320x480 6 // 320x480x256, 1 page +#define MX_360x175 7 // 360x175x256 +#define MX_360x200 8 // 360x200x256, 3 pages +#define MX_360x240 9 // 360x240x256, 2 pages +#define MX_360x350 10 // 360x350x256 +#define MX_360x400 11 // 360x400x256, 1 page +#define MX_360x480 12 // 360x480x256, 1 page +#define MX_400x600 13 // 400x600x256, 1 page + +// +// Fade effects +// +#define MX_FADEIN 0 +#define MX_FADEOUT 1 + +// +// Raster ops +// +#define OP_SET 0 // No operator +#define OP_AND 1 // And +#define OP_OR 2 // Or +#define OP_XOR 3 // Xor +#define OP_TRANS 4 // Transparent +#define OP_ADD 5 // Additive +#define OP_MOVE 0 // Alias for OP_SET + +// +// Temporary definitions +// +#define MXBYTE unsigned char +#define MXBOOL short int +#define MXSINT short int +#define MXUINT unsigned short int +#define MXAPI far pascal +#define MXPTR void far * + +// Functions + +#ifdef __cplusplus // Avoid C++ name mangling +extern "C" { +#endif + +// +// Initialization +// +MXSINT MXAPI mxInit( void ); // Returns 0 if successful +void MXAPI mxTerm( void ); +MXUINT MXAPI mxGetVersion( void ); +// +// Mode setting +// +void MXAPI mxChangeMode( MXUINT mode ); +void MXAPI mxSetMode( MXUINT mode ); +void MXAPI mxGetAspect( MXUINT far *aspectx, MXUINT far *aspecty ); +void MXAPI mxGetScreenSize( MXUINT far *width, MXUINT far *height ); +// +// Hardware support +// +void MXAPI mxWriteMode( MXBYTE wm ); +void MXAPI mxSplitScreen( MXUINT line ); +void MXAPI mxStartAddress( MXUINT sa ); +void MXAPI mxStartLine( MXUINT sl ); +void MXAPI mxWaitDisplay( void ); +void MXAPI mxWaitRetrace( void ); +void MXAPI mxWritePlane( MXBYTE wp ); +void MXAPI mxReadPlane( MXBYTE rp ); +void MXAPI mxRowAddress( MXBYTE ra ); +// +// Virtual screen +// +void MXAPI mxGetVirtualScreen( MXUINT far *width, MXUINT far *height ); +void MXAPI mxSetVirtualScreen( MXUINT width, MXUINT height ); +void MXAPI mxPan( MXUINT x, MXUINT y ); +// +// Clipping +// +MXBOOL MXAPI mxGetClip( void ); +MXBOOL MXAPI mxGetClipRegion( MXSINT far *x, MXSINT far *y, MXSINT far *w, MXSINT far *h ); +MXBOOL MXAPI mxSetClip( MXBOOL ); +void MXAPI mxSetClipRegion( MXUINT x, MXUINT y, MXUINT width, MXUINT height ); +// +// Graphics +// +void MXAPI mxBitBlt( MXSINT sx, MXSINT sy, MXUINT width, MXUINT height, MXSINT dx, MXSINT dy ); +void MXAPI mxFillBox( MXSINT x, MXSINT y, MXUINT width, MXUINT height, MXUINT color, MXUINT op ); +MXBYTE MXAPI mxGetPixel( MXSINT x, MXSINT y ); +void MXAPI mxPutPixel( MXSINT x, MXSINT y, MXBYTE color ); +void MXAPI mxLine( MXSINT x1, MXSINT y1, MXSINT x2, MXSINT y2, MXUINT color, MXUINT op ); +void MXAPI mxGetImage( MXPTR img, MXSINT x, MXSINT y, MXUINT width, MXUINT height ); +void MXAPI mxPutImage( MXPTR img, MXSINT x, MXSINT y, MXUINT w, MXUINT h, MXUINT op ); +void MXAPI mxPutTile( MXPTR tile, MXSINT x, MXSINT y, MXUINT width, MXUINT height ); +void MXAPI mxTransPutTile( MXPTR tile, MXSINT x, MXSINT y, MXUINT w, MXUINT h ); +void MXAPI mxCircle( MXSINT x, MXSINT y, MXUINT radius, MXBYTE color ); +void MXAPI mxStretchImage( MXPTR img, MXSINT x, MXSINT y, MXUINT w, MXUINT h, MXUINT neww, MXUINT newh, MXUINT op ); +// +// Palette +// +void MXAPI mxColorToGray( MXPTR source, MXPTR dest, MXUINT count ); +void MXAPI mxGammaCorrect( MXPTR source, MXPTR dest, MXUINT count ); +void MXAPI mxGetColor( MXUINT index, MXSINT far *r, MXSINT far *g, MXSINT far *b ); +void MXAPI mxSetColor( MXUINT index, MXSINT red, MXSINT green, MXSINT blue ); +void MXAPI mxGetPalette( MXPTR palette, MXUINT index, MXUINT count ); +void MXAPI mxSetPalette( MXPTR palette, MXUINT index, MXUINT count ); +void MXAPI mxFadePalette( MXPTR, MXUINT, MXUINT, MXUINT, MXUINT, MXUINT, MXUINT ); +void MXAPI mxRotatePalette( MXPTR palette, MXUINT count, MXSINT step ); +// +// Text +// +MXSINT MXAPI mxSetFont( MXPTR font, MXUINT charwidth, MXUINT charheight ); +void MXAPI mxSetTextColor( MXUINT color, MXUINT op ); +void MXAPI mxGetTextStep( MXSINT far *deltax, MXSINT far *deltay ); +void MXAPI mxSetTextStep( MXSINT deltax, MXSINT deltay ); +void MXAPI mxOutChar( MXSINT x, MXSINT y, char c ); +void MXAPI mxOutText( MXSINT x, MXSINT y, char far *sz ); +// +// Convex polygons +// +void MXAPI mxFillPoly( MXUINT, MXPTR, MXPTR, MXUINT, MXUINT ); +void MXAPI mxGouraudPoly( MXUINT, MXPTR, MXPTR, MXPTR, MXUINT, MXUINT ); +void MXAPI mxTexturePoly( MXUINT, MXPTR, MXPTR, MXPTR, MXPTR, MXUINT, MXUINT ); + +#ifdef __cplusplus +} +#endif + +// +// Remove temporary defines +// +#undef MXBYTE +#undef MXBOOL +#undef MXSINT +#undef MXUINT +#undef MXPTR +#undef MXAPI + +#endif // _MODEX_H_ diff --git a/16/x/modex.lbr b/16/x/modex.lbr new file mode 100755 index 00000000..93fc7801 --- /dev/null +++ b/16/x/modex.lbr @@ -0,0 +1,39 @@ ++-MXBB.OBJ & ++-MXCC.OBJ & ++-MXCG.OBJ & ++-MXCL.OBJ & ++-MXCR.OBJ & ++-MXFB.OBJ & ++-MXFP.OBJ & ++-MXGC.OBJ & ++-MXGI.OBJ & ++-MXGM.OBJ & ++-MXGP.OBJ & ++-MXGV.OBJ & ++-MXHL.OBJ & ++-MXIT.OBJ & ++-MXLL.OBJ & ++-MXLN.OBJ & ++-MXOT.OBJ & ++-MXPB.OBJ & ++-MXPF.OBJ & ++-MXPG.OBJ & ++-MXPI.OBJ & ++-MXPN.OBJ & ++-MXPP.OBJ & ++-MXPT.OBJ & ++-MXRA.OBJ & ++-MXRP.OBJ & ++-MXSA.OBJ & ++-MXSC.OBJ & ++-MXSI.OBJ & ++-MXSL.OBJ & ++-MXSM.OBJ & ++-MXSP.OBJ & ++-MXSS.OBJ & ++-MXTL.OBJ & ++-MXVS.OBJ & ++-MXWD.OBJ & ++-MXWM.OBJ & ++-MXWP.OBJ & ++-MXWR.OBJ diff --git a/16/x/modex.pas b/16/x/modex.pas new file mode 100755 index 00000000..7d9d26ed --- /dev/null +++ b/16/x/modex.pas @@ -0,0 +1,194 @@ +(* + Turbo Pascal interface to the MODEX library + Copyright (c) 1993,1994 by Alessandro Scotti +*) +unit ModeX; +interface + +const + (* Video modes *) + MX_TEXT = 0; + MX_320x175 = 1; + MX_320x200 = 2; + MX_320x240 = 3; + MX_320x350 = 4; + MX_320x400 = 5; + MX_320x480 = 6; + MX_360x175 = 7; + MX_360x200 = 8; + MX_360x240 = 9; + MX_360x350 = 10; + MX_360x400 = 11; + MX_360x480 = 12; + MX_400x600 = 13; + + (* Fade effects *) + MX_FADEIN = 0; + MX_FADEOUT = 1; + + (* Raster ops *) + OP_SET = 0; + OP_AND = 1; + OP_OR = 2; + OP_XOR = 3; + OP_TRANS = 4; + OP_ADD = 5; + OP_MOVE = 0; (* Alias for OP_SET *) + +procedure mxBitBlt( SX, SY: integer; Width, Height: word; DX, DY: integer ); +procedure mxCircle( CX, CY: integer; Radius: word; Color: byte ); +procedure mxChangeMode( Mode: word ); +procedure mxColorToGray( ColorPalette, GrayPalette: pointer; Count: word ); +procedure mxFadePalette( Palette: pointer; Cmd, Start, Count, R, G, B: word ); +procedure mxFillBox( X, Y: integer; Width, Height: word; Color: byte; Op: word ); +procedure mxGammaCorrect( ColorPalette, GammaPalette: pointer; Count: word ); +procedure mxGetAspect( var AspectX, AspectY: word ); +function mxGetClipRegion( var X1, Y1, Width, Height: word ): boolean; +function mxGetClip: boolean; +procedure mxGetImage( Image: pointer; X, Y: integer; Width, Height: word ); +procedure mxGetPalette( Palette: pointer; Start, Count: word ); +function mxGetPixel( X, Y: word ): byte; +procedure mxGetScreenSize( var Width, Height: word ); +procedure mxGetTextStep( var DeltaX, DeltaY: integer ); +function mxGetVersion: word; +procedure mxGetVirtualScreen( var Width, Height: word ); +procedure mxInit; +procedure mxLine( X1, Y1, X2, Y2: integer; Color, Op: word ); +procedure mxOutChar( X, Y: integer; C: char ); +procedure mxOutText( X, Y: integer; S: pointer ); +procedure mxPan( X, Y: word ); +procedure mxPutImage( Image: pointer; X, Y: integer; Width, Height, Op: word ); +procedure mxPutPixel( X, Y: word; C: byte ); +procedure mxPutTile( Tile: pointer; X, Y: integer; Width, Height: word ); +procedure mxReadPlane( Plane: byte ); +procedure mxRotatePalette( Palette: pointer; Count: word; Step: integer ); +procedure mxRowAddress( RowAddress: byte ); +function mxSetClip( Clip: boolean ): boolean; +procedure mxSetClipRegion( X1, Y1, Width, Height: word ); +procedure mxSetColor( Index, R, G, B: word ); +procedure mxSetFont( Font: pointer; Width, Height: word ); +procedure mxSetMode( Mode: word ); +procedure mxSetPalette( Palette: pointer; Start, Count: word ); +procedure mxSetTextColor( Color, Op: word ); +procedure mxSetTextStep( DeltaX, DeltaY: integer ); +procedure mxSetVirtualScreen( Width, Height: word ); +procedure mxStretchImage( Image: pointer; X, Y: integer; Width, Height, NewWidth, NewHeight, Op: word ); +procedure mxSplitScreen( Line: word ); +procedure mxStartAddress( StartAddress: word ); +procedure mxStartLine( Line: word ); +procedure mxTerm; +procedure mxTransPutTile( Tile: pointer; X, Y: integer; Width, Height: word ); +procedure mxWaitDisplay; +procedure mxWaitRetrace; +procedure mxWriteMode( Mode: byte ); +procedure mxWritePlane( Plane: byte ); + +procedure mxFillPoly( Count: word; var Map, Points; Color: word ); +procedure mxGouraudPoly( Count: word; var Map, Points, Colors; BaseColor: word ); +procedure mxTexturePoly( Count: word; var Map, Points, ImgPoints, Texture; Width: word ); + +procedure mxOutStr( X, Y: integer; S: string ); + +implementation + +procedure mxBitBlt; external; +procedure mxChangeMode( Mode: word ); external; +procedure mxCircle; external; +procedure mxColorToGray; external; +procedure mxFadePalette; external; +procedure mxFillBox; external; +procedure mxGammaCorrect; external; +procedure mxGetAspect( var AspectX, AspectY: word ); external; +function mxGetClipRegion; external; +function mxGetClip: boolean; external; +procedure mxGetImage; external; +procedure mxGetPalette( Palette: pointer; Start, Count: word ); external; +function mxGetPixel( X, Y: word ): byte; external; +procedure mxGetScreenSize( var Width, Height: word ); external; +procedure mxGetTextStep( var DeltaX, DeltaY: integer ); external; +function mxGetVersion: word; external; +procedure mxGetVirtualScreen( var Width, Height: word ); external; +procedure mxInit; external; +procedure mxLine( X1, Y1, X2, Y2: integer; Color, Op: word ); external; +procedure mxOutChar( X, Y: integer; C: char ); external; +procedure mxOutText( X, Y: integer; S: pointer ); external; +procedure mxPan( X, Y: word ); external; +procedure mxPutImage; external; +procedure mxPutPixel( X, Y: word; C: byte ); external; +procedure mxPutTile; external; +procedure mxReadPlane( Plane: byte ); external; +procedure mxRotatePalette; external; +procedure mxRowAddress( RowAddress: byte ); external; +function mxSetClip( Clip: boolean ): boolean; external; +procedure mxSetClipRegion( X1, Y1, Width, Height: word ); external; +procedure mxSetColor( Index, R, G, B: word ); external; +procedure mxSetFont( Font: pointer; Width, Height: word ); external; +procedure mxSetMode( Mode: word ); external; +procedure mxSetPalette( Palette: pointer; Start, Count: word ); external; +procedure mxSetTextColor( Color, Op: word ); external; +procedure mxSetTextStep( DeltaX, DeltaY: integer ); external; +procedure mxSetVirtualScreen( Width, Height: word ); external; +procedure mxSplitScreen( Line: word ); external; +procedure mxStartAddress( StartAddress: word ); external; +procedure mxStartLine; external; +procedure mxStretchImage; external; +procedure mxTerm; external; +procedure mxTransPutTile; external; +procedure mxWaitDisplay; external; +procedure mxWaitRetrace; external; +procedure mxWriteMode( Mode: byte ); external; +procedure mxWritePlane( Plane: byte ); external; + +procedure mxFillPoly; external; +procedure mxGouraudPoly; external; +procedure mxTexturePoly; external; +{$L MXPB} +{$L MXPF} +{$L MXPG} +{$L MXPT} + +{$L MXBB} +{$L MXCC} +{$L MXCG} +{$L MXCL} +{$L MXCR} +{$L MXFB} +{$L MXFP} +{$L MXGI} +{$L MXGM} +{$L MXGP} +{$L MXGV} +{$L MXHL} +{$L MXIT} +{$L MXLN} +{$L MXOT} +{$L MXPI} +{$L MXPN} +{$L MXPP} +{$L MXRA} +{$L MXRP} +{$L MXSA} +{$L MXSC} +{$L MXSI} +{$L MXSL} +{$L MXSM} +{$L MXSP} +{$L MXSS} +{$L MXTL} +{$L MXVS} +{$L MXWD} +{$L MXWM} +{$L MXWP} +{$L MXWR} + +(* + Prints a Turbo Pascal string. + Note: BP 7.0 supports ASCIIZ strings (PChar type). +*) +procedure mxOutStr; +begin + S := S + #0; + mxOutText( X, Y, @S[1] ); +end; + +end. diff --git a/16/x/modex/DEMO01.EXE b/16/x/modex/DEMO01.EXE new file mode 100755 index 00000000..28caff88 Binary files /dev/null and b/16/x/modex/DEMO01.EXE differ diff --git a/16/x/modex/DEMO01.PAS b/16/x/modex/DEMO01.PAS new file mode 100755 index 00000000..c684acdd --- /dev/null +++ b/16/x/modex/DEMO01.PAS @@ -0,0 +1,126 @@ +(* + DEMO01 - Sprites, page flipping and palette rotation + Copyright (c) 1994 Alessandro Scotti +*) +uses Crt, Modex; + +const + MAX_SPRITE = 100; +type + (* Sprite structure *) + TSprite = record + X, Y : integer; (* Sprite coordinates *) + DX,DY: integer; (* Deltas for sprite movement *) + W, H : integer; (* Sprite width and height *) + Image: array[ 1..16, 1..16 ] of byte; (* Sprite image data *) + end; + (* RGB color structure *) + TRgb = record + R, G, B: byte; + end; +var + S : array[ 1..MAX_SPRITE ] of TSprite; (* An array of sprites *) + Palette: array[ byte ] of TRgb; (* Palette *) + Page : word; (* Page offset *) + I : word; + +(* Initializes a sprite structure *) +procedure sxInit( var S: TSprite ); +var + I: word; +begin + S.X := Random( 320 ); (* Initialize position with random values *) + S.Y := Random( 240 ); + S.DX := Random( 7 )-3; (* Initialize speed with random values *) + S.DY := Random( 7 )-3; + S.W := 16; (* Size is fixed in this program *) + S.H := 16; + (* The image is a square with a hole inside *) + FillChar( S.Image, SizeOf(S.Image), Random(15)+1 ); + for I:=5 to 12 do FillChar( S.Image[ I, 5 ], 8, 0 ); +end; + +(* Moves a sprite *) +procedure sxMove( var S: TSprite ); +begin + Inc( S.X, S.DX ); (* Get new position *) + Inc( S.Y, S.DY ); + (* Check sprite position, change delta if needed *) + if( S.X > 320 ) then begin + S.X := 320; + S.DX := -S.DX; + end; + if( S.X < -16 ) then begin + S.X := -16; + S.DX := -S.DX; + end; + if( S.Y > 240 ) then begin + S.Y := 240; + S.DY := -S.DY; + end; + if( S.Y < -16 ) then begin + S.Y := -16; + S.DY := -S.DY; + end; + (* Draw the sprite, note the Page offset added to the *) + (* Y coordinate of the image *) + mxPutImage( @S.Image, S.X, Page+S.Y, S.W, S.H, OP_TRANS ); +end; + +begin + (* Initialize library *) + mxInit; + + (* Enter graphics mode *) + mxSetMode( MX_320x240 ); + + (* Print initialization message *) + mxSetTextColor( 15, OP_TRANS ); + mxOutStr( 4, 4, 'Initializing...' ); + + (* Initialize sprites *) + for I:=1 to MAX_SPRITE do sxInit( S[I] ); + + (* Draw background *) + for I:=1 to 192 do begin + mxCircle( 160, 480+120, I, I+63 ); + mxCircle( 161, 480+120, I, I+63 ); + end; + + (* Compute and set palette *) + for I:=1 to 192 do with Palette[I+63] do begin + R := 0; + G := 0; + B := 0; + if( I < 64 ) then + R := I shr 1+31 + else if( I < 128 ) then + G := (I-64) shr 1+31 + else + B := (I-128) shr 1+31; + end; + mxSetPalette( @Palette[64], 64, 192 ); + + (* Main loop *) + Page := 240; + while( not KeyPressed ) do begin + (* Set clip region to current page *) + mxSetClipRegion( 0, Page, 320, 240 ); + mxSetClip( TRUE ); + (* Restore background *) + mxBitBlt( 0, 480, 320, 240, 0, Page ); + (* Draw sprites *) + for I:=1 to MAX_SPRITE do sxMove( S[I] ); + (* Print message *) + mxOutStr( 4, Page+4, 'Some sprites moving...' ); + (* Flip page *) + mxStartLine( Page ); + Page := 240-Page; + (* Animate palette *) + mxSetPalette( @Palette[64], 64, 192 ); + mxRotatePalette( @Palette[64], 192, 3 ); + end; + + mxSetMode( MX_TEXT ); + mxTerm; +end. diff --git a/16/x/modex/DEMO02.EXE b/16/x/modex/DEMO02.EXE new file mode 100755 index 00000000..14e7dc72 Binary files /dev/null and b/16/x/modex/DEMO02.EXE differ diff --git a/16/x/modex/DEMO02.PAS b/16/x/modex/DEMO02.PAS new file mode 100755 index 00000000..6b4fb6f9 --- /dev/null +++ b/16/x/modex/DEMO02.PAS @@ -0,0 +1,125 @@ +(* + DEMO02 - Texture mapping and palette rotation + (c) 1994 by Alessandro Scotti +*) +uses Crt, Modex, Plasma, Threed; + +const + LSIZE = 85; + Trans : TPoint = ( X:0; Y:0; Z:0 ); +type + T2DPoint = record + X, Y: integer; + end; + TTexture = record + Desc : array[ 0..3 ] of T2DPoint; + Width : word; + Data : array[ 1..64*64 ] of byte; + end; + TQuad = record + VtxCnt : word; + Vtx : array[ 0..3 ] of word; + Texture: word; + end; +var + Vtx : array[ 0..7 ] of TPoint; + XVtx : array[ 0..7 ] of TPoint; + VVtx : array[ 0..7 ] of T2DPoint; + Face : array[ 0..5 ] of TQuad; + Txts : array[ 0..5 ] of TTexture; + Nrm : array[ 0..5 ] of TPoint; + XNrm : array[ 0..5 ] of TPoint; + Page : word; + Palette: array[ byte ] of record R, G, B: byte; end; + +(* Make a 64x64 plasma to be used as texture *) +procedure MakeTexture( Idx: word ); +var + I: word; +begin + mxFillBox( 0, 0, 64, 64, 0, OP_SET ); + MakePlasma( 0, 0, 64, 64, 96, Random(192)+1, Random(192)+1, Random(192)+1 ); + mxGetImage( @Txts[Idx].Data, 0, 0, 64, 64 ); + (* Texture vertexes are 8:8 fixed, add $80 (0.5) for best results *) + with Txts[Idx] do begin + Desc[0].X := $80; Desc[0].Y := $80; + Desc[1].X := $80; Desc[1].Y := $3F80; + Desc[2].X := $3F80; Desc[2].Y := $3F80; + Desc[3].X := $3F80; Desc[3].Y := $80; + Width := 64; + end; +end; + +procedure Init; +var + I: integer; +begin + (* Build vertexes for a cube *) + with Vtx[0] do begin X:=-LSIZE; Y:=-LSIZE; Z:=-LSIZE; end; + with Vtx[1] do begin X:=+LSIZE; Y:=-LSIZE; Z:=-LSIZE; end; + with Vtx[2] do begin X:=-LSIZE; Y:=+LSIZE; Z:=-LSIZE; end; + with Vtx[3] do begin X:=+LSIZE; Y:=+LSIZE; Z:=-LSIZE; end; + with Vtx[4] do begin X:=-LSIZE; Y:=-LSIZE; Z:=+LSIZE; end; + with Vtx[5] do begin X:=+LSIZE; Y:=-LSIZE; Z:=+LSIZE; end; + with Vtx[6] do begin X:=-LSIZE; Y:=+LSIZE; Z:=+LSIZE; end; + with Vtx[7] do begin X:=+LSIZE; Y:=+LSIZE; Z:=+LSIZE; end; + for I:=0 to 7 do begin (* Make points 16:16 fixed *) + Vtx[I].X := Vtx[I].X*$10000; + Vtx[I].Y := Vtx[I].Y*$10000; + Vtx[I].Z := Vtx[I].Z*$10000; + end; + (* Build faces *) + with Face[0] do begin Vtx[0]:=0; Vtx[1]:=2; Vtx[2]:=3; Vtx[3]:=1; end; + with Face[1] do begin Vtx[0]:=4; Vtx[1]:=5; Vtx[2]:=7; Vtx[3]:=6; end; + with Face[2] do begin Vtx[0]:=0; Vtx[1]:=1; Vtx[2]:=5; Vtx[3]:=4; end; + with Face[3] do begin Vtx[0]:=1; Vtx[1]:=3; Vtx[2]:=7; Vtx[3]:=5; end; + with Face[4] do begin Vtx[0]:=2; Vtx[1]:=0; Vtx[2]:=4; Vtx[3]:=6; end; + with Face[5] do begin Vtx[0]:=7; Vtx[1]:=3; Vtx[2]:=2; Vtx[3]:=6; end; + for I:=0 to 5 do Face[I].Texture := I; + (* Build textures and palette *) + Randomize; + FillChar( Palette, SizeOf(Palette), 0 ); + MakePlasmaPalette( Palette, PAL_RGB ); + mxSetPalette( @Palette, 0, 193 ); + for I:=0 to 5 do MakeTexture( I ); +end; + +var + AX, AY, AZ: byte; + I: word; +begin + mxInit; + mxSetMode( MX_320x240 ); + Init; + Page := 240; (* Start with hidden page *) + + AX := 0; + AY := 0; + AZ := 0; + (* Init 3D transforms, perspective is intentionally exaggerated *) + tdSetTranslation( Trans ); + tdSetPerspective( 400*$10000, $10000, $10000 ); + (* Main loop, all magic here! *) + while( not KeyPressed ) do begin + tdSetRotation( AX, AY, AZ ); (* Set new angles *) + tdTransform( Vtx, XVtx, 8 ); (* 3D transform points *) + tdTransformToImage( XVtx, VVtx, 8, 160, 120+Page ); + Inc( AX, 1 ); (* Bump angles *) + Inc( AY, 1 ); + Inc( AZ, 2 ); + mxSetClipRegion( 0, Page, 320, 240 ); (* Set clip to new page *) + mxSetClip( TRUE ); + mxFillBox( 0, Page, 320, 240, 0, OP_MOVE ); (* Clear screen *) + mxRotatePalette( @Palette[1], 192, 3 ); (* Rotate palette *) + (* Draw cube: backface culling is straighforward in this case, so *) + (* it can be handled by the polygon filling procedure *) + for I:=0 to 5 do + mxTexturePoly( 4, Face[I].Vtx, VVtx, Txts[I].Desc, Txts[I].Data, Txts[I].Width ); + mxStartLine( Page ); (* Flip pages *) + mxSetPalette( @Palette[1], 1, 192 ); (* Set new palette *) + Page := 240-Page; + end; + + mxSetMode( MX_TEXT ); + mxTerm; +end. diff --git a/16/x/modex/DEMO03.EXE b/16/x/modex/DEMO03.EXE new file mode 100755 index 00000000..c646c4b0 Binary files /dev/null and b/16/x/modex/DEMO03.EXE differ diff --git a/16/x/modex/DEMO03.PAS b/16/x/modex/DEMO03.PAS new file mode 100755 index 00000000..01d10f49 --- /dev/null +++ b/16/x/modex/DEMO03.PAS @@ -0,0 +1,152 @@ +(* + DEMO03 - Simple star animation, morphs between a cube and a sphere + (c) 1994 by Alessandro Scotti +*) +uses Crt, Modex, Threed; + +const + MAXVTX = 1000; (* Number of points *) + EDGE = 70; (* Length of cube edge *) + RADIUS = 90; (* Radius of sphere *) + WAITCOUNT = 192; (* Frames to wait for non-morphing shapes *) + MS = 32; (* Number of steps for morphing *) + Trans : TPoint = ( X:0; Y:0; Z:0 ); + InitMorph1: array[ 0..3 ] of integer = ( 0, MS, 0, 0 ); + InitMorph2: array[ 0..3 ] of integer = ( 0, 0, 0, MS ); + InitDelta1: array[ 0..3 ] of integer = ( 0, -1, 0, +1 ); + InitDelta2: array[ 0..3 ] of integer = ( 0, +1, 0, -1 ); +type + T2DPoint = record + X, Y: integer; + end; + T3DPointArray = array[ 0..MAXVTX-1 ] of TPoint; + P3DPointArray = ^T3DPointArray; +var + CubeVtx, SphereVtx, Vtx, XVtx: P3DPointArray; + VVtx : array[ 0..MAXVTX-1 ] of T2DPoint; + Page : word; + Status, Count, Delta1, Delta2, Morph1, Morph2: integer; + +procedure Swap( var A, B: longint ); +var + L: longint; +begin + L := A; A := B; B := L; +end; + +function Toggle( A: longint ): longint; +begin + Toggle := A; + if( Random(2) = 0 ) then Toggle := -A; +end; + +procedure Init; +label Retry; +var + I: integer; +begin + New( CubeVtx ); + New( SphereVtx ); + New( Vtx ); + New( XVtx ); + (* Build vertexes (yes, I know this piece of code is terrible) *) + Randomize; + for I:=0 to MAXVTX-1 do begin + with CubeVtx^[I] do begin + (* Build cube *) + X := (longint(Random(2*EDGE))-EDGE)*$10000; + Y := (longint(Random(2*EDGE))-EDGE)*$10000; + Z := Toggle( EDGE*$10000 ); + case Random(3) of + 0: Swap( X, Z ); + 1: Swap( Y, Z ); + end; + end; + with SphereVtx^[I] do begin + (* Build sphere *) +Retry: + X := (longint(Random(2*RADIUS))-RADIUS); + Y := (longint(Random(2*RADIUS))-RADIUS); + if( X*X+Y*Y > RADIUS*RADIUS ) then goto Retry; + Z := Toggle( Round( Sqrt( Abs( RADIUS*RADIUS-X*X-Y*Y ) ) ) ); + case Random(3) of + 0: Swap( X, Z ); + 1: Swap( Y, Z ); + end; + X := X * $10000; Y := Y * $10000; Z := Z * $10000; + end; + end; + (* Initialize morphing *) + Move( CubeVtx^, Vtx^, SizeOf(Vtx^) ); + Status := 0; + Count := WAITCOUNT; +end; + +procedure Morph; +var + I: integer; +begin + (* Fully unoptimized, slowest loop I could think of! *) + for I:=0 to MAXVTX-1 do begin + Vtx^[I].X := ((CubeVtx^[I].X * Morph1)+(SphereVtx^[I].X * Morph2)) div MS; + Vtx^[I].Y := ((CubeVtx^[I].Y * Morph1)+(SphereVtx^[I].Y * Morph2)) div MS; + Vtx^[I].Z := ((CubeVtx^[I].Z * Morph1)+(SphereVtx^[I].Z * Morph2)) div MS; + end; +end; + +var + AX, AY, AZ: byte; + I: word; + C: char; +begin + mxInit; + mxSetMode( MX_320x240 ); + Init; + Page := 240; (* Start with hidden page *) + + AX := 0; + AY := 0; + AZ := 0; + (* Init 3D transforms, perspective is intentionally exaggerated *) + tdSetTranslation( Trans ); + tdSetPerspective( 400*$10000, $10000, $10000 ); + C := #0; + repeat + tdSetRotation( AX, AY, AZ ); (* Set new angles *) + tdTransform( Vtx^, XVtx^, MAXVTX ); (* 3D transform points *) + tdTransformToImage( XVtx^, VVtx, MAXVTX, 160, 120+Page ); + Inc( AX, 1 ); (* Bump angles *) + Inc( AY, 1 ); + Inc( AZ, 2 ); + mxSetClipRegion( 0, Page, 320, 240 ); (* Set clip to new page *) + mxSetClip( TRUE ); + mxFillBox( 0, Page, 320, 240, 0, OP_MOVE ); (* Clear screen *) + (* Draw points *) + for I:=0 to MAXVTX-1 do + mxPutPixel( VVtx[I].X, VVtx[I].Y, 128 + XVtx^[I].Z shr 18 ); + mxStartLine( Page ); (* Flip pages *) + Page := 240-Page; + (* Morph *) + if( Odd(Status) ) then begin + Morph; + Inc( Morph1, Delta1 ); + Inc( Morph2, Delta2 ); + if( Morph1 < 0 )or( Morph2 < 0 ) then Inc( Status ); + if( Status = 4 ) then Status := 0; + end + else begin + Dec( Count ); + if( Count < 0 ) then begin + Inc( Status ); + Count := WAITCOUNT; + Morph1 := InitMorph1[Status]; + Morph2 := InitMorph2[Status]; + Delta1 := InitDelta1[Status]; + Delta2 := InitDelta2[Status]; + end; + end; + until( KeyPressed ); + + mxSetMode( MX_TEXT ); + mxTerm; +end. diff --git a/16/x/modex/DEMO04.DAT b/16/x/modex/DEMO04.DAT new file mode 100755 index 00000000..72aaad08 Binary files /dev/null and b/16/x/modex/DEMO04.DAT differ diff --git a/16/x/modex/DEMO04.EXE b/16/x/modex/DEMO04.EXE new file mode 100755 index 00000000..1fec5e8a Binary files /dev/null and b/16/x/modex/DEMO04.EXE differ diff --git a/16/x/modex/DEMO04.PAS b/16/x/modex/DEMO04.PAS new file mode 100755 index 00000000..1a946315 --- /dev/null +++ b/16/x/modex/DEMO04.PAS @@ -0,0 +1,198 @@ +(* + DEMO04 - Multiple textures and triple buffering (3 pages) + (c) 1994 by Alessandro Scotti +*) +uses Crt, Modex, Threed; + +const + MAXVTX = 256; + MAXCUB = 2; + MAXTXT = 2; + Trans : TPoint = ( X:0; Y:0; Z:0 ); + TxtSunDial: array[ 0..7 ] of word = ( + $7F80,$0080, $0080,$0080, $0080,$7E80, $7F80,$7E80 ); + TxtSapphire : array[ 0..7 ] of word = ( + $0080,$0080, $0080,$1F80, $1F80,$1F80, $1F80,$0080 ); + TxtMarble: array[ 0..7 ] of word = ( + $0080,$8080, $0080,$FD80, $7F80,$FD80, $7F80,$8080 ); +type + T2DPoint = record + X, Y: integer; + end; + TTexture = record + Desc : array[ 0..3 ] of record X, Y: word end; + Width : word; + Data : pointer; + end; + TQuad = record + Vtx : array[ 0..3 ] of word; + Texture: word; + end; + TCube = record + Face : array[ 0..5 ] of TQuad; + Base : integer; + end; +var + Vtx, XVtx: array[ 0..MAXVTX ] of TPoint; + VVtx : array[ 0..MAXVTX ] of T2DPoint; + Cube : array[ 0..MAXCUB ] of TCube; + ZList : array[ 0..MAXCUB ] of integer; + VtxCnt : word; + Txts : array[ 0..MAXTXT ] of TTexture; + Page : word; + Palette : array[ byte ] of record R, G, B: byte; end; + TxtDat1, TxtDat2: pointer; + +(* Add a new entry to the vertex array *) +procedure AddVtx( PX, PY, PZ: longint ); +begin + with Vtx[VtxCnt] do begin X:=PX*$10000; Y:=PY*$10000; Z:=PZ*$10000; end; + Inc( VtxCnt ); +end; + +procedure MakeCube( var C: TCube; X1,Y1,Z1, X2,Y2,Z2, TX,TY,TZ, Texture: integer ); +const + FaceIdx: array[ 0..23 ] of integer = ( + 0,1,2,3, 0,4,5,1, 1,5,6,2, 2,6,7,3, 3,7,4,0, 6,5,4,7 ); +var + I, VC: integer; +begin + VC := VtxCnt; + C.Base := VC; + AddVtx( X1+TX, Y1+TY, Z1+TZ ); + AddVtx( X2+TX, Y1+TY, Z1+TZ ); + AddVtx( X2+TX, Y2+TY, Z1+TZ ); + AddVtx( X1+TX, Y2+TY, Z1+TZ ); + AddVtx( X1+TX, Y1+TY, Z2+TZ ); + AddVtx( X2+TX, Y1+TY, Z2+TZ ); + AddVtx( X2+TX, Y2+TY, Z2+TZ ); + AddVtx( X1+TX, Y2+TY, Z2+TZ ); + for I:=0 to 23 do C.Face[I shr 2].Vtx[I and 3] := VC+FaceIdx[I]; + for I:=0 to 5 do C.Face[I].Texture := Texture; +end; + +procedure MakeTexture( Idx: integer; var VtxData ); +var + P: ^word; + I: integer; +begin + P := @VtxData; + with Txts[Idx] do begin + for I:=0 to 3 do begin + Desc[I].X := P^; Inc( P ); + Desc[I].Y := P^; Inc( P ); + end; + Width := 129; + Data := TxtDat1; + end; +end; + +procedure Init; +var + I: integer; + V: integer; + F: file; + P: array[ 1..768 ] of byte; +begin + (* Initialize objects *) + VtxCnt := 0; + MakeCube( Cube[0], -64,-64,8, 64,64,-8, 0,0,0, 1 ); (* Sundial *) + Cube[0].Face[0].Texture := 0; + V := VtxCnt; + MakeCube( Cube[1], -16,-16,16, 16,16,-16, 0,0,0, 2 ); (* Sapphire *) + tdSetTranslation( Trans ); + tdSetRotation( 32, 32, 00 ); + tdRotate( Vtx[V], XVtx[V], 8 ); (* Got to rotate this cube *) + for I:=V to V+7 do begin + Vtx[I].X := XVtx[I].X; + Vtx[I].Y := XVtx[I].Y; + Vtx[I].Z := XVtx[I].Z + 100*$10000; + end; + MakeCube( Cube[2], -64,-4,48, 64,4,-48, 0,68,56, 1 ); (* Marble *) + (* Load texture and palette *) + Assign( F, 'DEMO04.DAT' ); + Reset( F, 1 ); + BlockRead( F, P, SizeOf(P) ); + mxSetPalette( @P, 0, 256 ); + GetMem( TxtDat1, 63*1024 ); + BlockRead( F, TxtDat1^, 129*286 ); + Close( F ); + TxtDat2 := Ptr( Seg(TxtDat1^), Ofs(TxtDat1^)+129*254 ); + (* Init textures *) + MakeTexture( 0, TxtSundial ); + MakeTexture( 1, TxtMarble ); + MakeTexture( 2, TxtSapphire ); + Txts[2].Data := TxtDat2; +end; + +(* Sort procedure, not worth optimizing with only a few objects *) +procedure SortObjects; +var + I, J, K: integer; + ZMax: array[ 0..MAXCUB ] of longint; + ZI: integer; + L: longint; +begin + for I:=0 to MAXCUB do begin + L := XVtx[Cube[I].Base].Z; + for J:=1 to 7 do + if( L > XVtx[Cube[I].Base+J].Z ) then L := XVtx[Cube[I].Base+J].Z; + ZMax[I] := L; + ZList[I] := I; + end; + for I:=0 to MAXCUB-1 do begin + ZI := I; + for J:=I+1 to MAXCUB do + if( ZMax[ZList[J]] > ZMax[ZList[ZI]] ) then ZI := J; + if( ZI <> I ) then begin + K := ZList[I]; + ZList[I] := ZList[ZI]; + ZList[ZI] := K; + end; + end; +end; + +var + AX, AY, AZ: byte; + I, J, K: word; +begin + mxInit; + mxSetMode( MX_320x240 ); + Init; + Page := 240; (* Start with hidden page *) + + (* Init 3D transforms, perspective is intentionally exaggerated *) + AX := 0; AY := 0; AZ := 0; + tdSetTranslation( Trans ); + tdSetPerspective( 600*$10000, $10000, $10000 ); + (* Main loop, all magic here! *) + while( not KeyPressed ) do begin + tdSetRotation( AX, AY, AZ ); (* Set new angles *) + tdTransform( Vtx, XVtx, VtxCnt ); (* 3D transform points *) + tdTransformToImage( XVtx, VVtx, VtxCnt, 160, 120+Page ); + Inc( AX, 1 ); (* Bump angles *) + Inc( AY, 2 ); + Inc( AZ, 1 ); + mxSetClipRegion( 0, Page, 320, 240 ); (* Set clip to new page *) + mxSetClip( TRUE ); + mxFillBox( 0, Page, 320, 240, 0, OP_MOVE ); (* Clear screen *) + (* Draw objects *) + SortObjects; + for I:=0 to MAXCUB do with Cube[ZList[I]] do begin + for J:=0 to 5 do begin + K := Face[J].Texture; + mxTexturePoly( 4, Face[J].Vtx, VVtx, Txts[K].Desc, Txts[K].Data^, Txts[K].Width ); + end; + end; + (* Flip page: at 320x240 the Start Address Register Low is always zero *) + case Page of + 0 : begin PortW[$3D4] := $000C; Page := 240; end; + 240: begin PortW[$3D4] := $4B0C; Page := 480; end; + 480: begin PortW[$3D4] := $960C; Page := 0; end; + end; + mxWaitRetrace; (* If the frame rate seems low, try to remove this line *) + end; + + mxSetMode( MX_TEXT ); + mxTerm; +end. diff --git a/16/x/modex/DEMO05.EXE b/16/x/modex/DEMO05.EXE new file mode 100755 index 00000000..21a7c207 Binary files /dev/null and b/16/x/modex/DEMO05.EXE differ diff --git a/16/x/modex/DEMO05.PAS b/16/x/modex/DEMO05.PAS new file mode 100755 index 00000000..819c5cf3 --- /dev/null +++ b/16/x/modex/DEMO05.PAS @@ -0,0 +1,131 @@ +(* + DEMO05 - A Gouraud-shaded rotating torus + (c) 1994 Alessandro Scotti +*) +uses Crt, Modex, Threed; + +(* Define ALTPAL for alternate palette *) +{$define ALTPAL} + +const + MAXVTX1 = 15; RADIUS1 = 70; (* MAXVTX1+1 must be multiple of 4 *) + MAXVTX2 = 15; RADIUS2 = 30; + MAXVTX = (MAXVTX1+1)*(MAXVTX2+1)-1; + MAXFACE = MAXVTX; + Trans : TPoint = ( X:0; Y:0; Z:0 ); (* Object translation *) + Light : TPoint = ( X:0; Y:0; Z:-63*$10000 ); (* Light direction *) +type + TQuad = record + QVtx : array[ 0..3 ] of integer; + end; +var + Vtx, XVtx : array[ 0..MAXVTX ] of TPoint; (* Points *) + VVtx : array[ 0..MAXVTX ] of record X, Y: integer end; + Face : array[ 0..MAXFACE ] of TQuad; (* Polys *) + Culled : array[ 0..MAXFACE ] of integer; + GNrm,XGNrm: array[ 0..MAXVTX ] of TVector; (* Gouraud normals *) + VtxLight : array[ 0..MAXVTX ] of integer; (* Points brightness *) + Page : word; + +function GetVtx( I1, I2: integer ): integer; +begin + GetVtx := (I1 mod (MAXVTX1+1))*(MAXVTX2+1) + I2 mod (MAXVTX2+1); +end; + +procedure Init; +var + R, N, X, Y, Z: real; + I, J, K, V: integer; +begin + (* Build vertexes *) + for I:=0 to MAXVTX1 do begin + K := (I + (MAXVTX1+1) shr 2) mod (MAXVTX1+1); + R := RADIUS1 + RADIUS2*Cos( 2*K*Pi / (MAXVTX1+1) ); + for J:=0 to MAXVTX2 do begin + V := I*(MAXVTX2+1)+J; (* Index of current vertex *) + (* Compute coordinates of current vertex *) + X := R*Cos(2*J*Pi / (MAXVTX2+1)); (* Get coordinates *) + Y := R*Sin(2*J*Pi / (MAXVTX2+1)); + Z := RADIUS2*Sin(2*K*Pi / (MAXVTX1+1)); + Vtx[V].X := Round( X )*$10000; (* Save coordinates *) + Vtx[V].Y := Round( Y )*$10000; + Vtx[V].Z := Round( Z )*$10000; + (* Compute direction of Gouraud normal thru current vertex *) + X := X - RADIUS1*Cos(2*J*Pi / (MAXVTX2+1)); + Y := Y - RADIUS1*Sin(2*J*Pi / (MAXVTX2+1)); + N := Sqrt( X*X + Y*Y + Z*Z ); (* Get vector length *) + GNrm[V].X := Trunc( X*$10000/N ); (* Save normal vector *) + GNrm[V].Y := Trunc( Y*$10000/N ); + GNrm[V].Z := Trunc( Z*$10000/N ); + end; + end; + (* Generate faces so that depth-sorting is not needed: there are still *) + (* some *very* little errors, but this is the best I could devise *) + J := 0; + K := 0; + for I:=0 to MAXFACE do with Face[I] do begin + QVtx[0] := GetVtx( J, K ); + QVtx[1] := GetVtx( J, K+1 ); + QVtx[2] := GetVtx( J+1, K+1 ); + QVtx[3] := GetVtx( J+1, K ); + Inc( K ); + if( K > MAXVTX2 ) then begin + K := 0; + Inc( J ); + end; + end; +{$ifndef ALTPAL} + for I:=0 to 63 do mxSetColor( I+64, 0, 0, I ); (* Blue palette *) +{$else} + for I:=0 to 31 do mxSetColor(I+64, 0, I shl 1, 0); (* Green neon palette *) + for I:=32 to 63 do mxSetColor ( I+64, (I-32) shl 1, 63, (I-32) shl 1 ); +{$endif} +end; + +var + AX, AY, AZ: byte; + I: word; +begin + mxInit; + mxSetMode( MX_320x240 ); + Init; + Page := 240; (* Start with hidden page *) + + AX := 0; + AY := 0; + AZ := 0; + (* Init 3D transforms, perspective is intentionally exaggerated *) + tdSetTranslation( Trans ); + tdSetLight( Light ); + tdSetPerspective( 400*$10000, $10000, $10000 ); + (* Main loop, all magic here! *) + while( not KeyPressed ) do begin + tdSetRotation( AX, AY, AZ ); (* Set new angles *) + tdTransform( Vtx, XVtx, MAXVTX+1 ); (* 3D transform points *) + tdTransformToImage( XVtx, VVtx, MAXVTX+1, 160, 120+Page ); + tdRotate( GNrm, XGNrm, MAXVTX+1 ); (* Rotate Gouraud normals *) + tdTransformLight( XGNrm, VtxLight, MAXVTX+1 ); + (* Backplane culling is not really needed here! *) + FillChar( Culled, SizeOf(Culled), 0 ); + tdBackPlaneCull( Face, XVtx, Culled, MAXFACE+1, SizeOf(TQuad) ); + Inc( AX, 1 ); (* Bump angles *) + Inc( AY, 2 ); + Inc( AZ, 3 ); + mxSetClipRegion( 0, Page, 320, 240 ); (* Set clip to new page *) + mxSetClip( TRUE ); + mxFillBox( 0, Page, 320, 240, 0, OP_MOVE ); (* Clear screen *) + (* Draw polygons *) + for I:=0 to MAXFACE do with Face[I] do + if( Culled[I] >= 0 ) then mxGouraudPoly( 4, QVtx, VVtx, VtxLight, 64 ); + (* Flip page: at 320x240 the Start Address Register Low is always zero *) + case Page of + 0 : begin PortW[$3D4] := $000C; Page := 240; end; + 240: begin PortW[$3D4] := $4B0C; Page := 480; end; + 480: begin PortW[$3D4] := $960C; Page := 0; end; + end; + mxWaitRetrace; (* Uncomment this instruction if screen flickers *) + end; + + mxSetMode( MX_TEXT ); + mxTerm; +end. diff --git a/16/x/modex/DEMO06.DAT b/16/x/modex/DEMO06.DAT new file mode 100755 index 00000000..1ac2c2bb Binary files /dev/null and b/16/x/modex/DEMO06.DAT differ diff --git a/16/x/modex/DEMO06.EXE b/16/x/modex/DEMO06.EXE new file mode 100755 index 00000000..f1308e8a Binary files /dev/null and b/16/x/modex/DEMO06.EXE differ diff --git a/16/x/modex/DEMO06.PAS b/16/x/modex/DEMO06.PAS new file mode 100755 index 00000000..f26af067 --- /dev/null +++ b/16/x/modex/DEMO06.PAS @@ -0,0 +1,135 @@ +(* + DEMO06 - Magnifying glass + (c) 1994 Alessandro Scotti +*) +uses Crt, Modex; + +const + R = 40; (* Lens radius *) + K : real = 1.8; (* Magnifying factor, less makes a stronger lens *) +type + TLine = array[ 0..319 ] of byte; + PLine = ^TLine; + TScreen = array[ 0..239 ] of PLine; +var + VScreen: TScreen; (* Virtual screen *) + BallX : array[ 0..R, 0..R ] of integer; + BallY : array[ 0..R, 0..R ] of integer; + Sprite : array[ -R..R, -R..R ] of byte; + Page : word; + +(* Returns "lens-view" coordinates of X,Y *) +procedure GetCoords( var X, Y: integer ); +var + LR, Z, SinA, SinB, TgB, Q: real; +begin + LR := Sqrt( X*X + Y*Y ); + if( LR = 0 ) then Exit; + if( LR < R ) then begin + Z := Sqrt( R*R - LR*LR ); + SinA := LR / R; + SinB := SinA / K; + TgB := SinB / Sqrt( 1-SinB*SinB ); + Q := LR - TgB*Z; + X := Round( X * ( Q/LR ) ); + Y := Round( Y * ( Q/LR ) ); + end; +end; + +procedure Init; +var + F : file; + Palette: array[ 0..767 ] of record R, G, B: byte; end; + X, Y, + X2, Y2 : integer; +begin + (* Load background image *) + Assign( F, 'demo06.dat' ); + Reset( F, 1 ); + BlockRead( F, Palette, 768 ); + mxSetPalette( @Palette, 0, 256 ); + for Y:=0 to 239 do begin + New( VScreen[Y] ); + BlockRead( F, VScreen[Y]^, 320 ); + mxPutImage( VScreen[Y], 0, 480+Y, 320, 1, OP_MOVE ); + end; + Close( F ); + (* Build lens *) + for X:=0 to R do begin + for Y:=0 to R do begin + X2 := X; + Y2 := Y; + GetCoords( X2, Y2 ); + BallX[X, Y] := X2; + BallY[X, Y] := Y2; + end; + end; +end; + +procedure PutLens( OX, OY: integer ); +var + X, Y: integer; +begin + for X:=0 to R do begin + for Y:=0 to R do begin + Sprite[Y][X] := VScreen[ OY+BallY[X,Y] ]^[ OX+BallX[X,Y] ]; + Sprite[Y][-X] := VScreen[ OY+BallY[X,Y] ]^[ OX-BallX[X,Y] ]; + Sprite[-Y][X] := VScreen[ OY-BallY[X,Y] ]^[ OX+BallX[X,Y] ]; + Sprite[-Y][-X] := VScreen[ OY-BallY[X,Y] ]^[ OX-BallX[X,Y] ]; + end; + end; + (* Draw the sprite *) + mxPutImage( @Sprite, OX-R, OY-R+Page, 2*R+1, 2*R+1, OP_MOVE ); +end; + +function Delta: integer; +begin + Delta := Random(3)+2; +end; + +procedure Check( Cond: boolean; var Coord, DeltaC: integer; NewCoord, Sign: integer ); +begin + if( Cond ) then begin + Coord := NewCoord; + DeltaC := Sign*Delta; + end; +end; + +var + X, Y, DX, DY: integer; + C: char; +begin + mxInit; + mxSetMode( MX_320x240 ); + Init; + Page := 240; + X := R; + Y := R; + Randomize; + DX := Delta; + DY := Delta; + + (* Main loop *) + repeat + (* Update video *) + mxBitBlt( 0, 480, 320, 240, 0, Page ); + PutLens( X, Y ); + mxCircle( X, Page+Y, R, 0 ); + (* Update lens coordinates *) + Inc( X, DX ); + Check( X+R >= 319, X, DX, 319-R, -1 ); + Check( X <= R, X, DX, R, +1 ); + Inc( Y, DY ); + Check( Y+R >= 239, Y, DY, 239-R, -1 ); + Check( Y <= R, Y, DY, R, +1 ); + (* Flip pages: double buffering, avoid wait for display *) + case Page of + 0 : begin PortW[$3D4] := $000C; Page := 240; end; + 240: begin PortW[$3D4] := $4B0C; Page := 0; end; + end; + mxWaitRetrace; (* Wait for hidden page to show *) + until( KeyPressed ); + + mxSetMode( MX_TEXT ); + mxTerm; +end. diff --git a/16/x/modex/DEMO07.EXE b/16/x/modex/DEMO07.EXE new file mode 100755 index 00000000..8a401169 Binary files /dev/null and b/16/x/modex/DEMO07.EXE differ diff --git a/16/x/modex/DEMO07.PAS b/16/x/modex/DEMO07.PAS new file mode 100755 index 00000000..04fff790 --- /dev/null +++ b/16/x/modex/DEMO07.PAS @@ -0,0 +1,68 @@ +(* + DEMO07 - Hardware scrolling + Copyright (c) 1994 Alessandro Scotti +*) +uses Crt, Modex; + +const + (* Change this if scrolling seems jerky (this simple program does *) + (* not handle vertical retrace/display very well) *) + STEPS = 5; + +procedure Check( Cond: boolean; var Coord, DeltaC: integer; NewCoord, Sign: integer ); +begin + if( Cond ) then begin + Coord := NewCoord; + DeltaC := Sign*(Random(3)+2); + end; +end; + +var + I, X, Y, DX, DY: integer; +begin + (* Initialize library and graphics mode *) + mxInit; + mxSetMode( MX_320x200 ); + (* Set a 640x400 virtual screen *) + mxSetVirtualScreen( 640, 400 ); + mxSetClip( TRUE ); + + X := 0; + Y := 0; + DX := 1; + DY := 1; + + (* Main loop: draw lines, circles, points and rectangles in separate *) + (* 320x200 windows, while smoothly panning virtual screen *) + while( not KeyPressed ) do begin + (* Points *) + mxSetClipRegion( 0, 0, 320, 200 ); + for I:=1 to STEPS do + mxPutPixel( Random(320), Random(200), Random(16) ); + (* Lines *) + mxSetClipRegion( 0, 200, 320, 200 ); + for I:=1 to STEPS do + mxLine( Random(320), Random(200)+200, Random(320), Random(200)+200, Random(16), OP_SET ); + (* Circles *) + mxSetClipRegion( 320, 0, 320, 200 ); + for I:=1 to STEPS do + mxCircle( Random(320)+320, Random(200), Random(100), Random(16) ); + (* Boxes *) + mxSetClipRegion( 320, 200, 320, 200 ); + for I:=1 to STEPS do + mxFillBox( Random(320)+320, Random(200)+200, Random(100)+1, Random(100)+1, Random(16), OP_SET ); + (* Pan *) + Inc( X, DX ); + Check( X+320 >= 639, X, DX, 319, -1 ); + Check( X < 0, X, DX, 0, +1 ); + Inc( Y, DY ); + Check( Y+200 >= 399, Y, DY, 199, -1 ); + Check( Y < 0, Y, DY, 0, +1 ); + mxPan( X, Y ); + mxWaitRetrace; + end; + + (* Shutdown *) + mxSetMode( MX_TEXT ); + mxTerm; +end. diff --git a/16/x/modex/MATH.INC b/16/x/modex/MATH.INC new file mode 100755 index 00000000..742af410 --- /dev/null +++ b/16/x/modex/MATH.INC @@ -0,0 +1,34 @@ +; +; MATH.INC - Include file for THREED.ASM +; + +; 3-dimensional point, coordinates in fixed format (16:16) +; +TPOINT STRUC + X DD ? + Y DD ? + Z DD ? +TPOINT ENDS + +; 2-dimensional point, coordinates in integer format +; +TIMAGEPOINT STRUC + IX DW ? + IY DW ? +TIMAGEPOINT ENDS + +; Fixed-point divide: EAX = EAX / arg +; +.xdiv MACRO arg + xor edx, edx + shld edx, eax, 16 + shl eax, 16 + idiv arg +ENDM + +; Fixed-point multiply: EAX = EAX * arg +; +.xmul MACRO arg + imul arg + shrd eax, edx, 16 +ENDM diff --git a/16/x/modex/PLASMA.PAS b/16/x/modex/PLASMA.PAS new file mode 100755 index 00000000..237e292a --- /dev/null +++ b/16/x/modex/PLASMA.PAS @@ -0,0 +1,103 @@ +unit Plasma; +interface + +const + PAL_RGB = 0; + PAL_CLOUDS = 1; + PAL_LANDSCAPE = 2; + +procedure MakePlasma( X, Y: integer; W, H: word; C1, C2, C3, C4: byte ); +procedure MakePlasmaPalette( var Palette; What: word ); + +implementation uses Modex; + +procedure NewColor( XA, YA, X, Y, XB, YB: integer ); +var + Color: longint; +begin + Color := Abs( XA-XB )+Abs( YA-YB ); + Color := Random( Color shl 1 )-Color; + Color := (Color+mxGetPixel( XA, YA )+mxGetPixel( XB, YB )+1) shr 1; + if( Color < 1 ) then Color := 1; + if( Color > 192 ) then Color := 192; + if( mxGetPixel( X, Y ) = 0 ) then + mxPutPixel( X, Y, Lo(Color) ); +end; + +procedure Divide( X1, Y1, X2, Y2: integer ); +var + X, Y, Color: integer; +begin + if not( (X2-X1<2)and(Y2-Y1<2) ) then begin + X := (X1+X2) shr 1; + Y := (Y1+Y2) shr 1; + NewColor( X1, Y1, X, Y1, X2, Y1 ); + NewColor( X2, Y1, X2, Y, X2, Y2 ); + NewColor( X1, Y2, X, Y2, X2, Y2 ); + NewColor( X1, Y1, X1, Y, X1, Y2 ); + Color := (mxGetPixel( X1, Y1 )+mxGetPixel( X2, Y1 )+ + mxGetPixel( X2, Y2 )+mxGetPixel( X1, Y2 )) shr 2; + mxPutPixel( X, Y, Color ); + Divide( X1, Y1, X, Y ); + Divide( X, Y1, X2, Y ); + Divide( X, Y, X2, Y2 ); + Divide( X1, Y, X, Y2 ); + end; +end; + +procedure MakePlasma; +begin + Dec( W ); + Dec( H ); + mxPutPixel( X, Y, C1 ); + mxPutPixel( X, Y+H, C2 ); + mxPutPixel( X+W, Y+H, C3 ); + mxPutPixel( X+W, Y, C4 ); + Divide( X, Y, X+W, Y+H ); +end; + +procedure MakePlasmaPalette; +type + TPal = array[ byte ] of record R, G, B: byte end; +var + I: word; +begin + FillChar( TPal(Palette)[1], 192*3, 0 ); + case What of + PAL_CLOUDS: + for I:=1 to 192 do begin + TPal(Palette)[I].R := Abs( I-96 )*63 div 96; + TPal(Palette)[I].G := Abs( I-96 )*63 div 96; + TPal(Palette)[I].B := 63; + end; + PAL_LANDSCAPE: + begin + for I:=0 to 31 do begin + TPal(Palette)[I+1].R := I; + TPal(Palette)[I+1].G := I; + TPal(Palette)[I+1].B := I + I shr 1+15; + end; + for I:=32 to 63 do begin + TPal(Palette)[I+1].R := 0; + TPal(Palette)[I+1].G := I; + TPal(Palette)[I+1].B := 0; + end; + for I:=64 to 191 do begin + TPal(Palette)[I+1].R := (I-64) div 3 + 15; + TPal(Palette)[I+1].G := (I-64) div 3 + 15; + TPal(Palette)[I+1].B := (I-64) div 3 + 15; + end; + end; + else + for I:=1 to 64 do begin + TPal(Palette)[I].G := I-1; + TPal(Palette)[I].B := 64-I; + TPal(Palette)[I+64].R := I-1; + TPal(Palette)[I+64].G := 64-I; + TPal(Palette)[I+128].B := I-1; + TPal(Palette)[I+128].R := 64-I; + end; + end; +end; + +end. \ No newline at end of file diff --git a/16/x/modex/QIX2.EXE b/16/x/modex/QIX2.EXE new file mode 100755 index 00000000..a10d7db5 Binary files /dev/null and b/16/x/modex/QIX2.EXE differ diff --git a/16/x/modex/QIX2.PAS b/16/x/modex/QIX2.PAS new file mode 100755 index 00000000..d1b59791 --- /dev/null +++ b/16/x/modex/QIX2.PAS @@ -0,0 +1,210 @@ +{$E-,N+} +uses Crt, Modex; + +const + DEFVERT = 12; (* Vertex count *) + DEFREPL = 3; (* Repetition count *) + DEFQIXS = 2; (* Qixs *) + FADESPEED = 48; +type + TPoint = record + X, Y : integer; + end; + TRGB = record + R, G, B: byte; + end; + TQix = record + Color: integer; + Vert : array[ 0..DEFVERT-1, 0..DEFREPL-1 ] of TPoint; + Delta: array[ 0..DEFVERT-1 ] of TPoint; + end; +var + Page : integer; + MaxX, + MaxY : word; + Qix : array[ 0..DEFQIXS-1 ] of TQix; + Pal : array[ byte ] of TRGB; + +type + TReal = double; + TRPoint = record + X, Y: TReal; + end; + TMatrix = array[ 0..3, 0..3 ] of TReal; +var + M: TMatrix; + G: array[ 0..DEFVERT-1 ] of TRPoint; + C: array[ 0..DEFVERT-1 ] of TRPoint; + +procedure BumpPal( Idx, DR, DG, DB, Steps: integer ); +var + I: integer; +begin + for I:=1 to Steps do begin + Pal[Idx+1].R := Pal[Idx].R + DR; + Pal[Idx+1].G := Pal[Idx].G + DG; + Pal[Idx+1].B := Pal[Idx].B + DB; + Inc( Idx ); + end; +end; + +procedure InitPalette; +begin + with Pal[0] do begin R:=0; G:=0; B:=0; end; + with Pal[1] do begin R:=0; G:=0; B:=62; end; + BumpPal( 1, 0, 2, -2, 31 ); + BumpPal( 32, 2, -2, 0, 31 ); + BumpPal( 63, -2, 2, 2, 31 ); + BumpPal( 94, 2, 0, -2, 31 ); + BumpPal( 125, -2, -2, 2, 31 ); +end; + +procedure Init( var Qix: TQix; Color: integer ); +var + I: integer; +begin + FillChar( Qix.Vert, SizeOf(Qix.Vert), 0 ); + for I:=0 to DEFVERT-1 do begin + Qix.Vert[I, DEFREPL-1].X := Random( MaxX ); + Qix.Vert[I, DEFREPL-1].Y := Random( MaxY ); + Qix.Delta[I].X := Random(5)+1; + Qix.Delta[I].Y := Random(5)+1; + end; + Qix.Color := Color; + + (* Initialize matrix (Catmull-Rom) *) + M[0,0] := -1/2; M[0,1] := 3/2; M[0,2] := -3/2; M[0,3] := 1/2; + M[1,0] := 1; M[1,1] := -5/2; M[1,2] := 2; M[1,3] := -1/2; + M[2,0] := -1/2; M[2,1] := 0; M[2,2] := 1/2; M[2,3] := 0; + M[3,0] := 0; M[3,1] := 1; M[3,2] := 0; M[3,3] := 0; +end; + +procedure mxBezier( var Qix: TQix; I0, Idx, N: integer ); +var + I, J: integer; + T, T2, T3: TReal; + X0, Y0, X, Y: TReal; + Delta: TReal; +begin + (* Compute coefficients *) + for I:=0 to 3 do begin + C[I].X := 0; + for J:=0 to 3 do C[I].X := C[I].X + M[I,J]*Qix.Vert[(I0+J) mod DEFVERT,Idx].X; + C[I].Y := 0; + for J:=0 to 3 do C[I].Y := C[I].Y + M[I,J]*Qix.Vert[(I0+J) mod DEFVERT,Idx].Y; + end; + X0 := C[3].X; + Y0 := C[3].Y; + Delta := 1 / N; + T := 0; + for I:=1 to N do begin + T := T + Delta; + T2 := T*T; + T3 := T*T2; + X := C[0].X*T3 + C[1].X*T2 + C[2].X*T + C[3].X; + Y := C[0].Y*T3 + C[1].Y*T2 + C[2].Y*T + C[3].Y; + mxLine( Round(X0), Page+Round(Y0), Round(X), Page+Round(Y), Qix.Color, OP_SET ); + X0 := X; + Y0 := Y; + end; +end; + +procedure Plot( var Qix: TQix; Idx: integer ); +var + I, J: integer; +begin + for I:=0 to DEFVERT-1 do begin + mxBezier( Qix, I, Idx, 12 ); + end; +end; + +procedure Update( var Qix: TQix; Idx: integer ); +var + I: integer; +begin + for I:=0 to DEFVERT-1 do with Qix do begin + Inc( Vert[I,Idx].X, Delta[I].X ); + if( Vert[I,Idx].X < 0 ) then begin + Vert[I,Idx].X := 0; + Delta[I].X := Random( 5 )+1; + end; + if( Vert[I,Idx].X > MaxX ) then begin + Vert[I,Idx].X := MaxX; + Delta[I].X := -Random( 5 )-1; + end; + Inc( Vert[I,Idx].Y, Delta[I].Y ); + if( Vert[I,Idx].Y < 0 ) then begin + Vert[I,Idx].Y := 0; + Delta[I].Y := Random( 5 )+1; + end; + if( Vert[I,Idx].Y > MaxY ) then begin + Vert[I,Idx].Y := MaxY; + Delta[I].Y := -Random( 5 )-1; + end; + end; +end; + +procedure Copy( var Qix: TQix; Dest, Src: integer ); +var + I: integer; +begin + for I:=0 to DEFVERT-1 do with Qix do begin + Vert[I,Dest].X := Vert[I,Src].X; + Vert[I,Dest].Y := Vert[I,Src].Y; + end; +end; + +procedure AnimateQix; +var + Q, Idx, I, J, P, Count: integer; +begin + Count := 0; + P := DEFREPL-1; + I := 0; + J := 1; + repeat + mxSetClipRegion( 0, Page, MaxX+1, MaxY+1 ); + mxSetClip( TRUE ); + mxFillBox( 0, Page, MaxX+1, MaxY+1, 0, OP_SET ); + for Q:=0 to DEFQIXS-1 do begin + Copy( Qix[Q], I, P ); + Update( Qix[Q], I ); + for Idx:=0 to DEFREPL-1 do begin + Plot( Qix[Q], Idx ); + end; + end; + I := (I+1) mod DEFREPL; + J := (J+1) mod DEFREPL; + P := (P+1) mod DEFREPL; + Inc( Count ); + mxStartLine( Page ); + if( Count >= FADESPEED ) then begin + for Q:=0 to DEFQIXS-1 do begin + Inc( Qix[Q].Color ); + if( Qix[Q].Color > 156 ) then + Qix[Q].Color := 1; + end; + Count := 0; + end; + Page := 240-Page; + until( KeyPressed ); +end; + +var + I: integer; +begin + Randomize; + mxInit; + mxSetMode( MX_320x240 ); + mxGetScreenSize( MaxX, MaxY ); + for I:=0 to DEFQIXS-1 do + Init( Qix[I], (I*(155 div DEFQIXS)) mod 155 + 1 ); + InitPalette; + mxSetPalette( @Pal, 0, 157 ); + Page := 240; + Dec( MaxX ); + Dec( MaxY ); + AnimateQix; + mxSetMode( MX_TEXT ); + mxTerm; +end. diff --git a/16/x/modex/README.TXT b/16/x/modex/README.TXT new file mode 100755 index 00000000..306e8b9a --- /dev/null +++ b/16/x/modex/README.TXT @@ -0,0 +1,8 @@ +ModeX - A graphical library for DOS programs +Copyright (c) 1993-1994 Alessandro Scotti +http://www.ascotti.org/ + +Please look at the above site in the "Art of..." and +then in the "Old programs" section for more information. + + diff --git a/16/x/modex/SINCOS.INC b/16/x/modex/SINCOS.INC new file mode 100755 index 00000000..6986eeeb --- /dev/null +++ b/16/x/modex/SINCOS.INC @@ -0,0 +1,518 @@ +; +; SINCOS.INC - Sin/cos tables for THREED.ASM +; + +tblSin LABEL DWORD + DD 0 + DD 411733 + DD 823219 + DD 1234209 + DD 1644455 + DD 2053710 + DD 2461729 + DD 2868265 + DD 3273072 + DD 3675909 + DD 4076531 + DD 4474698 + DD 4870169 + DD 5262706 + DD 5652074 + DD 6038037 + DD 6420363 + DD 6798821 + DD 7173184 + DD 7543226 + DD 7908725 + DD 8269459 + DD 8625213 + DD 8975771 + DD 9320922 + DD 9660458 + DD 9994176 + DD 10321873 + DD 10643353 + DD 10958422 + DD 11266890 + DD 11568571 + DD 11863283 + DD 12150850 + DD 12431097 + DD 12703856 + DD 12968963 + DD 13226258 + DD 13475586 + DD 13716797 + DD 13949745 + DD 14174291 + DD 14390298 + DD 14597637 + DD 14796184 + DD 14985817 + DD 15166424 + DD 15337895 + DD 15500126 + DD 15653022 + DD 15796488 + DD 15930439 + DD 16054795 + DD 16169479 + DD 16274424 + DD 16369565 + DD 16454846 + DD 16530216 + DD 16595628 + DD 16651044 + DD 16696429 + DD 16731757 + DD 16757007 + DD 16772163 + DD 16777216 + DD 16772163 + DD 16757007 + DD 16731757 + DD 16696429 + DD 16651044 + DD 16595628 + DD 16530216 + DD 16454846 + DD 16369565 + DD 16274424 + DD 16169479 + DD 16054795 + DD 15930439 + DD 15796488 + DD 15653022 + DD 15500126 + DD 15337895 + DD 15166424 + DD 14985817 + DD 14796184 + DD 14597637 + DD 14390298 + DD 14174291 + DD 13949745 + DD 13716797 + DD 13475586 + DD 13226258 + DD 12968963 + DD 12703856 + DD 12431097 + DD 12150850 + DD 11863283 + DD 11568571 + DD 11266890 + DD 10958422 + DD 10643353 + DD 10321873 + DD 9994176 + DD 9660458 + DD 9320922 + DD 8975771 + DD 8625213 + DD 8269459 + DD 7908725 + DD 7543226 + DD 7173184 + DD 6798821 + DD 6420363 + DD 6038037 + DD 5652074 + DD 5262706 + DD 4870169 + DD 4474698 + DD 4076531 + DD 3675909 + DD 3273072 + DD 2868265 + DD 2461729 + DD 2053710 + DD 1644455 + DD 1234209 + DD 823219 + DD 411733 + DD 0 + DD -411733 + DD -823219 + DD -1234209 + DD -1644455 + DD -2053710 + DD -2461729 + DD -2868265 + DD -3273072 + DD -3675909 + DD -4076531 + DD -4474698 + DD -4870169 + DD -5262706 + DD -5652074 + DD -6038037 + DD -6420363 + DD -6798821 + DD -7173184 + DD -7543226 + DD -7908725 + DD -8269459 + DD -8625213 + DD -8975771 + DD -9320922 + DD -9660458 + DD -9994176 + DD -10321873 + DD -10643353 + DD -10958422 + DD -11266890 + DD -11568571 + DD -11863283 + DD -12150850 + DD -12431097 + DD -12703856 + DD -12968963 + DD -13226258 + DD -13475586 + DD -13716797 + DD -13949745 + DD -14174291 + DD -14390298 + DD -14597637 + DD -14796184 + DD -14985817 + DD -15166424 + DD -15337895 + DD -15500126 + DD -15653022 + DD -15796488 + DD -15930439 + DD -16054795 + DD -16169479 + DD -16274424 + DD -16369565 + DD -16454846 + DD -16530216 + DD -16595628 + DD -16651044 + DD -16696429 + DD -16731757 + DD -16757007 + DD -16772163 + DD -16777216 + DD -16772163 + DD -16757007 + DD -16731757 + DD -16696429 + DD -16651044 + DD -16595628 + DD -16530216 + DD -16454846 + DD -16369565 + DD -16274424 + DD -16169479 + DD -16054795 + DD -15930439 + DD -15796488 + DD -15653022 + DD -15500126 + DD -15337895 + DD -15166424 + DD -14985817 + DD -14796184 + DD -14597637 + DD -14390298 + DD -14174291 + DD -13949745 + DD -13716797 + DD -13475586 + DD -13226258 + DD -12968963 + DD -12703856 + DD -12431097 + DD -12150850 + DD -11863283 + DD -11568571 + DD -11266890 + DD -10958422 + DD -10643353 + DD -10321873 + DD -9994176 + DD -9660458 + DD -9320922 + DD -8975771 + DD -8625213 + DD -8269459 + DD -7908725 + DD -7543226 + DD -7173184 + DD -6798821 + DD -6420363 + DD -6038037 + DD -5652074 + DD -5262706 + DD -4870169 + DD -4474698 + DD -4076531 + DD -3675909 + DD -3273072 + DD -2868265 + DD -2461729 + DD -2053710 + DD -1644455 + DD -1234209 + DD -823219 + DD -411733 +tblCos LABEL DWORD + DD 16777216 + DD 16772163 + DD 16757007 + DD 16731757 + DD 16696429 + DD 16651044 + DD 16595628 + DD 16530216 + DD 16454846 + DD 16369565 + DD 16274424 + DD 16169479 + DD 16054795 + DD 15930439 + DD 15796488 + DD 15653022 + DD 15500126 + DD 15337895 + DD 15166424 + DD 14985817 + DD 14796184 + DD 14597637 + DD 14390298 + DD 14174291 + DD 13949745 + DD 13716797 + DD 13475586 + DD 13226258 + DD 12968963 + DD 12703856 + DD 12431097 + DD 12150850 + DD 11863283 + DD 11568571 + DD 11266890 + DD 10958422 + DD 10643353 + DD 10321873 + DD 9994176 + DD 9660458 + DD 9320922 + DD 8975771 + DD 8625213 + DD 8269459 + DD 7908725 + DD 7543226 + DD 7173184 + DD 6798821 + DD 6420363 + DD 6038037 + DD 5652074 + DD 5262706 + DD 4870169 + DD 4474698 + DD 4076531 + DD 3675909 + DD 3273072 + DD 2868265 + DD 2461729 + DD 2053710 + DD 1644455 + DD 1234209 + DD 823219 + DD 411733 + DD 0 + DD -411733 + DD -823219 + DD -1234209 + DD -1644455 + DD -2053710 + DD -2461729 + DD -2868265 + DD -3273072 + DD -3675909 + DD -4076531 + DD -4474698 + DD -4870169 + DD -5262706 + DD -5652074 + DD -6038037 + DD -6420363 + DD -6798821 + DD -7173184 + DD -7543226 + DD -7908725 + DD -8269459 + DD -8625213 + DD -8975771 + DD -9320922 + DD -9660458 + DD -9994176 + DD -10321873 + DD -10643353 + DD -10958422 + DD -11266890 + DD -11568571 + DD -11863283 + DD -12150850 + DD -12431097 + DD -12703856 + DD -12968963 + DD -13226258 + DD -13475586 + DD -13716797 + DD -13949745 + DD -14174291 + DD -14390298 + DD -14597637 + DD -14796184 + DD -14985817 + DD -15166424 + DD -15337895 + DD -15500126 + DD -15653022 + DD -15796488 + DD -15930439 + DD -16054795 + DD -16169479 + DD -16274424 + DD -16369565 + DD -16454846 + DD -16530216 + DD -16595628 + DD -16651044 + DD -16696429 + DD -16731757 + DD -16757007 + DD -16772163 + DD -16777216 + DD -16772163 + DD -16757007 + DD -16731757 + DD -16696429 + DD -16651044 + DD -16595628 + DD -16530216 + DD -16454846 + DD -16369565 + DD -16274424 + DD -16169479 + DD -16054795 + DD -15930439 + DD -15796488 + DD -15653022 + DD -15500126 + DD -15337895 + DD -15166424 + DD -14985817 + DD -14796184 + DD -14597637 + DD -14390298 + DD -14174291 + DD -13949745 + DD -13716797 + DD -13475586 + DD -13226258 + DD -12968963 + DD -12703856 + DD -12431097 + DD -12150850 + DD -11863283 + DD -11568571 + DD -11266890 + DD -10958422 + DD -10643353 + DD -10321873 + DD -9994176 + DD -9660458 + DD -9320922 + DD -8975771 + DD -8625213 + DD -8269459 + DD -7908725 + DD -7543226 + DD -7173184 + DD -6798821 + DD -6420363 + DD -6038037 + DD -5652074 + DD -5262706 + DD -4870169 + DD -4474698 + DD -4076531 + DD -3675909 + DD -3273072 + DD -2868265 + DD -2461729 + DD -2053710 + DD -1644455 + DD -1234209 + DD -823219 + DD -411733 + DD 0 + DD 411733 + DD 823219 + DD 1234209 + DD 1644455 + DD 2053710 + DD 2461729 + DD 2868265 + DD 3273072 + DD 3675909 + DD 4076531 + DD 4474698 + DD 4870169 + DD 5262706 + DD 5652074 + DD 6038037 + DD 6420363 + DD 6798821 + DD 7173184 + DD 7543226 + DD 7908725 + DD 8269459 + DD 8625213 + DD 8975771 + DD 9320922 + DD 9660458 + DD 9994176 + DD 10321873 + DD 10643353 + DD 10958422 + DD 11266890 + DD 11568571 + DD 11863283 + DD 12150850 + DD 12431097 + DD 12703856 + DD 12968963 + DD 13226258 + DD 13475586 + DD 13716797 + DD 13949745 + DD 14174291 + DD 14390298 + DD 14597637 + DD 14796184 + DD 14985817 + DD 15166424 + DD 15337895 + DD 15500126 + DD 15653022 + DD 15796488 + DD 15930439 + DD 16054795 + DD 16169479 + DD 16274424 + DD 16369565 + DD 16454846 + DD 16530216 + DD 16595628 + DD 16651044 + DD 16696429 + DD 16731757 + DD 16757007 + DD 16772163 diff --git a/16/x/modex/THREED.ASM b/16/x/modex/THREED.ASM new file mode 100755 index 00000000..5ecd3ba3 --- /dev/null +++ b/16/x/modex/THREED.ASM @@ -0,0 +1,872 @@ +COMMENT / + Fixed-point math functions and 3D transforms + Copyright (c) 1993,94 by Alessandro Scotti +/ +WARN PRO +P386 +JUMPS +LOCALS + +INCLUDE MATH.INC + +PUBLIC tdFixedMul +PUBLIC tdGetNormal +PUBLIC tdRotate +PUBLIC tdGetSurfaceLight +PUBLIC tdSetLight +PUBLIC tdSetRotation +PUBLIC tdSetTranslation +PUBLIC tdTransform +PUBLIC tdTransformToImage +PUBLIC tdTransformLight +PUBLIC tdBackPlaneCull +PUBLIC tdSetPerspective + +;----------------------------------------------------------- +; +; Data segment +; +MATH_DATA SEGMENT USE16 PARA PUBLIC 'DATA' + ASSUME ds:MATH_DATA + +INCLUDE SINCOS.INC ; Fixed 8:24 sin/cos table + +XRotation TPOINT <> ; 3x3 rotation matrix +YRotation TPOINT <> +ZRotation TPOINT <> + +Translation TPOINT <> ; Translation vector + +Light TPOINT <> ; Light vector +AmbientLight DW 00 ; Ambient light + +XScale DD 10000h ; Scaling factor for X coordinate +YScale DD 10000h ; Scaling factor for Y coordinate +PerspectiveDistance DD 20000000h + +MATH_DATA ENDS + +;----------------------------------------------------------- +; +; Code segment +; +MATH_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MATH_TEXT, es:NOTHING, fs:NOTHING + +tdSetPerspective PROC PASCAL FAR + ARG Perspective:DWORD, \ + ScaleX:DWORD, \ + ScaleY:DWORD + USES ds + + mov ax, SEG MATH_DATA + mov ds, ax + ASSUME ds:MATH_DATA + + mov eax, [Perspective] + mov [PerspectiveDistance], eax + mov eax, [ScaleX] + mov [XScale], eax + mov eax, [ScaleY] + mov [YScale], eax + + ret +tdSetPerspective ENDP + + +;----------------------------------------------------------- +; +; Sets the rotation matrix. +; +; Input: +; RX = X-axis rotation angle +; RY = X-axis rotation angle +; RZ = X-axis rotation angle +; Output: +; none +; +tdSetRotation PROC PASCAL FAR + ARG RX:WORD, \ + RY:WORD, \ + RZ:WORD + USES ds, si, di + + mov ax, SEG MATH_DATA + mov ds, ax + ASSUME ds:MATH_DATA + + mov bx, [RZ] + mov si, [RY] + mov di, [RX] + shl bx, 2 + shl si, 2 + shl di, 2 + + push ebp ; We use EBP as a scratch register + +; Set X rotation + mov eax, tblCos[bx] + imul tblCos[si] + mov [XRotation.X], edx + + mov eax, tblSin[bx] + imul tblCos[si] + mov [XRotation.Y], edx + + mov eax, tblSin[si] + sar eax, 8 ; Convert fixed 8:24 to fixed 16:16 + mov [XRotation.Z], eax + +; Set Y rotation + mov eax, tblCos[bx] + imul tblSin[si] ; EDX:EAX = fixed 16:48 + shrd eax, edx, 24 ; EAX = fixed 8:24 + imul tblSin[di] ; EDX:EAX = fixed 16:48 + mov ebp, eax + mov ecx, edx + mov eax, tblSin[bx] + imul tblCos[di] + add eax, ebp + adc edx, ecx ; EDX:EAX = fixed 16:48 + neg edx + mov [YRotation.X], edx + + mov eax, tblSin[bx] + imul tblSin[si] + shrd eax, edx, 24 + imul tblSin[di] + mov ebp, eax + mov ecx, edx + mov eax, tblCos[bx] + imul tblCos[di] + sub eax, ebp + sbb edx, ecx + mov [YRotation.Y], edx + + mov eax, tblCos[si] + imul tblSin[di] + mov [YRotation.Z], edx + +; Set Z rotation + mov eax, tblCos[bx] + imul tblSin[si] + shrd eax, edx, 24 + imul tblCos[di] + mov ebp, eax + mov ecx, edx + mov eax, tblSin[bx] + imul tblSin[di] + sub eax, ebp + sbb edx, ecx + mov [ZRotation.X], edx + + mov eax, tblSin[bx] + imul tblSin[si] + shrd eax, edx, 24 + imul tblCos[di] + mov ebp, eax + mov ecx, edx + mov eax, tblCos[bx] + imul tblSin[di] + add eax, ebp + add edx, ecx + neg edx + mov [ZRotation.Y], edx + + mov eax, tblCos[si] + imul tblCos[di] + mov [ZRotation.Z], edx + + pop ebp ; Restore EBP + + ret +tdSetRotation ENDP + +;----------------------------------------------------------- +; +; Sets the translation vector. +; +; Input: +; TV = pointer to translation vector +; Output: +; none +; +tdSetTranslation PROC PASCAL FAR + ARG TV:DWORD + USES ds, es, di + + mov ax, SEG MATH_DATA + mov ds, ax + ASSUME ds:MATH_DATA + + les di, [TV] + mov eax, es:[di].X + mov [Translation.X], eax + mov eax, es:[di].Y + mov [Translation.Y], eax + mov eax, es:[di].Z + mov [Translation.Z], eax + + ret +tdSetTranslation ENDP + +;----------------------------------------------------------- +; +; Transforms an array of TPOINT. +; +; Input: +; Source = pointer to source array of TPOINT +; Dest = pointer to destination array of TPOINT +; Count = number of entries to transform +; Output: +; none +; +tdTransform PROC PASCAL FAR + ARG Source:DWORD, \ + Dest:DWORD, \ + Count:WORD + LOCAL Adjust:DWORD + USES ds, si, es, di, fs + + mov ax, SEG MATH_DATA + mov ds, ax + ASSUME ds:MATH_DATA + + lfs si, [Source] + les di, [Dest] + + ALIGN DWORD +@@Loop: +; Transform Z coordinate + mov eax, fs:[si].X + imul [ZRotation.X] + mov ecx, eax + mov ebx, edx + mov eax, fs:[si].Y + imul [ZRotation.Y] + add ecx, eax + adc ebx, edx + mov eax, fs:[si].Z + imul [ZRotation.Z] + add eax, ecx + adc edx, ebx + mov ebx, eax + shrd eax, edx, 16 + add eax, [Translation.Z] ; EAX = new Z coord (fixed 16:16) + mov es:[di].Z, eax +; Get perspective factor + mov ebx, [PerspectiveDistance] + sub eax, ebx + neg eax ; EAX = PD - Z + xor edx, edx + shld edx, eax, 16 + shl eax, 16 + idiv ebx ; EAX = fixed 16:16 result + mov [Adjust], eax + +; Transform X coordinate + mov eax, fs:[si].X + imul [XRotation.X] + mov ecx, eax + mov ebx, edx + mov eax, fs:[si].Y + imul [XRotation.Y] + add ecx, eax + adc ebx, edx + mov eax, fs:[si].Z + imul [XRotation.Z] + add eax, ecx + adc edx, ebx + shrd eax, edx, 16 + add eax, [Translation.X] + imul [Adjust] + shrd eax, edx, 16 + mov es:[di].X, eax + +; Transform Y coordinate + mov eax, fs:[si].X + imul [YRotation.X] + mov ecx, eax + mov ebx, edx + mov eax, fs:[si].Y + imul [YRotation.Y] + add ecx, eax + adc ebx, edx + mov eax, fs:[si].Z + imul [YRotation.Z] + add eax, ecx + adc edx, ebx + shrd eax, edx, 16 + add eax, [Translation.Y] + imul [Adjust] + shrd eax, edx, 16 + mov es:[di].Y, eax + + add si, SIZE TPOINT + add di, SIZE TPOINT + dec [Count] + jnz @@Loop + + ret +tdTransform ENDP + +;----------------------------------------------------------- +; +; Transforms an array of TPOINT into an array of TIMAGEPOINT. +; +; Input: +; Source = pointer to source array of TPOINT +; Dest = pointer to destination array of TIMAGEPOINT +; Count = number of entries to transform +; DeltaX = translation distance for the X coordinate +; DeltaY = translation distance for the Y coordinate +; Output: +; the maximum Z value +; +tdTransformToImage PROC PASCAL FAR + ARG Source:DWORD, \ + Dest:DWORD, \ + Count:WORD, \ + DeltaX:WORD, \ + DeltaY:WORD + LOCAL Adjust:DWORD, \ + Max:DWORD + USES ds, si, es, di, fs + + mov ax, SEG MATH_DATA + mov ds, ax + ASSUME ds:MATH_DATA + + lfs si, [Source] + les di, [Dest] + mov [Max], 80000000h + +@@Loop: +; Check max Z + mov eax, fs:[si].Z + cmp eax, [Max] + jle @@1 + mov [Max], eax +@@1: + +; Transform X coordinate + mov ax, WORD PTR fs:[si].X[2] + add ax, [DeltaX] + mov es:[di].IX, ax + +; Transform Y coordinate + mov ax, WORD PTR fs:[si].Y[2] + add ax, [DeltaY] + mov es:[di].IY, ax + + add si, SIZE TPOINT + add di, SIZE TIMAGEPOINT + dec [Count] + jnz @@Loop + + mov eax, [Max] + shld edx, eax, 16 + ret +tdTransformToImage ENDP + +;----------------------------------------------------------- +; +; Sets the light source. +; +; Input: +; Light = pointer to light vector +; Output: +; none +; +tdSetLight PROC PASCAL FAR + ARG L:DWORD + USES ds, es, di + + mov ax, SEG MATH_DATA + mov ds, ax + ASSUME ds:MATH_DATA + + les di, [L] + mov eax, es:[di].X + mov [Light.X], eax + mov eax, es:[di].Y + mov [Light.Y], eax + mov eax, es:[di].Z + mov [Light.Z], eax + + ret +tdSetLight ENDP + +;----------------------------------------------------------- +; +; Computes light intensity for an array of surfaces. +; +; Input: +; Normals = pointer to an array of surface normals +; Lights = pointer to an array of integer to be filled with +; light intensity +; Count = number of elements to transform +; Output: +; none +; +tdTransformLight PROC PASCAL FAR + ARG Normals:DWORD, \ + Lights:DWORD, \ + Count:WORD + USES ds, si, es, di, fs + + mov ax, SEG MATH_DATA + mov fs, ax + ASSUME fs:MATH_DATA + + lds si, [Normals] + les di, [Lights] + ASSUME ds:NOTHING + +; Intensity is given by the dot product between the Light vector and +; the surface normal +@@Loop: + mov eax, ds:[si].Z + imul [Light.Z] + mov ebx, eax + mov ecx, edx + mov eax, ds:[si].Y + imul [Light.Y] + add ebx, eax + adc ecx, edx + mov eax, ds:[si].X + imul [Light.X] + add eax, ebx + adc edx, ecx ; EDX:EAX = fixed 32:32 intensity + add dx, [AmbientLight] + test dx, dx + jg @@1 + xor dx, dx ; Return 0 for no light +@@1: + mov es:[di], dx + inc di + inc di + add si, SIZE TPOINT + dec [Count] + jnz @@Loop + + ASSUME fs:NOTHING + ret +tdTransformLight ENDP + +;----------------------------------------------------------- +; +; Returns the light value given the normal to a surface. +; +; Input: +; Normal = pointer to TPOINT surface normal vector +; Output: +; AX = light intensity (>=0) +; Notes: +; the normal is rotated according to the current setting. +; +tdGetSurfaceLight PROC PASCAL FAR + ARG Normal:DWORD + USES ds, esi, es, di + + mov ax, SEG MATH_DATA + mov ds, ax + ASSUME ds:MATH_DATA + + les di, [Normal] + +; Transform Z coordinate + mov eax, es:[di].X + imul [ZRotation.X] + mov ecx, eax + mov ebx, edx + mov eax, es:[di].Y + imul [ZRotation.Y] + add ecx, eax + adc ebx, edx + mov eax, es:[di].Z + imul [ZRotation.Z] + add eax, ecx + adc edx, ebx + shrd eax, edx, 16 + imul [Light.Z] + shrd eax, edx, 16 + mov esi, eax + +; Transform X coordinate + mov eax, es:[di].X + imul [XRotation.X] + mov ecx, eax + mov ebx, edx + mov eax, es:[di].Y + imul [XRotation.Y] + add ecx, eax + adc ebx, edx + mov eax, es:[di].Z + imul [XRotation.Z] + add eax, ecx + adc edx, ebx + shrd eax, edx, 16 + imul [Light.X] + shrd eax, edx, 16 + add esi, eax + +; Transform Y coordinate + mov eax, es:[di].X + imul [YRotation.X] + mov ecx, eax + mov ebx, edx + mov eax, es:[di].Y + imul [YRotation.Y] + add ecx, eax + adc ebx, edx + mov eax, es:[di].Z + imul [YRotation.Z] + add eax, ecx + adc edx, ebx + shrd eax, edx, 16 + imul [Light.X] + shrd eax, edx, 16 + add eax, esi + shr eax, 16 + +; Add ambient light + add ax, [AmbientLight] + test ax, ax + jge @@Exit + xor ax, ax + +@@Exit: + ret +tdGetSurfaceLight ENDP + +;----------------------------------------------------------- +; +; Rotates an array of TPOINT. +; +; Input: +; Source = pointer to source array of TPOINT +; Dest = pointer to destination array of TPOINT +; Count = number of entries to transform +; Output: +; none +; +tdRotate PROC PASCAL FAR + ARG Source:DWORD, \ + Dest:DWORD, \ + Count:WORD + USES ds, si, es, di, fs + + mov ax, SEG MATH_DATA + mov ds, ax + ASSUME ds:MATH_DATA + + lfs si, [Source] + les di, [Dest] + +@@Loop: +; Transform Z coordinate + mov eax, fs:[si].X + imul [ZRotation.X] + mov ecx, eax + mov ebx, edx + mov eax, fs:[si].Y + imul [ZRotation.Y] + add ecx, eax + adc ebx, edx + mov eax, fs:[si].Z + imul [ZRotation.Z] + add eax, ecx + adc edx, ebx + shrd eax, edx, 16 + mov es:[di].Z, eax + +; Transform X coordinate + mov eax, fs:[si].X + imul [XRotation.X] + mov ecx, eax + mov ebx, edx + mov eax, fs:[si].Y + imul [XRotation.Y] + add ecx, eax + adc ebx, edx + mov eax, fs:[si].Z + imul [XRotation.Z] + add eax, ecx + adc edx, ebx + shrd eax, edx, 16 + mov es:[di].X, eax + +; Transform Y coordinate + mov eax, fs:[si].X + imul [YRotation.X] + mov ecx, eax + mov ebx, edx + mov eax, fs:[si].Y + imul [YRotation.Y] + add ecx, eax + adc ebx, edx + mov eax, fs:[si].Z + imul [YRotation.Z] + add eax, ecx + adc edx, ebx + shrd eax, edx, 16 + mov es:[di].Y, eax + + add si, SIZE TPOINT + add di, SIZE TPOINT + dec [Count] + jnz @@Loop + + ret +tdRotate ENDP + +tdFixedMul PROC PASCAL FAR + ARG F1:DWORD, \ + F2:DWORD + + mov eax, [F1] + imul [F2] + shr eax, 16 + + ret +tdFixedMul ENDP + +;----------------------------------------------------------- +; +; Returns in EAX the square root of EDX:EAX. +; +subSqrt PROC NEAR + push esi + push edi + + add eax, eax + adc edx, 0 + mov eax, edx ; Just discard the low bits + + mov esi, eax + xor edi, edi + shld edi, esi, 16 + shl esi, 16 +@@Loop: + mov ebx, eax + mul eax + add eax, esi + adc edx, edi + shrd eax, edx, 1 + shr edx, 1 + div ebx + cmp eax, ebx + jne @@Loop + +; Adjust EAX + shl eax, 8 + + pop edi + pop esi + ret +subSqrt ENDP + +;----------------------------------------------------------- +; +; Finds the unitary normal to a given surface. +; +; Input: +; Dest = pointer to TPOINT (vector) result +; P1, P2, P3 = pointer to TPOINT points on surface +; Output: +; none +; Notes: +; the normal is given by the cross-product between (P3-P1) and +; (P2-P1), so its orientation depends on the parameters order. +; +tdGetNormal PROC PASCAL FAR + ARG Dest:DWORD, \ + P1:DWORD, \ + P2:DWORD, \ + P3:DWORD + LOCAL V1:TPOINT, \ + V2:TPOINT, \ + N:TPOINT + USES ds, si, es, di + +; Get vector V1 + lds si, [P1] + les di, [P3] + mov eax, es:[di].X + sub eax, ds:[si].X + mov [V1.X], eax + mov eax, es:[di].Y + sub eax, ds:[si].Y + mov [V1.Y], eax + mov eax, es:[di].Z + sub eax, ds:[si].Z + mov [V1.Z], eax + +; Get vector V2 + les di, [P2] + mov eax, es:[di].X + sub eax, ds:[si].X + mov [V2.X], eax + mov eax, es:[di].Y + sub eax, ds:[si].Y + mov [V2.Y], eax + mov eax, es:[di].Z + sub eax, ds:[si].Z + mov [V2.Z], eax + +; Get normal vector (V1 x V2) + mov eax, [V1.Z] + imul [V2.Y] + mov ebx, eax + mov ecx, edx + mov eax, [V1.Y] + imul [V2.Z] + sub eax, ebx + sbb edx, ecx + shrd eax, edx, 16 + mov [N.X], eax + + mov eax, [V1.X] + imul [V2.Z] + mov ebx, eax + mov ecx, edx + mov eax, [V1.Z] + imul [V2.X] + sub eax, ebx + sbb edx, ecx + shrd eax, edx, 16 + mov [N.Y], eax + + mov eax, [V1.Y] + imul [V2.X] + mov ebx, eax + mov ecx, edx + mov eax, [V1.X] + imul [V2.Y] + sub eax, ebx + sbb edx, ecx + shrd eax, edx, 16 + mov [N.Z], eax + +; Get normal length + mov eax, [N.X] + imul eax + mov ebx, eax + mov ecx, edx + mov eax, [N.Y] + imul eax + add ebx, eax + adc ecx, edx + mov eax, [N.Z] + imul eax + add eax, ebx + adc edx, ecx ; EDX:EAX = N.X*N.X + N.Y*N.Y + N.Z*N.Z + call subSqrt ; EAX = normal length + mov ebx, eax + +; Adjust vector and save it + les di, [Dest] + mov eax, [N.X] + cdq + shld edx, eax, 16 + shl eax, 16 + idiv ebx + mov es:[di].X, eax + mov eax, [N.Y] + cdq + shld edx, eax, 16 + shl eax, 16 + idiv ebx + mov es:[di].Y, eax + mov eax, [N.Z] + cdq + shld edx, eax, 16 + shl eax, 16 + idiv ebx + mov es:[di].Z, eax + + ret +tdGetNormal ENDP + +TPOLY STRUC + Vtx DW 4 DUP(?) +TPOLY ENDS + +;----------------------------------------------------------- +; +; Performs surface removal on an array of polygons. +; +; Input: +; Poly = pointer to an array of TPOLY +; Vertex = pointer to an array of TPOINT +; Dest = pointer to an array of integer +; Count = number of polygons to check +; Step = size of TPOLY structure +; Output: +; if the n-th polygon is invisible the n-th entry of the +; Dest array is set to -1, other entries are not modified +; (so it's possible to use the Light array for Dest, because +; the light intensity is always >= 0) +; +tdBackPlaneCull PROC PASCAL FAR + ARG Step:WORD, \ + Poly:DWORD, \ + Vertex:DWORD, \ + Dest:DWORD, \ + Count:WORD + USES ds, si, es, di, fs + ASSUME ds:NOTHING + + mov ds, WORD PTR Vertex[2] + les di, [Poly] + mov fs, WORD PTR Dest[2] + +@@Loop: + mov ax, es:[di].Vtx[2] ; Index of 2nd vertex + shl ax, 2 + mov bx, ax + shl ax, 1 + add bx, ax ; BX = index*SIZE TPOINT + add bx, WORD PTR [Vertex] ; BX = offset of 2nd vertex + mov ax, es:[di].Vtx[4] ; Index of 3rd vertex + shl ax, 2 + mov si, ax + shl ax, 1 + add si, ax + add si, WORD PTR [Vertex] ; SI = offset of 3rd vertex + mov ecx, ds:[si].X + sub ecx, ds:[bx].X ; ECX = V3.X-V2.X + mov edx, ds:[si].Y + sub edx, ds:[bx].Y ; EDX = V3.Y-V2.Y + mov ax, es:[di].Vtx[0] ; Index of 1st vertex + shl ax, 2 + mov si, ax + shl ax, 1 + add si, ax + add si, WORD PTR [Vertex] ; SI = offset of 1st vertex + mov eax, ds:[si].X + sub eax, ds:[bx].X ; EAX = V1.X-V2.X + mov esi, ds:[si].Y + sub esi, ds:[bx].Y ; ESI = V1.Y-V2.Y + imul edx + mov ebx, eax + xchg ecx, edx ; ECX:EBX = (V1.X-V2.X)*(V3.Y-V2.Y) + mov eax, esi + imul edx ; EDX:EAX = (V1.Y-V2.Y)*(V3.X-V2.X) + sub eax, ebx + sbb edx, ecx + jl @@Next ; Polygon is visible + mov bx, WORD PTR [Dest] ; FS:BX -> current Dest entry + mov WORD PTR fs:[bx], -1 ; Remove polygon +@@Next: + add WORD PTR [Dest], 2 ; Next entry for dest + add di, [Step] ; Next polygon + dec [Count] + jnz @@Loop + + ret +tdBackPlaneCull ENDP + +MATH_TEXT ENDS +END diff --git a/16/x/modex/THREED.H b/16/x/modex/THREED.H new file mode 100755 index 00000000..b993ef86 --- /dev/null +++ b/16/x/modex/THREED.H @@ -0,0 +1,32 @@ +typedef struct { + long x, y, z; +} TVECTOR; + +#define PVECTOR TVECTOR far * + +#define TPOINT TVECTOR +#define PPOINT PVECTOR + +#define VPTR void far * + +#ifdef __cplusplus +extern "C" { +#endif + +long far pascal tdFixedMul( long, long ); +int far pascal tdGetSurfaceLight( PPOINT ); +long far pascal tdTransformToImage( VPTR, VPTR, short, short, short ); + +void far pascal tdBackPlaneCull( VPTR, VPTR, VPTR, short, short ); +void far pascal tdGetNormal( VPTR, PPOINT, PPOINT, PPOINT ); +void far pascal tdRotate( VPTR, VPTR, short ); +void far pascal tdSetLight( PVECTOR ); +void far pascal tdSetRotation( short, short, short ); +void far pascal tdSetTranslation( PVECTOR ); +void far pascal tdSetPerspective( long, long, long ); +void far pascal tdTransform( VPTR, VPTR, short ); +void far pascal tdTransformLight( VPTR, VPTR, short ); + +#ifdef __cplusplus +} +#endif diff --git a/16/x/modex/THREED.PAS b/16/x/modex/THREED.PAS new file mode 100755 index 00000000..8b712c9d --- /dev/null +++ b/16/x/modex/THREED.PAS @@ -0,0 +1,40 @@ +unit ThreeD; +interface + +type + TVector = record + X, Y, Z : longint; + end; + TPoint = TVector; + +function tdFixedMul( F1, F2: longint ): longint; +function tdGetSurfaceLight( var Normal: TPoint ): integer; +function tdTransformToImage( var Source, Dest; Count, DeltaX, DeltaY: integer ): longint; + +procedure tdBackPlaneCull( var Poly, Vertex, Dest; Count, Step: word ); +procedure tdGetNormal( var Dest, P1, P2, P3: TVector ); +procedure tdRotate( var Source, Dest; Count: word ); +procedure tdSetLight( var Light: TVector ); +procedure tdSetRotation( RX, RY, RZ: word ); +procedure tdSetTranslation( var TV: TVector ); +procedure tdSetPerspective( PD, XF, YF: longint ); +procedure tdTransform( var Source, Dest; Count: word ); +procedure tdTransformLight( var Source, Dest; Count: word ); + +implementation + +function tdGetSurfaceLight; external; +procedure tdSetRotation( RX, RY, RZ: word ); external; +procedure tdGetNormal; external; +procedure tdSetTranslation( var TV: TVector ); external; +procedure tdTransform( var Source, Dest; Count: word ); external; +procedure tdRotate; external; +function tdTransformToImage; external; +procedure tdSetLight( var Light: TVector ); external; +procedure tdSetPerspective; external; +procedure tdTransformLight; external; +function tdFixedMul( F1, F2: longint ): longint; external; +procedure tdBackPlaneCull; external; +{$L THREED} + +end. diff --git a/16/x/mxbb.asm b/16/x/mxbb.asm new file mode 100755 index 00000000..ac6668ce --- /dev/null +++ b/16/x/mxbb.asm @@ -0,0 +1,278 @@ +;----------------------------------------------------------- +; +; MXBB.ASM - Bit block transfer +; Copyright (c) 1993,1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +NOWARN RES +INCLUDE MODEX.DEF + +PUBLIC mxBitBlt + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +EXTRN subHorizontalLineInfo : NEAR + +EXTRN mx_VideoSegment : WORD +EXTRN mx_BytesPerLine : WORD + +;----------------------------------------------------------- +; +; Moves a block of video memory. +; +; Input: +; SX, SY = source coordinates +; Width = source width +; Height = source height +; DX, DY = destination coordinates +; Output: +; none +; +; Note: overlapping regions are not allowed. +; +mxBitBlt PROC FAR + ARG DestY:WORD, \ + DestX:WORD, \ + Height:WORD, \ + Width:WORD, \ + SY:WORD, \ + SX:WORD = ARG_SIZE + LOCAL PlaneWidth:WORD:4, \ + SourceOffset:WORD, \ + DestOffset:WORD, \ + Count:BYTE, \ + ReadPlane:BYTE, \ + WritePlane:BYTE, \ + LeftMask:BYTE, \ + RightMask:BYTE = AUTO_SIZE + .enter AUTO_SIZE + .push ds, si, es, di + +; Exit now if null width + cmp [Width], 0 + je @@Exit + +; Calls the proper procedure to handle transfer + mov ax, [SX] + and al, 03h ; AL = source plane + mov dx, [DestX] + and dl, 03h ; DL = destination plane + mov bx, OFFSET subPlaneBlt + cmp al, dl ; Same source and destination plane? + jne @@BitBlt ; No, use slow procedure + mov bx, OFFSET subMoveBlt +@@BitBlt: + call bx + +@@Exit: + xor ax, ax + .pop ds, si, es, di + .leave ARG_SIZE + +;----------------------------------------------------------- +; Uses write mode 1 for maximum speed. Only works if source +; and destination are plane-aligned. +; +subMoveBlt PROC NEAR +; Get horizontal line info and address of destination + mov bx, [DestX] + mov ax, [DestY] + mov cx, [Width] + call subHorizontalLineInfo + mov [LeftMask], al + mov [RightMask], ah + mov [Width], cx + +; Setup segments + mov ax, [mx_VideoSegment] + mov ds, ax + mov es, ax + +; Get address of source pixel + mov ax, [SY] + mul [mx_BytesPerLine] + mov si, [SX] + .shr si, 2 + add si, ax + +; Set write mode 1 + mov dx, GDC + mov ax, 4105h + out dx, ax + cld + +; Move left block +@@L0: + mov ah, [LeftMask] + or ah, ah + jz @@C0 + mov dx, TS + mov al, 02h + out dx, ax ; Set write plane mask + mov ax, [mx_BytesPerLine] + dec ax + mov cx, [Height] + .push si, di +@@L1: + movsb + add si, ax + add di, ax + dec cx + jnz @@L1 + .pop si, di + inc si + inc di + +; Move center block +@@C0: + mov bx, [Width] + test bx, bx + jz @@R0 + mov dx, TS + mov ax, 0F02h + out dx, ax ; Enable all planes + mov ax, [mx_BytesPerLine] + sub ax, bx + mov dx, [Height] + .push si, di +@@C1: + mov cx, bx ; CX = image width + rep movsb ; Cannot use "movsw" here! + add si, ax ; Next scan line + add di, ax ; Next scan line + dec dx ; All lines processed? + jnz @@C1 ; No, continue + .pop si, di + add si, bx + add di, bx + +; Move right block +@@R0: + mov ah, [RightMask] + or ah, ah + jz @@Done + mov dx, TS + mov al, 02h + out dx, ax ; Set write plane mask + mov ax, [mx_BytesPerLine] + dec ax + mov cx, [Height] +@@R1: + movsb + add si, ax + add di, ax + dec cx + jnz @@R1 + +@@Done: + mov dx, GDC + mov ax, 4005h + out dx, ax ; Restore write mode 0 + +@@Exit: + ret +subMoveBlt ENDP + +;----------------------------------------------------------- +; Moves one plane at a time. +; +subPlaneBlt PROC NEAR +; Compute extra bytes and width count for each plane + mov cx, [Width] + mov bx, cx + shr bx, 1 + shr bx, 1 ; Width for each plane + and cl, 03h + mov al, 00001000b + shr al, cl + mov si, 3 SHL 1 +@@PatchLoop: + mov PlaneWidth[si], bx + shr al, 1 + adc bx, 0 + dec si + dec si + jge @@PatchLoop + +; Get pixel addresses + mov ax, [mx_VideoSegment] + mov ds, ax + mov es, ax + mov ax, [SY] + mul [mx_BytesPerLine] + mov si, [SX] + shr si, 1 + shr si, 1 + add si, ax ; DS:SI points to source + mov [SourceOffset], si + mov ax, [DestY] + mul [mx_BytesPerLine] + mov di, [DestX] + shr di, 1 + shr di, 1 + add di, ax ; ES:DI points to destination + mov [DestOffset], di + +; Adjust plane for output to VGA registers + mov ax, [SX] + and al, 03h + mov [ReadPlane], al + mov cx, [DestX] + and cl, 03h + mov al, 00010001b + shl al, cl + mov [WritePlane], al + +; Ready to move now + cld + mov [Count], 4 ; Four planes + lea bx, PlaneWidth ; SS:[BX] = width in bytes for plane +@@PlaneLoop: + cmp WORD PTR ss:[bx], 0 + je @@Done + mov ah, [WritePlane] + and ah, 0Fh + mov al, 02h + mov dx, TS + out dx, ax ; Select write plane + mov ah, [ReadPlane] + mov al, 04h + mov dx, GDC + out dx, ax ; Select read plane + mov dx, [Height] + mov ax, [mx_BytesPerLine] + sub ax, ss:[bx] ; AX = extra bytes per line +@@Loop: + mov cx, ss:[bx] + shr cx, 1 + rep movsw + rcl cx, 1 + rep movsb + add si, ax + add di, ax + dec dx + jnz @@Loop ; Repeat for all lines + inc bx + inc bx ; Select width for next plane + inc [ReadPlane] + and [ReadPlane], 03h ; Should be faster on 386 using + jnz @@ReadPlaneOk ; BTR and ADC... + inc [SourceOffset] +@@ReadPlaneOk: + rol [WritePlane], 1 + adc [DestOffset], 0 + mov si, [SourceOffset] + mov di, [DestOffset] + dec [Count] + jnz @@PlaneLoop ; Repeat for all planes + +@@Done: + ret +subPlaneBlt ENDP + +mxBitBlt ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxcc.asm b/16/x/mxcc.asm new file mode 100755 index 00000000..4f78adb9 --- /dev/null +++ b/16/x/mxcc.asm @@ -0,0 +1,644 @@ +;----------------------------------------------------------- +; +; MXCC.ASM - Fast clip line function +; Copyright (c) 1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +NOWARN RES +INCLUDE MODEX.DEF + +PUBLIC xsubClipLine + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +EXTRN mx_BytesPerLine : WORD +EXTRN mx_VideoSegment : WORD + +EXTRN mx_ClipX1 : WORD +EXTRN mx_ClipY1 : WORD +EXTRN mx_ClipX2 : WORD +EXTRN mx_ClipY2 : WORD + +tblGroups LABEL WORD + DW 10, tbl00 + DW 10, tbl10 + DW 9, tbl20 + DW -1, 0 + DW 10, tbl40 + DW 10, tbl50 + DW 9, tbl60 + DW -1, 0 + DW 6, tbl80 + DW 6, tbl90 + DW 5, tblA0 + DW -1, 0 + DW -1, 0 + DW -1, 0 + DW -1, 0 + DW -1, 0 +tbl00 DW cc00, cc01, cc02, ccFF, cc04, cc05, cc06, ccFF, cc08, cc09, cc0A +tbl10 DW cc10, ccFF, cc12, ccFF, cc14, ccFF, cc16, ccFF, cc18, ccFF, cc1A +tbl20 DW cc20, cc21, ccFF, ccFF, cc24, cc25, ccFF, ccFF, cc28, cc29 +tbl40 DW cc40, cc41, cc42, ccFF, ccFF, ccFF, ccFF, ccFF, cc48, cc49, cc4A +tbl50 DW cc50, ccFF, cc52, ccFF, ccFF, ccFF, ccFF, ccFF, cc58, ccFF, cc5A +tbl60 DW cc60, cc61, ccFF, ccFF, ccFF, ccFF, ccFF, ccFF, cc68, cc69 +tbl80 DW cc80, cc81, cc82, ccFF, cc84, cc85, cc86 +tbl90 DW cc90, ccFF, cc92, ccFF, cc94, ccFF, cc96 +tblA0 DW ccA0, ccA1, ccFF, ccFF, ccA4, ccA5 + +ccTT: clc + ret +ccFF: stc + ret + +; Group 00 ------------------------------------------------- +; +cc00: + clc + ret +cc01: + jmp ClipQLeft +cc02: + jmp ClipQRight +cc04: + jmp ClipQTop +cc05: + call ClipQLeft + cmp si, [mx_ClipY1] + jge ccTT + jmp ClipQTop +cc06: + call ClipQRight + cmp si, [mx_ClipY1] + jge ccTT + jmp ClipQTop +cc08: + jmp ClipQBottom +cc09: + call ClipQLeft + cmp si, [mx_ClipY2] + jle ccTT + jmp ClipQBottom +cc0A: + call ClipQRight + cmp si, [mx_ClipY2] + jle ccTT + jmp ClipQBottom + +; Group 10 ------------------------------------------------- +; +cc10FF: + stc + ret +cc10TT: + clc + ret +cc10: + jmp ClipPLeft +cc12: + call ClipPLeft + jmp ClipQRight +cc14: + call ClipPLeft + cmp bx, [mx_ClipY1] + jl cc10FF + jmp ClipQTop +cc16: + call ClipPLeft + cmp bx, [mx_ClipY1] + jl cc10FF + call ClipQTop + cmp cx, [mx_ClipX2] + jle cc10TT + jmp ClipQRight +cc18: + call ClipPLeft + cmp bx, [mx_ClipY2] + jg cc10FF + jmp ClipQBottom +cc1A: + call ClipPLeft + cmp bx, [mx_ClipY2] + jg cc10FF + call ClipQBottom + cmp cx, [mx_ClipX2] + jle cc10TT + jmp ClipQRight + +; Group 20 ------------------------------------------------- +; +cc20TT: + clc + ret +cc20FF: + stc + ret +cc20: + jmp ClipPRight +cc21: + call ClipPRight + jmp ClipQLeft +cc24: + call ClipPRight + cmp bx, [mx_ClipY1] + jl cc20FF + jmp ClipQTop +cc25: + call ClipPRight + cmp bx, [mx_ClipY1] + jl cc20FF + call ClipQTop + cmp cx, [mx_ClipX1] + jge cc20TT + jmp ClipQLeft +cc28: + call ClipPRight + cmp bx, [mx_ClipY2] + jg cc20FF + jmp ClipQBottom +cc29: + call ClipPRight + cmp bx, [mx_ClipY2] + jg cc20FF + call ClipQBottom + cmp cx, [mx_ClipX1] + jge cc20TT + jmp ClipQLeft + +; Group 40 ------------------------------------------------- +; +cc40TT: + clc + ret +cc40FF: + stc + ret +cc40: + jmp ClipPTop +cc41: + call ClipPTop + cmp di, [mx_ClipX1] + jl cc40FF + call ClipQLeft + cmp si, [mx_ClipY1] + jge cc40TT + jmp ClipQTop +cc42: + call ClipPTop + cmp di, [mx_ClipX2] + jg cc40FF + jmp ClipQRight +cc48: + call ClipPTop + jmp ClipQBottom +cc49: + call ClipPTop + cmp di, [mx_ClipX1] + jl cc40FF + call ClipQLeft + cmp si, [mx_ClipY2] + jle cc40TT + jmp ClipQBottom +cc4A: + call ClipPTop + cmp di, [mx_ClipX2] + jg cc40FF + call ClipQRight + cmp si, [mx_ClipY2] + jle cc40TT + jmp ClipQBottom + + +; Group 50 ------------------------------------------------- +; +cc50TT: + clc + ret +cc50FF: + stc + ret +cc50: + call ClipPLeft + cmp bx, [mx_ClipY1] + jge cc50TT + jmp ClipPTop +cc52: + call ClipQRight + cmp si, [mx_ClipY1] + jl cc50FF + call ClipPTop + cmp di, [mx_ClipX1] + jge cc50TT + jmp ClipPLeft +cc58: + call ClipQBottom + cmp cx, [mx_ClipX1] + jl cc50FF + call ClipPTop + cmp di, [mx_ClipX1] + jge cc50TT + jmp ClipPLeft +cc5A: + call ClipPLeft + cmp bx, [mx_ClipY2] + jg cc50FF + call ClipQRight + cmp bx, [mx_ClipY1] + jl cc50FF + cmp si, [mx_ClipY2] + jle cc50TT + jmp ClipQBottom + +; Group 60 ------------------------------------------------- +; +cc60TT: + clc + ret +cc60FF: + stc + ret +cc60: + call ClipPRight + cmp bx, [mx_ClipY1] + jge cc60TT + jmp ClipPTop +cc61: + call ClipQLeft + cmp si, [mx_ClipY2] + jl cc60FF + call ClipPTop + cmp di, [mx_ClipX2] + jle cc60TT + jmp ClipPRight +cc68: + call ClipQBottom + cmp cx, [mx_ClipX2] + jg cc60FF + call ClipPRight + cmp bx, [mx_ClipY1] + jge cc60TT + jmp ClipPTop +cc69: + call ClipQLeft + cmp si, [mx_ClipY1] + jl cc60FF + call ClipPRight + cmp bx, [mx_ClipY2] + jg cc60FF + cmp si, [mx_ClipY2] + jle cc69_1 + call ClipQBottom +cc69_1: + cmp bx, [mx_ClipY1] + jge cc60TT + jmp ClipPTop + +; Group 80 ------------------------------------------------- +; +cc80TT: + clc + ret +cc80FF: + stc + ret +cc80: + jmp ClipPBottom +cc81: + call ClipPBottom + cmp di, [mx_ClipX1] + jl cc80FF + jmp ClipQLeft +cc82: + call ClipPBottom + cmp di, [mx_ClipX2] + jg cc80FF + jmp ClipQRight +cc84: + call ClipPBottom + jmp ClipQTop +cc85: + call ClipPBottom + cmp di, [mx_ClipX1] + jl cc80FF + call ClipQLeft + cmp si, [mx_ClipY1] + jge cc80FF + jmp ClipQTop +cc86: + call ClipPBottom + cmp di, [mx_ClipX2] + jg cc80FF + call ClipQRight + cmp si, [mx_ClipY1] + jge cc80TT + jmp ClipQTop + +; Group 90 ------------------------------------------------- +; +cc90TT: + clc + ret +cc90FF: + stc + ret +cc90: + call ClipPLeft + cmp bx, [mx_ClipY2] + jle cc90TT + jmp ClipPBottom +cc92: + call ClipQRight + cmp si, [mx_ClipY2] + jg cc90FF + call ClipPBottom + cmp di, [mx_ClipX1] + jge cc90TT + jmp ClipPLeft +cc94: + call ClipQTop + cmp cx, [mx_ClipX1] + jl cc90FF + call ClipPLeft + cmp bx, [mx_ClipY2] + jle cc90TT + jmp ClipPBottom +cc96: + call ClipPLeft + cmp bx, [mx_ClipY1] + jl cc90FF + call ClipQRight + cmp si, [mx_ClipY2] + jg cc90FF + cmp bx, [mx_ClipY2] + jle cc96_1 + call ClipPBottom +cc96_1: + cmp si, [mx_ClipY1] + jge cc90TT + jmp ClipQTop + +; Group A0 ------------------------------------------------- +; +ccA0TT: + clc + ret +ccA0FF: + stc + ret +ccA0: + call ClipPRight + cmp bx, [mx_ClipY2] + jle ccA0TT + jmp ClipPBottom +ccA1: + call ClipQLeft + cmp si, [mx_ClipY2] + jg ccA0FF + call ClipPBottom + cmp di, [mx_ClipX2] + jle ccA0TT + jmp ClipPRight +ccA4: + call ClipQTop + cmp cx, [mx_ClipX2] + jg ccA0FF + call ClipPRight + cmp bx, [mx_ClipY2] + jle ccA0TT + jmp ClipPBottom +ccA5: + call ClipQLeft + cmp si, [mx_ClipY2] + jg ccA0FF + call ClipPRight + cmp bx, [mx_ClipY1] + jl ccA0FF + cmp si, [mx_ClipY1] + jge ccA5_1 + call ClipQTop +ccA5_1: + cmp bx, [mx_ClipY2] + jle ccA0TT + jmp ClipPBottom + +; Y1 = (Y2-Y1)*(mx_ClipX1-X1)/(X2-X1)+Y1 = (SI-BX)*(mx_ClipX1-DI)/(CX-DI)+BX +; X1 = mx_ClipX1 +ClipPLeft: + mov ax, si + sub ax, bx + mov dx, [mx_ClipX1] + sub dx, di + imul dx + mov bp, cx + sub bp, di + idiv bp + add bx, ax + mov di, [mx_ClipX1] + clc + ret + +; Y1 = (Y2-Y1)*(mx_ClipX2-X1)/(X2-X1)+Y1 = (SI-BX)*(mx_ClipX2-DI)/(CX-DI)+BX +; X1 = mx_ClipX2 +ClipPRight: + mov ax, si + sub ax, bx + mov dx, [mx_ClipX2] + sub dx, di + imul dx + mov bp, cx + sub bp, di + idiv bp + add bx, ax + mov di, [mx_ClipX2] + clc + ret + +; X1 = (X2-X1)*(mx_ClipY2-Y1)/(Y2-Y1)+X1 = (CX-DI)*(mx_ClipY2-BX)/(SI-BX)+DI +; Y1 = mx_ClipY2 +ClipPBottom: + mov ax, cx + sub ax, di + mov dx, [mx_ClipY2] + sub dx, bx + imul dx + mov bp, si + sub bp, bx + idiv bp + add di, ax + mov bx, [mx_ClipY2] + clc + ret + +; X1 = (X2-X1)*(mx_ClipY1-Y1)/(Y2-Y1)+X1 = (CX-DI)*(mx_ClipY1-BX)/(SI-BX)+DI +; Y1 = mx_ClipY1 +ClipPTop: + mov ax, cx + sub ax, di + mov dx, [mx_ClipY1] + sub dx, bx + imul dx + mov bp, si + sub bp, bx + idiv bp + add di, ax + mov bx, [mx_ClipY1] + clc + ret + +; Y2 = (Y1-Y2)*(mx_ClipX1-X2)/(X1-X2)+Y2 = (BX-SI)*(mx_ClipX1-CX)/(DI-CX)+SI +; X2 = mx_ClipX1 +ClipQLeft: + mov ax, bx + sub ax, si + mov dx, [mx_ClipX1] + sub dx, cx + imul dx + mov bp, di + sub bp, cx + idiv bp + add si, ax + mov cx, [mx_ClipX1] + clc + ret + +; Y2 = (Y1-Y2)*(mx_ClipX2-X2)/(X1-X2)+Y2 = (BX-SI)*(mx_ClipX2-CX)/(DI-CX)+SI +; X2 = mx_ClipX1 +ClipQRight: + mov ax, bx + sub ax, si + mov dx, [mx_ClipX2] + sub dx, cx + imul dx + mov bp, di + sub bp, cx + idiv bp + add si, ax + mov cx, [mx_ClipX2] + clc + ret + +; X2 = (X1-X2)*(mx_ClipY2-Y2)/(Y1-Y2)+X2 = (DI-CX)*(mx_ClipY2-SI)/(BX-SI)+CX +; Y2 = mx_ClipY1 +ClipQBottom: + mov ax, di + sub ax, cx + mov dx, [mx_ClipY2] + sub dx, si + imul dx + mov bp, bx + sub bp, si + idiv bp + add cx, ax + mov si, [mx_ClipY2] + clc + ret + +; X2 = (X1-X2)*(mx_ClipY1-Y2)/(Y1-Y2)+X2 = (DI-CX)*(mx_ClipY1-SI)/(BX-SI)+CX +; Y2 = mx_ClipY1 +ClipQTop: + mov ax, di + sub ax, cx + mov dx, [mx_ClipY1] + sub dx, si + imul dx + mov bp, bx + sub bp, si + idiv bp + add cx, ax + mov si, [mx_ClipY1] + clc + ret + +;----------------------------------------------------------- +; +; Checks the coordinates of a line against the active +; clip region. +; Uses the Sobkow-Pospisil-Yang (SPY) algorithm: this was +; supposed to be twice as fast as Cohen-Sutherland, but my +; tests show only a very small increase in speed and a noticeable +; increase of the program size! Maybe this is caused by the +; slow speed of VGA cards, so probably a better test should +; be performed with lines drawn in RAM. +; +; Input: +; AX, BX = X1, Y1 +; CX, DX = X2, Y2 +; Output: +; CF = set if line is full clipped +; AX, BX = clipped X1, Y1 +; CX, DX = clipped X2, Y2 +; Note: +; destroys SI, DI +; +xsubClipLine PROC NEAR + push bp + xor si, si ; SPY code + + cmp dx, [mx_ClipY2] + jle @@1 + or si, 08h + jmp @@2 +@@1: + cmp dx, [mx_ClipY1] + jge @@2 + or si, 04h +@@2: + + cmp cx, [mx_ClipX2] + jle @@3 + or si, 02h + jmp @@4 +@@3: + cmp cx, [mx_ClipX1] + jge @@4 + or si, 01h +@@4: + + cmp bx, [mx_ClipY2] + jle @@5 + or si, 80h + jmp @@6 +@@5: + cmp bx, [mx_ClipY1] + jge @@6 + or si, 40h +@@6: + + cmp ax, [mx_ClipX2] + jle @@7 + or si, 20h + jmp @@8 +@@7: + cmp ax, [mx_ClipX1] + jge @@8 + or si, 10h +@@8: + + mov di, si + and di, 000Fh ; Index of procedure + and si, 00F0h + .shr si, 2 ; Index of group (times 4) + cmp di, cs:tblGroups[si] ; Is index within range? + jg @@Exit ; No, line is full clipped + mov si, cs:tblGroups[si+2] ; Get offset of group table + shl di, 1 ; We must index word elements + add si, di ; Make full offset + mov di, ax ; Move X1 to DI and free AX + mov si, cs:[si] ; Get subroutine address + xchg dx, si ; Move Y2 to SI and free DX + call dx ; Call the proper subroutine + mov ax, di ; Restore AX to X1 + mov dx, si ; Restore DX to Y2 + pop bp + ret + +@@Exit: + pop bp + stc + ret +xsubClipLine ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxcg.asm b/16/x/mxcg.asm new file mode 100755 index 00000000..42163d7a --- /dev/null +++ b/16/x/mxcg.asm @@ -0,0 +1,69 @@ +;----------------------------------------------------------- +; +; MXCG.ASM - Color to gray conversion +; Copyright (c) 1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +INCLUDE MODEX.DEF + +PUBLIC mxColorToGray + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +;----------------------------------------------------------- +; +; Converts RGB colors to gray shades. +; +; Input: +; CPal = pointer to color palette +; GPal = pointer to destination (gray) palette +; Count = number of colors to convert +; Output: +; none +; +; Note: CPal and GPal may point to the same buffer. +; +mxColorToGray PROC FAR + ARG Count:WORD, \ + DPal:DWORD, \ + SPal:DWORD = ARG_SIZE + ASSUME ds:NOTHING + .enter 0 + .push ds, si, es, di + + mov cx, [Count] + jcxz @@Exit + lds si, [SPal] + les di, [DPal] + cld +; We use the standard formula +; gray=(red*30 + green*59 + blue*11)/100 +; in the equivalent form +; gray=(red*77 + green*151 + blue*28)/256 +; which doesn't need the last divide. + mov bx, 77 SHL 8 + 151 +@@Loop: + lodsb ; Red + mul bh + mov dx, ax + lodsb ; Green + mul bl + add dx, ax + lodsb ; Blue + mov ah, 28 + mul ah + add ax, dx + mov al, ah + stosw ; Save new RGB + stosb + loop @@Loop + +@@Exit: + .pop ds, si, es, di + .leave ARG_SIZE +mxColorToGray ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxcl.asm b/16/x/mxcl.asm new file mode 100755 index 00000000..aaa0bac3 --- /dev/null +++ b/16/x/mxcl.asm @@ -0,0 +1,151 @@ +;----------------------------------------------------------- +; +; MXCL.ASM - Bresenham circle +; Copyright (c) 1993,1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +NOWARN RES +INCLUDE MODEX.DEF + +PUBLIC mxCircle + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +EXTRN mx_BytesPerLine : WORD +EXTRN mx_VideoSegment : WORD +EXTRN mx_ClipX1 : WORD +EXTRN mx_ClipY1 : WORD +EXTRN mx_ClipX2 : WORD +EXTRN mx_ClipY2 : WORD + +;----------------------------------------------------------- +; +; Draws a circle using the Bresenham algorithm. +; +; Input: +; XC, YC = center coordinates +; Radius = circle radius +; Color = circle color +; Output: +; none +; Note: +; computes only points in the first octant, all other +; points are obtained by symmetry. +; +mxCircle PROC FAR + ARG Color:BYTE:2, \ + Radius:WORD, \ + YC:WORD, \ + XC:WORD = ARG_SIZE + LOCAL Delta:WORD = AUTO_SIZE + .enter AUTO_SIZE + .push ds, si, di + + xor si, si ; X + mov di, [Radius] ; Y + mov ax, 3 + sub ax, di + sub ax, di + mov [Delta], ax ; Delta = 3-R*2 + + mov ds, [mx_VideoSegment] + +@@Loop: + cmp si, di ; + jg @@Done ; Exit when X > Y +; Draw points + mov ax, si + mov bx, di + call @@subPutPixel + mov ax, si + neg ax + mov bx, di + call @@subPutPixel + mov ax, si + mov bx, di + neg bx + call @@subPutPixel + mov ax, si + neg ax + mov bx, di + neg bx + call @@subPutPixel + mov ax, di + mov bx, si + call @@subPutPixel + mov ax, di + neg ax + mov bx, si + call @@subPutPixel + mov ax, di + mov bx, si + neg bx + call @@subPutPixel + mov ax, di + neg ax + mov bx, si + neg bx + call @@subPutPixel +; Moves coordinates to next point + mov ax, [Delta] + test ax, ax + jl @@Next + mov ax, di + .shl ax, 2 + sub ax, 4 + sub [Delta], ax + dec di +@@Next: + mov ax, si + .shl ax, 2 + add ax, 6 + add [Delta], ax + inc si + jmp @@Loop + +@@Done: + xor ax, ax + .pop ds, si, di + .leave ARG_SIZE + +;--------------------------------------- +; Put pixel function. +; Input: +; BX = X coordinate (relative to center) +; AX = Y coordinate (relative to center) +; DS = video segment +@@subPutPixel: + add bx, [XC] ; Get absolute coordinates + add ax, [YC] + + cmp bx, [mx_ClipX1] ; Clip pixel + jl @@subExit + cmp bx, [mx_ClipX2] + jg @@subExit + cmp ax, [mx_ClipY1] + jl @@subExit + cmp ax, [mx_ClipY2] + jg @@subExit + + mul [mx_BytesPerLine] ; Get pixel offset + mov cx, bx ; Save X coordinate + .shr bx, 2 + add bx, ax ; DS:BX = pixel offset + + and cl, 3 ; Set write plane + mov ax, 0102h + shl ah, cl + mov dx, TS + out dx, ax + + mov al, [Color] ; Write pixel + mov ds:[bx], al + +@@subExit: + retn +mxCircle ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxcr.asm b/16/x/mxcr.asm new file mode 100755 index 00000000..ca1fa7bb --- /dev/null +++ b/16/x/mxcr.asm @@ -0,0 +1,380 @@ +;----------------------------------------------------------- +; +; MXCR.ASM - Clip functions +; Copyright (c) 1993,1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +NOWARN RES +INCLUDE MODEX.DEF + +PUBLIC mxSetSysClipRegion +PUBLIC mxGetClipRegion +PUBLIC mxSetClipRegion +PUBLIC mxSetClip +PUBLIC mxGetClip + +PUBLIC subClipBox +PUBLIC subClipImage + +PUBLIC mx_ClipX1 +PUBLIC mx_ClipY1 +PUBLIC mx_ClipX2 +PUBLIC mx_ClipY2 + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +EXTRN mx_CodeSegment : WORD + +mx_ClipX1 DW ? ; Clip coordinates +mx_ClipY1 DW ? +mx_ClipX2 DW ? +mx_ClipY2 DW ? + +mx_SysClipX1 DW ? ; System clip coordinates +mx_SysClipY1 DW ? ; (active when mx_ClipStatus is FALSE) +mx_SysClipX2 DW ? +mx_SysClipY2 DW ? + +mx_UserClipX1 DW ? ; User clip coordinates +mx_UserClipY1 DW ? ; (active when mx_ClipStatus is TRUE) +mx_UserClipX2 DW ? +mx_UserClipY2 DW ? + +mx_ClipStatus DB ? + +;----------------------------------------------------------- +; +; Toggles clipping between user and system regions. +; +; Input: +; ClipStatus = TRUE (FALSE) to enable (disable) clipping +; Output: +; AX = old clip status +; +mxSetClip PROC FAR + ARG ClipStatus:BYTE:2 = ARG_SIZE + ASSUME ds:NOTHING + .enter 0 + .push ds + mov ds, [mx_CodeSegment] + ASSUME ds:MX_TEXT + + mov ax, [mx_UserClipX1] + mov bx, [mx_UserClipY1] + mov cx, [mx_UserClipX2] + mov dx, [mx_UserClipY2] + cmp [ClipStatus], TRUE + je @@Done + mov ax, [mx_SysClipX1] + mov bx, [mx_SysClipY1] + mov cx, [mx_SysClipX2] + mov dx, [mx_SysClipY2] +@@Done: + mov [mx_ClipX1], ax + mov [mx_ClipY1], bx + mov [mx_ClipX2], cx + mov [mx_ClipY2], dx + + mov al, [ClipStatus] + xchg al, [mx_ClipStatus] + xor ah, ah + + .pop ds + .leave ARG_SIZE +mxSetClip ENDP + +;----------------------------------------------------------- +; +; Returns the current clipping status. +; +; Input: +; none +; Output: +; TRUE (FALSE) if clipping enabled (disabled) +; +mxGetClip PROC FAR + ASSUME ds:NOTHING + mov al, [mx_ClipStatus] + xor ah, ah + ret +mxGetClip ENDP + +;----------------------------------------------------------- +; +; Sets the system clip region and disables user clipping. +; +; Input: +; Width = width in pixels of clip region +; Height = height in pixels of clip region +; Output: +; old clip status. +; +mxSetSysClipRegion PROC FAR + ARG Height:WORD, \ + Width:WORD = ARG_SIZE + ASSUME ds:NOTHING + .enter 0 + .push ds + mov ds, [mx_CodeSegment] + ASSUME ds:MX_TEXT + + xor ax, ax ; Sys clip region always starts at (0,0) + mov [mx_SysClipX1], ax + mov [mx_SysClipY1], ax + mov ax, [Width] + dec ax + mov [mx_SysClipX2], ax + mov ax, [Height] + dec ax + mov [mx_SysClipY2], ax + + IF USE286 EQ TRUE + push FALSE + ELSE + mov ax, FALSE + push ax + ENDIF + call mxSetClip + + .pop ds + .leave ARG_SIZE +mxSetSysClipRegion ENDP + +;----------------------------------------------------------- +; +; Sets the clip region. +; +; Input: +; X, Y = coordinates of top left corner of clip region +; Width = width in pixels of clip region +; Height = height in pixels of clip region +; Output: +; none (no checking on parameters) +; +mxSetClipRegion PROC FAR + ARG Height:WORD, \ + Width:WORD, \ + Y:WORD, \ + X:WORD = ARG_SIZE + ASSUME ds:NOTHING + .enter 0 + .push ds + mov ds, [mx_CodeSegment] + ASSUME ds:MX_TEXT + + mov ax, [X] + mov [mx_UserClipX1], ax + mov ax, [Y] + mov [mx_UserClipY1], ax + mov ax, [Width] + add ax, [X] + dec ax + mov [mx_UserClipX2], ax + mov ax, [Height] + add ax, [Y] + dec ax + mov [mx_UserClipY2], ax + + mov al, [mx_ClipStatus] + cmp al, TRUE + jne @@Exit + push ax + call mxSetClip + +@@Exit: + xor ax, ax + .pop ds + .leave ARG_SIZE +mxSetClipRegion ENDP + +;----------------------------------------------------------- +; +; Returns the current user clip region. +; +; Input: +; X, Y = pointers to integer coordinates of top left corner +; Width = pointer to word width of clip region +; Height = pointer to word height of clip region +; Output: +; AX = current clip status +; +mxGetClipRegion PROC FAR + ARG Height:DWORD, \ + Width:DWORD, \ + Y:DWORD, \ + X:DWORD = ARG_SIZE + ASSUME ds:NOTHING + .enter 0 + .push es, di + + mov ax, [mx_UserClipX1] + les di, [X] + mov es:[di], ax + mov ax, [mx_UserClipY1] + les di, [Y] + mov es:[di], ax + + mov ax, [mx_UserClipX2] + sub ax, [mx_UserClipX1] + inc ax + les di, [Width] + mov es:[di], ax + mov ax, [mx_UserClipY2] + sub ax, [mx_UserClipY1] + inc ax + les di, [Height] + mov es:[di], ax + + mov al, [mx_ClipStatus] + xor ah, ah + .pop es, di + .leave ARG_SIZE +mxGetClipRegion ENDP + +;----------------------------------------------------------- +; +; Internal use: checks the coordinates of a rectangle against +; the active clip region. +; This function assumes that a "raw" image has to be clipped, +; so it returns in SI the number of "raw" bytes to skip if +; X, Y were clipped. +; +; Input: +; BX, AX = X, Y coordinates of rectangle (signed) +; CX = box width +; DX = box height +; Output: +; CF = set if rectangle is full clipped +; BX, AX = new X, Y coordinates of rectangle +; CX, DX = clipped width and height +; SI = number of bytes to skip before copying a buffer +; DI destroyed +; +subClipImage PROC NEAR + ASSUME ds:NOTHING + xor si, si + +; Check clip height + mov di, [mx_ClipY1] + cmp ax, di + jge @@CheckBottom + sub di, ax ; Number of lines to clip + sub dx, di ; New box height + jle @@Exit + mov ax, di + mov di, dx ; Save box height into DI + mul cx ; DX:AX = number of bytes to skip + mov si, ax + mov dx, di ; Restore box height + mov ax, [mx_ClipY1] +@@CheckBottom: + mov di, [mx_ClipY2] + cmp ax, di + jg @@Exit + inc di + sub di, dx + sub di, ax + jge @@DoneHeight ; None, continue + add dx, di ; Clip lines +@@DoneHeight: + +; Check clip width +@@CheckLeft: + mov di, [mx_ClipX1] + cmp bx, di + jge @@CheckRight + sub di, bx ; Number of columns to clip left + sub cx, di + jle @@Exit + add si, di ; Update skip count + mov bx, [mx_ClipX1] +@@CheckRight: + mov di, [mx_ClipX2] + cmp bx, di + jg @@Exit + inc di + sub di, bx + sub di, cx + jge @@DoneWidth ; None, exit + add cx, di ; New box width +@@DoneWidth: + +; Set return flag and exit +@@Done: + clc + ret +@@Exit: + stc + ret +subClipImage ENDP + +;----------------------------------------------------------- +; +; Internal use: checks the coordinates of a rectangle against +; the active clip region. +; +; Input: +; BX, AX = X, Y coordinates of rectangle (signed) +; CX = box width +; DX = box height +; Output: +; CF = set if rectangle is full clipped +; BX, AX = new X, Y coordinates of rectangle +; CX, DX = clipped width and height +; DI destroyed +; +subClipBox PROC NEAR + ASSUME ds:NOTHING + +; Check clip height + mov di, [mx_ClipY1] + cmp ax, di + jge @@CheckBottom + sub di, ax ; Number of lines to clip + sub dx, di ; New box height + jle @@Exit + mov ax, [mx_ClipY1] +@@CheckBottom: + mov di, [mx_ClipY2] + cmp ax, di + jg @@Exit + inc di + sub di, dx + sub di, ax ; Clipped some point? + jge @@DoneHeight ; No, continue + add dx, di ; Clip lines (DI is negative) +@@DoneHeight: + +; Check clip width +@@CheckLeft: + mov di, [mx_ClipX1] + cmp bx, di + jge @@CheckRight + sub di, bx ; Number of columns to clip left + sub cx, di + jle @@Exit + mov bx, [mx_ClipX1] +@@CheckRight: + mov di, [mx_ClipX2] + cmp bx, di + jg @@Exit + inc di + sub di, bx + sub di, cx ; Clipped some point? + jge @@DoneWidth ; No, exit + add cx, di ; New box width (DI is negative) +@@DoneWidth: + +; Set return flag and exit +@@Done: + clc + ret +@@Exit: + stc + ret +subClipBox ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxel.asm b/16/x/mxel.asm new file mode 100755 index 00000000..2c9dda2a --- /dev/null +++ b/16/x/mxel.asm @@ -0,0 +1,167 @@ +;----------------------------------------------------------- +; +; MXEL.ASM - Mid-point ellipse +; Copyright (c) 1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +NOWARN RES +INCLUDE MODEX.DEF + +PUBLIC mxEllipse + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +EXTRN mx_BytesPerLine : WORD +EXTRN mx_VideoSegment : WORD +EXTRN mx_ClipX1 : WORD +EXTRN mx_ClipY1 : WORD +EXTRN mx_ClipX2 : WORD +EXTRN mx_ClipY2 : WORD + +;----------------------------------------------------------- +; +; Draws an ellipse using the mid-point algorithm. +; +; Input: +; XC, YC = center coordinates +; A = horizontal radius +; B = vertical radius +; Color = ellipse color +; Output: +; none +; Note: +; computes only points in the first quadrant, all other +; points are obtained by symmetry. +; +mxEllipse PROC FAR + ARG Color:BYTE:2, \ + B:WORD, \ + A:WORD, \ + YC:WORD, \ + XC:WORD = ARG_SIZE + LOCAL A2:DWORD, \ + B2:DWORD, \ + CC:DWORD, \ + DD:DWORD, \ + X:DWORD, \ + Y:DWORD = AUTO_SIZE + .enter AUTO_SIZE + .push ds, si, di + + .chk386 mxEllipse, @@Exit + +; Initialize variables + xor eax, eax + mov [X], ax ; X = 0 + mov ax, [A] + mul eax ; EAX = A*A + mov [DD], eax ; DD = A*A + shl eax, 1 + mov [CC], eax ; CC = 2*A*A + shl eax, 1 + mov [A2], eax ; A2 = 4*A*A + movzx edx, [B] + mov [Y], edx + mul edx ; EAX = 4*A*A*B + sub [DD], eax ; DD = A*A - 4*A*A*B + movzx eax, [B] + mul eax ; EAX = B*B + shl eax, 2 ; EAX = 4*B*B + mov [B2], eax ; B2 = 4*B*B + add [CC], eax ; CC = 2*A*A + 4*B*B + add [D1], eax ; DD = A*A - 4*A*A*B + 4*B*B + +; Draw initial points + call subPlot4 + +; First loop +@@Loop1: + mov eax, [X] ; Check slope + mul [B2] + mov ecx, eax + mov eax, [Y] + mul [A2] + sub eax, ecx + sub eax, [CC] ; EAX = Y*A2 - X*B2 - CC + jle @@Done1 ; Crossed critical point, jump to next loop + + mov ecx, [DD] ; Get error + test ecx, ecx ; Positive? + jl @@Draw1 ; No, use default step + + mov eax, 1 + sub eax, [Y] + mul [A2] + shl eax, 1 + add ecx, eax ; Bump error + dec WORD PTR [Y] ; Decrement Y coordinate + +@@Draw1: + mov eax, [X] + shl eax, 1 + add eax, 3 + mul [B2] + add ecx, eax ; Bump error + mov [DD], ecx ; Save error + inc WORD PTR [X] ; Increment X coordinate + + call subPlot4 ; Draw points + jmp @@Loop1 +@@Done1: + +; Initialize variables + shr [B2], 2 + mov eax, [X] + mul eax + add [X] + shl eax, 2 + inc eax + mul [B2] + mov [DD], eax + mov eax, [Y] + mul eax + add [Y] + dec eax + add [Y] + sub eax, [B2] + add [DD], eax + shl [B2], 3 + inc WORD PTR [X] + +; Second loop +@@Loop2: + cmp WORD PTR [Y], 0 + ja @@Done2 + + mov ecx, [DD] + test ecx, ecx + jge @@Draw2 + + mov eax, [X] + inc eax + mul [B2] + add ecx, eax + inc WORD PTR [X] + +@@Draw2: + mov eax, [Y] + shl eax, 1 + sub eax, 3 + neg eax + imul [A2] + add ecx, eax + dec WORD PTR [Y] + + call subPlot4 + jmp @@Loop2 +@@Done2: + +@@Exit: + xor ax, ax + .leave ARG_SIZE +mxEllipse ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxfb.asm b/16/x/mxfb.asm new file mode 100755 index 00000000..41ea5deb --- /dev/null +++ b/16/x/mxfb.asm @@ -0,0 +1,194 @@ +;----------------------------------------------------------- +; +; MXFB.ASM - Fill box function +; Copyright (c) 1993,1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +NOWARN RES +INCLUDE MODEX.DEF + +PUBLIC mxFillBox + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +EXTRN mx_BytesPerLine : WORD +EXTRN mx_VideoSegment : WORD +EXTRN subClipBox : NEAR +EXTRN subHorizontalLineInfo : NEAR + +;----------------------------------------------------------- +; +; Raster op functions. Raster op is limited to OP_MOVE, +; OP_AND, OP_OR and OP_XOR. The VGA hardware is used to +; perform the selected logical functions on up to four +; pixel at a time. +; +subRepFill PROC NEAR + mov ah, al + shr cx, 1 + rep stosw + rcl cx, 1 + rep stosb + ret +subRepFill ENDP +; +subFill PROC NEAR +@@Loop: + mov ds:[bx], al + add bx, dx + loop @@Loop + ret +subFill ENDP +; +subRepMove PROC NEAR + mov si, di +@@Loop: + mov ah, ds:[si] ; Dummy read to latch the data + mov ds:[si], al + inc si + loop @@Loop + ret +subRepMove ENDP +; +subMove PROC NEAR +@@Loop: + mov ah, ds:[bx] ; Dummy read to latch the data + mov ds:[bx], al + add bx, dx + loop @@Loop + ret +subMove ENDP + +;----------------------------------------------------------- +; +; Fills a rectangle with a specified color. +; +; Input: +; X, Y = X, Y coordinates of rectangle +; Width = width of rectangle +; Height = height of rectangle +; Color = fill color +; Op = raster operator +; Output: +; none +; +; Note: raster op is limited to OP_MOVE, OP_AND, OP_OR and OP_XOR. +; +mxFillBox PROC FAR + ARG Op:WORD, \ + Color:BYTE:2, \ + Height:WORD, \ + Width:WORD, \ + Y:WORD, \ + X:WORD = ARG_SIZE + LOCAL LeftMask:BYTE, \ + RightMask:BYTE, \ + FillFunction:WORD, \ + RepFillFunction:WORD = AUTO_SIZE + .enter AUTO_SIZE + .push ds, si, es, di + ASSUME ds:NOTHING + +; Clip rectangle + mov bx, [X] + mov ax, [Y] + mov cx, [Width] + mov dx, [Height] + call subClipBox + jc @@Exit ; Full clipped + + mov [Height], dx ; Save clipped height + call subHorizontalLineInfo ; Get additional info, init DI + mov [Width], cx + mov [LeftMask], al + mov [RightMask], ah + +; Initialize segments + mov ax, [mx_VideoSegment] + mov es, ax ; ES:DI points to pixel + mov ds, ax + cld ; Clear direction flag + +; Select fill functions + mov [FillFunction], OFFSET subFill + mov [RepFillFunction], OFFSET subRepFill + mov ax, [Op] ; Get raster op + cmp al, OP_XOR + ja @@1 ; Assume it's a fill + cmp al, OP_MOVE + je @@1 + .shl al, 3 + mov ah, al + mov al, 03h + mov dx, GDC + out dx, ax ; Set GDC logical function + mov [FillFunction], OFFSET subMove + mov [RepFillFunction], OFFSET subRepMove +@@1: + +; Fill left block +@@L0: + mov ah, [LeftMask] + or ah, ah + jz @@C0 ; Nothing to do, go to center block + mov dx, TS + mov al, 02h + out dx, ax ; Set write plane mask + mov dx, [mx_BytesPerLine] + mov cx, [Height] + mov bx, di + mov al, [Color] + call [FillFunction] ; Fill this column + inc di ; Update starting video offset + +; Fill center block +@@C0: + mov cx, [Width] + jcxz @@R0 ; Nothing to do, go to right block + mov dx, TS + mov ax, 0F02h + out dx, ax ; Write to all planes + mov al, [Color] + mov bx, di + mov dx, [Height] + push di ; Save pixel address +@@C1: + mov di, bx ; Update video offset + call [RepFillFunction] ; Fill current scan line + mov cx, [Width] ; Restore byte count + add bx, [mx_BytesPerLine] ; Bump to next scan line + dec dx ; Done all lines? + jnz @@C1 ; No, continue + pop di ; Restore pixel address + add di, [Width] ; Go to right block + +; Fill right block +@@R0: + mov ah, [RightMask] + or ah, ah + jz @@Done ; Nothing to do, exit + mov dx, TS + mov al, 02h + out dx, ax ; Set write plane mask + mov dx, [mx_BytesPerLine] + mov cx, [Height] + mov bx, di + mov al, [Color] + call [FillFunction] ; Fill this column + +; Restore VGA registers +@@Done: + mov dx, GDC + mov ax, 0003h + out dx, ax ; Set logical function to "move" + +@@Exit: + xor ax, ax + .pop ds, si, es, di + .leave ARG_SIZE +mxFillBox ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxfp.asm b/16/x/mxfp.asm new file mode 100755 index 00000000..8eea25be --- /dev/null +++ b/16/x/mxfp.asm @@ -0,0 +1,326 @@ +;----------------------------------------------------------- +; +; MXFP.ASM - Fade palette function +; Copyright (c) 1992-1994 ARTIS s.r.l. +; Author: Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +INCLUDE MODEX.DEF + +PUBLIC mxFadePalette + +MAXCOLOR EQU 256 +FADE_IN EQU 0 +FADE_OUT EQU 1 + +; The actual speed of fading depends on the number of passes (FADE_SPEED) and +; the delay between two consecutive passes (FADE_DELAY). Below are the +; default values, used when no parameters are specified. +; +FADE_DELAY EQU 1 ; Vert. retraces between video updates +FADE_SPEED EQU 48 ; Speed of effect (max 127) + +; Bit field record for fade commands +; +FADE_COMMAND RECORD fpDELAY:8,fpSPEED:7,fpDIRECTION:1 + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +DB 'Copyright (c) 1992-1994 ARTIS s.r.l. All rights reserved.' + +;----------------------------------------------------------- +; +; Fades a VGA palette. +; +; Input: +; Buffer = pointer to source/destination palette +; Command = fading direction and optional parameters +; Start = index of first color to fade +; Count = number of color to fade +; Red = destination red +; Green = destination green +; Blue = destination blue +; Output: +; none +; Notes: +; - about 1.5 Kbytes of stack space are needed for internal buffers; +; - the Command argument usually is 0 to fade in and 1 to fade out, +; however additional parameters may be specified. To set the effect +; speed, i.e. the number of iterations needed to completely fade a +; palette, shift the value one bit left and "or" it with the +; direction bit (range is 0..127). To set the delay between two +; consecutive passes, shift it eight bits left (range is 0..255). +; +mxFadePalette PROC FAR + ARG bBlue:WORD, \ + bGreen:WORD, \ + bRed:WORD, \ + wCount:WORD, \ + wStartIdx:WORD, \ + wCommand:WORD, \ + vfpPalette:DWORD = ARG_SIZE + LOCAL bSPalette:BYTE:MAXCOLOR*3, \ + bDPalette:BYTE:MAXCOLOR*3, \ + bLoopIndex:BYTE, \ + bLoopStep:BYTE, \ + bLoopCount:BYTE, \ + wDelay:WORD, \ + wSpeed:WORD = AUTO_SIZE + ASSUME ds:NOTHING + .enter AUTO_SIZE + .push si, di, ds, es ; Save registers +; +; Check parameters and setup variables +; +@@GetDelay: + mov [wDelay], FADE_DELAY ; Set default delay + mov ax, [wCommand] ; Get command word + and ax, MASK fpDELAY ; Mask delay command + jz @@GetSpeed ; No command, get speed + IF USE286 EQ TRUE + shr ax, fpDELAY + ELSE + mov cl, fpDELAY ; Get size of delay field + shr ax, cl ; Right justify the field + ENDIF + mov [wDelay], ax ; Set new delay + +@@GetSpeed: + mov ax, [wCommand] ; Get command + and ax, MASK fpSPEED ; Mask speed + IF USE286 EQ TRUE + shr ax, fpSPEED + ELSE + mov cl, fpSPEED ; Get size of speed field + shr ax, cl ; Right justify the field + ENDIF + or ax, ax ; Any speed specified? + jnz @@SetVariables ; Yes, set variables + mov ax, FADE_SPEED ; Set default speed + +@@SetVariables: + mov [wSpeed], ax ; Set speed + inc ax ; Number of iterations + mov [bLoopCount], al ; Set loop count + mov [bLoopStep], 1 ; Assume we're fading in + mov [bLoopIndex], 0 +; +; Check bounds for bad values +; + mov ax, [wStartIdx] ; Get first index + cmp ax, MAXCOLOR ; Is in the valid range? + jae @@Exit ; No, exit + add ax, [wCount] ; Get last index + cmp ax, MAXCOLOR ; Is in the valid range? + jbe @@BoundsOk ; Yes, continue + mov ax, MAXCOLOR + sub ax, [wStartIdx] + mov [wCount], ax ; Set count to maximum value + or ax, ax + jz @@Exit ; Nothing to do, exit +@@BoundsOk: +; +; Copy the source palette in a local array: if we fade in it's ready to +; use, otherwise we'll overwrite it later +; + mov cx, [wCount] + mov ax, cx + shl ax, 1 + add cx, ax ; CX = wCount * 3 + mov ax, ss + mov es, ax + lea di, [bSPalette] ; ES:DI points to local palette + mov ax, [wStartIdx] + mov si, ax + shl ax, 1 + add ax, si + lds si, [vfpPalette] ; DS:SI points to user palette + add si, ax ; Skip unused entries + cld + shr cx, 1 + rep movsw + rcl cx, 1 + rep movsb +; +; Check direction +; + test [wCommand], MASK fpDIRECTION ; Are we fading in? + jz @@Main ; Yes, ok to continue + mov ax, [wSpeed] ; Get speed + mov [bLoopIndex], al ; Exchange first and last index + mov [bLoopStep], -1 ; Move backward + mov ax, ss ; Overwrite our copy of + mov ds, ax ; user palette with the + mov es, ax ; current active palette + lea di, [bSPalette] + mov ax, [wStartIdx] + mov cx, [wCount] + call ReadPalette ; Read current palette +; +; Prepare variables and registers for fading +; +@@Main: + mov bh, BYTE PTR [bRed] ; Destination red + and bh, 00111111b ; Be sure it's a valid VGA value + mov bl, BYTE PTR [bGreen] ; Destination green + and bl, 00111111b ; Be sure it's a valid VGA value + mov dh, BYTE PTR [bBlue] ; Destination blue + and dh, 00111111b ; Be sure it's a valid VGA value + mov dl, [bLoopIndex] ; Loop index + mov ax, ss ; All tables are stored + mov ds, ax ; in the stack segment, + mov es, ax ; set DS and ES +; +; Main loop +; +@@Loop: + mov ax, [wCount] ; Store count in AX + mov cx, [wSpeed] ; Set maximum speed in CX + lea si, [bSPalette] ; DS:SI points to source palette + lea di, [bDPalette] ; ES:DI points to dest. palette + call RecalcPalette ; Build a faded palette + + .push bx, dx ; Save registers we need + lea si, [bDPalette] ; DS:SI points to palette + mov ax, [wStartIdx] ; First index to write + mov bx, [wCount] ; Total entries to write + mov cx, [wDelay] ; Fade delay between updates + call WritePalette ; Write palette + .pop bx, dx ; Restore BX and DX + + add dl, [bLoopStep] ; Change fade intensity + dec [bLoopCount] ; Done? + jnz @@Loop ; No, loop again + +@@Exit: + .pop si, di, ds, es ; Restore registers + .leave ARG_SIZE +mxFadePalette ENDP + +;------- INTERNAL USE ONLY ------------------------------------------------ +; +; Calculates a partially faded palette. +; +; Input: +; AX = number of entries in palette +; CX = maximum fade intensity (same as fade speed) +; DS:SI = pointer to source palette +; ES:DI = pointer to destination palette +; BH = destination red +; BL = destination green +; DH = destination blue +; DL = relative intensity of destination palette +; Note: +; it's important that a new palette can be calculated in less +; than 1/70th of second. Fading to any RGB value requires use +; of "imul" instructions: "idiv" may be replaced with faster +; "sar", but only when the number of passes is a power of two, +; thus reducing the range of selectable speeds. +; In both cases an extimate of CPU cycles required by this +; procedure shows that it's too slow to run on a 4.77 Mhz 8086 +; CPU and a 256 color palette, so we keep "idiv" and hope +; the target machine to be at least a 6 Mhz 80286 (that's not +; asking too much...). +; +RecalcPalette PROC NEAR + cld + push bp ; Save BP + mov bp, ax ; Copy counter in BP +@@Loop: + lodsb ; Red: read value + sub al, bh ; Subtract destination value + imul dl ; Scale to desired weight + idiv cl ; Put value in AL + add al, bh ; Add destination value... + stosb ; ...and store it + lodsb ; Green: read value + sub al, bl ; Subtract destination value + imul dl ; Scale to desired weight + idiv cl ; Put value in AL + add al, bl ; Add destination value... + stosb ; ...and store it + lodsb ; Blue: read value + sub al, dh ; Subtract destination value + imul dl ; Scale to desired weight + idiv cl ; Put value in AL + add al, dh ; Add destination value... + stosb ; ...and store it + dec bp + jnz @@Loop + pop bp ; Restore BP + ret +RecalcPalette ENDP + +;------- INTERNAL USE ONLY ------------------------------------------------ +; +; Writes a 256 color palette. +; +; Input: +; AX = index of first color to write +; BX = number of colors to write (each color is an RGB triplet) +; CX = number of vertical retraces to wait before writing to DACs +; DS:SI = pointer to first entry of palette +; +WritePalette PROC NEAR + ASSUME ds:NOTHING + mov ah, al ; Save index + mov dx, 03DAh ; Input status register +@@Delay1: + in al, dx + test al, 08h + jnz @@Delay1 ; Wait for display mode +@@Delay2: + in al, dx + test al, 08h + jz @@Delay2 ; Wait for vertical retrace mode + loop @@Delay1 ; Repeat CX times +@@Write: + mov cx, bx ; Get number of colors + mov dx, 03C8h ; PEL write address register + mov al, ah ; Restore index + out dx, al ; Select index of first color + inc dx ; PEL data register + cld ; Move forward + cli ; Disable interrupts +@@Loop: + lodsb + out dx, al ; Red + lodsb + out dx, al ; Green + lodsb + out dx, al ; Blue + loop @@Loop ; Loop until done + sti ; Enable interrupts + ret +WritePalette ENDP + +;------- INTERNAL USE ONLY ------------------------------------------------ +; +; Reads the current palette. +; +; Input: +; AX = index of first color to read +; CX = number of colors +; ES:DI = pointer to destination buffer +; +ReadPalette PROC NEAR + mov dx, 03C7h + out dx, al + inc dx + inc dx + cld +@@Loop: + in al, dx + stosb + in al, dx + stosb + in al, dx + stosb + loop @@Loop + ret +ReadPalette ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxgc.asm b/16/x/mxgc.asm new file mode 100755 index 00000000..85edf7a6 --- /dev/null +++ b/16/x/mxgc.asm @@ -0,0 +1,54 @@ +;----------------------------------------------------------- +; +; MXGC.ASM - Get color function +; Copyright (c) 1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +INCLUDE MODEX.DEF + +PUBLIC mxGetColor + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +;----------------------------------------------------------- +; +; Returns the current setting of the selected DAC register. +; +; Input: +; Index = color index (0-255) +; R, G, B = byte pointers to red, green and blue +; Output: +; none +; +mxGetColor PROC FAR + ARG B:DWORD, \ + G:DWORD, \ + R:DWORD, \ + Index:WORD = ARG_SIZE + .enter 0 + .push ds, si + + mov ax, [Index] + mov dx, 3C7h ; PEL read address register + out dx, al + inc dx + inc dx + + lds si, [R] + in al, dx + mov ds:[si], al + lds si, [G] + in al, dx + mov ds:[si], al + lds si, [B] + in al, dx + mov ds:[si], al + + .pop ds, si + .leave ARG_SIZE +mxGetColor ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxgi.asm b/16/x/mxgi.asm new file mode 100755 index 00000000..7037d411 --- /dev/null +++ b/16/x/mxgi.asm @@ -0,0 +1,132 @@ +;----------------------------------------------------------- +; +; MXGI.ASM - Get image +; Copyright (c) 1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +NOWARN RES +INCLUDE MODEX.DEF + +PUBLIC mxGetImage + +EXTRN subClipImage : NEAR + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +EXTRN mx_VideoSegment : WORD +EXTRN mx_BytesPerLine : WORD + +;----------------------------------------------------------- +; +; Copies an image from screen to memory. +; +; Input: +; Image = pointer to buffer for image +; X, Y = coordinates of image on screen +; Width = width of image in pixels +; Height = height of image in pixels +; Output: +; none +; +mxGetImage PROC FAR + ARG Height:WORD, \ + Width:WORD, \ + Y:WORD, \ + X:WORD, \ + Image:DWORD = ARG_SIZE + LOCAL PlaneWidth:WORD:4, \ + PixelOffset:WORD, \ + MoveFunction:WORD, \ + ReadPlane:BYTE, \ + Count:BYTE = AUTO_SIZE + ASSUME ds:NOTHING + .enter AUTO_SIZE + .push ds, si, es, di + +; Clip image + mov bx, [X] + mov ax, [Y] + mov cx, [Width] + mov dx, [Height] + call subClipImage + jc @@Exit ; Full clipped + mov [Height], dx + add WORD PTR Image[0], si ; Skip clipped pixels + +; Get pixel address + mul [mx_BytesPerLine] + mov si, bx + shr si, 1 + shr si, 1 + add si, ax + mov [PixelOffset], si + mov ds, [mx_VideoSegment] ; DS:SI points to pixel + and bl, 03h + mov [ReadPlane], bl + +; Compute extra bytes and width count for each plane + mov bx, cx + shr bx, 1 + shr bx, 1 ; Width for each plane + and cl, 03h + mov al, 00001000b + shr al, cl + mov di, 3 SHL 1 +@@PatchLoop: + mov PlaneWidth[di], bx + shr al, 1 + adc bx, 0 + dec di + dec di + jge @@PatchLoop + +; Get image + cld + mov [Count], 4 ; Four planes + lea bx, PlaneWidth ; SS:[BX] = width in bytes for plane + mov es, WORD PTR Image[2] ; ES:DI will point to image + mov ah, [ReadPlane] +@@PlaneLoop: + cmp WORD PTR ss:[bx], 0 ; Exit if nothing more to do + je @@Exit ; (also, never try to move zero bytes!) + mov di, WORD PTR Image[0] + mov al, 04h + mov dx, GDC + out dx, ax ; Select read plane + mov dx, [Height] + mov si, [PixelOffset] ; DS:SI points to video memory +@@Loop: + .push si, di + mov cx, WORD PTR ss:[bx] ; Number of bytes to move +@@MoveLoop: + movsb + add di, 3 + dec cx + jnz @@MoveLoop + .pop si, di + add di, [Width] ; Go to next image line + add si, [mx_BytesPerLine] ; Go to next screen row + dec dx + jnz @@Loop ; Repeat for all lines + inc bx + inc bx ; Select width for next plane + inc ah + test ah, 04h ; Plane wraparound? + jz @@PlaneOk ; No + inc [PixelOffset] ; Yes, bump video pointer + and ah, 03h +@@PlaneOk: + inc WORD PTR Image[0] + dec [Count] + jnz @@PlaneLoop ; Repeat for all planes + +@@Exit: + xor ax, ax + .pop ds, si, es, di + .leave ARG_SIZE +mxGetImage ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxgm.asm b/16/x/mxgm.asm new file mode 100755 index 00000000..a67476a0 --- /dev/null +++ b/16/x/mxgm.asm @@ -0,0 +1,63 @@ +;----------------------------------------------------------- +; +; MXGM.ASM - Gamma correction +; Copyright (c) 1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +INCLUDE MODEX.DEF + +PUBLIC mxGammaCorrect + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +mx_tblGamma LABEL BYTE + DB 00, 10, 14, 17, 19, 21, 23, 24, 26, 27, 28, 29, 31, 32, 33, 34 + DB 35, 36, 37, 37, 38, 39, 40, 41, 41, 42, 43, 44, 44, 45, 46, 46 + DB 47, 48, 48, 49, 49, 50, 51, 51, 52, 52, 53, 53, 54, 54, 55, 55 + DB 56, 56, 57, 57, 58, 58, 59, 59, 60, 60, 61, 61, 62, 62, 63, 63 + +;----------------------------------------------------------- +; +; Correct palette colors (gamma is 2.3). +; +; Input: +; CPal = pointer to color palette +; GPal = pointer to destination (gamma corrected) palette +; Count = number of colors to convert +; Output: +; none +; +; Note: CPal and GPal may point to the same buffer. +; +mxGammaCorrect PROC FAR + ARG Count:WORD, \ + DPal:DWORD, \ + SPal:DWORD = ARG_SIZE + ASSUME ds:NOTHING + .enter 0 + .push ds, si, es, di + + mov cx, [Count] + jcxz @@Exit ; Exit now if nothing to do + lds si, [SPal] + les di, [DPal] + mov bx, OFFSET mx_tblGamma ; Setup BX for XLAT instruction + cld + mov ax, cx ; AX = Count + add cx, cx ; CX = Count*2 + add cx, ax ; CX = Count*3 +@@Loop: + lodsb + xlat mx_tblGamma + stosb + loop @@Loop + +@@Exit: + .pop ds, si, es, di + .leave ARG_SIZE +mxGammaCorrect ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxgp.asm b/16/x/mxgp.asm new file mode 100755 index 00000000..6c143173 --- /dev/null +++ b/16/x/mxgp.asm @@ -0,0 +1,56 @@ +;----------------------------------------------------------- +; +; MXGP.ASM - Get palette function +; Copyright (c) 1993,1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +INCLUDE MODEX.DEF + +PUBLIC mxGetPalette + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +;----------------------------------------------------------- +; +; Returns the current setting of the VGA palette. +; +; Input: +; Buffer = pointer to palette data (R,G,B) +; Start = index of first color to get +; Count = number of color to get +; Output: +; none +; +mxGetPalette PROC FAR + ARG Count:WORD, \ + Start:WORD, \ + Buffer:DWORD = ARG_SIZE + ASSUME ds:NOTHING + .enter 0 + .push es, di + + les di, [Buffer] + mov cx, [Count] + mov ax, [Start] + mov dx, 3C7h ; PEL read address register + out dx, al + inc dx + inc dx + cld +@@Loop: + in al, dx + stosb + in al, dx + stosb + in al, dx + stosb + loop @@Loop ; Loop until done + + .pop es, di + .leave ARG_SIZE +mxGetPalette ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxgv.asm b/16/x/mxgv.asm new file mode 100755 index 00000000..2a54b1d0 --- /dev/null +++ b/16/x/mxgv.asm @@ -0,0 +1,25 @@ +;----------------------------------------------------------- +; +; MXGV.ASM - Get version function +; Copyright (c) 1993,1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +INCLUDE MODEX.DEF + +PUBLIC mxGetVersion + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +;----------------------------------------------------------- +; +; Returns the library version. +; +mxGetVersion PROC FAR + mov ax, MXVERSION + ret +mxGetVersion ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxhl.asm b/16/x/mxhl.asm new file mode 100755 index 00000000..049a0566 --- /dev/null +++ b/16/x/mxhl.asm @@ -0,0 +1,76 @@ +;----------------------------------------------------------- +; +; MXHL.ASM - Horizontal line mask utility +; Copyright (c) 1993,1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +INCLUDE MODEX.DEF + +PUBLIC subHorizontalLineInfo + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +EXTRN mx_BytesPerLine : WORD + +tblLeftSize DW 00h, 03h, 02h, 01h +tblLeftMask DB 00h, 0Eh, 0Ch, 08h +tblRightMask DB 00h, 01h, 03h, 07h +tblPatchMask DB 02h, 06h + +;----------------------------------------------------------- +; +; Prepares register for fast horizontal line drawing. +; +; Input: +; BX, AX = X, Y address of left pixel +; CX = line width +; Output: +; DI = left pixel offset in video memory +; AL = left block write plane mask (0 = none) +; AH = right block write plane mask (0 = none) +; CX = center block width in 4-pixel blocks +; +subHorizontalLineInfo PROC NEAR + ASSUME ds:NOTHING + + mul [mx_BytesPerLine] + mov di, bx + shr di, 1 + shr di, 1 + add di, ax ; Offset of left pixel + + and bx, 03h + mov al, tblLeftMask[bx] + shl bx, 1 + sub cx, tblLeftSize[bx] + jge @@1 ; Ok to continue + +; Special case: start and end in the middle of a 4-pixel block. +; There are only three cases: +; Pixels Left mask CX CX+2 Patch mask Result +; 1) ..o. ..xx -1 1 .xx. ..x. +; 2) .oo. .xxx -1 1 .xx. .xx. +; 3) .o.. .xxx -2 0 .x.. .x.. +; All other cases are automatically handled with the standard masks. + mov bx, cx + inc bx + inc bx + and al, tblPatchMask[bx] ; Combine masks + xor ah, ah ; No right block + xor cx, cx ; No center block + jmp @@Exit + +@@1: + mov bx, cx + and bx, 03h + mov ah, tblRightMask[bx] + shr cx, 2 + +@@Exit: + ret +subHorizontalLineInfo ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxit.asm b/16/x/mxit.asm new file mode 100755 index 00000000..c0d9cedd --- /dev/null +++ b/16/x/mxit.asm @@ -0,0 +1,98 @@ +;----------------------------------------------------------- +; +; MXIT.ASM - Initialization/termination functions +; Copyright (c) 1993,1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +INCLUDE MODEX.DEF + +PUBLIC mxInit +PUBLIC mxTerm + +PUBLIC mx_VideoSegment +PUBLIC mx_CodeSegment + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +DB 'MODEX library - Copyright (c) 1992-1994 Alessandro Scotti' + +mx_VideoSegment DW 0A000h +mx_CodeSegment DW SEG MX_TEXT + +;----------------------------------------------------------- +; +; Initialization. +; +; Input: +; none +; Output: +; AX = 0 on success +; +mxInit PROC FAR + LOCAL Result:WORD, \ + VideoSeg:WORD, \ + CStoDSalias:WORD = AUTO_SIZE + ASSUME ds:NOTHING + .enter AUTO_SIZE + .push ds, si, es, di + + mov [Result], -1 ; Assume an error + mov [VideoSeg], 0A000h ; Real mode video segment + mov [CStoDSalias], cs ; Real mode data alias for CS + +; Check if running in protected mode under DPMI + mov ax, 1686h + int 2Fh + or ax, ax + jnz @@1 ; DPMI not found, continue in real mode + +; Get a data alias for CS + mov ax, 000Ah ; DMPI: create data alias + mov bx, cs + int 31h + jc @@Exit ; Exit if service failed + mov [CStoDSalias], ax ; Save data alias for CS +; Get a protected-mode selector for the video segment + mov ax, 0002h + mov bx, 0A000h ; Real mode segment of video + int 31h ; DPMI: get segment selector + jc @@Exit ; Exit if service failed + mov [VideoSeg], ax ; Save protected mode video selector + +; Initialize variables +@@1: + mov ds, [CStoDSalias] + ASSUME ds:MX_TEXT + mov [mx_CodeSegment], ds + mov ax, [VideoSeg] + mov [mx_VideoSegment], ax + +; Don't bother with VGA check for now... + + mov [Result], 0 + +@@Exit: + mov ax, [Result] + .pop ds, si, es, di + .leave +mxInit ENDP + +;----------------------------------------------------------- +; +; Termination. +; +; Input: +; none +; Output: +; always 0. +; +mxTerm PROC FAR + ASSUME ds:NOTHING + xor ax, ax + ret +mxTerm ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxll.asm b/16/x/mxll.asm new file mode 100755 index 00000000..34fec043 --- /dev/null +++ b/16/x/mxll.asm @@ -0,0 +1,82 @@ +;----------------------------------------------------------- +; +; MXLL.ASM - Load latches +; Copyright (c) 1993,1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +INCLUDE MODEX.DEF + +PUBLIC mxLoadLatches + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +EXTRN mx_VideoSegment : WORD + +;----------------------------------------------------------- +; +; Loads the specified value into the VGA latches. +; +; Input: +; BL = value to load into latches +; Output: +; none +; Changes: +; bit mask register to FFh; +; function select register to "move"; +; write mode to 00h. +; Note: +; this is for internal use only. +; +mxLoadLatches PROC NEAR + ASSUME ds:NOTHING + + .push ds, si + mov dx, GDC + mov ax, 0FF08h + out dx, ax ; Set bit mask to FFh + mov ax, 0003h + out dx, ax ; Set function to "move" + mov ax, 0005h + out dx, ax ; Set write mode + mov ax, [mx_VideoSegment] + mov ds, ax + mov si, 0FFFFh + mov bh, 8 ; BH = write plane mask + mov cx, 3 ; CX = count = read plane +; Saves old values and force BL into latches +@@SetLoop: + mov dx, GDC + mov al, 04h + mov ah, cl + out dx, ax ; Select read plane + mov dx, TS + mov al, 02h + mov ah, bh + out dx, ax ; Select write plane + mov al, ds:[si] + push ax + mov ds:[si], bl + mov al, ds:[di] ; Force value into latch + shr bh, 1 ; Next write plane + loop @@SetLoop +; Restore previous values + mov cx, 3 + mov bh, 8 + mov dx, TS +@@ResetLoop: + mov al, 02h + mov ah, bh + out dx, ax ; Select write plane + pop ax + mov ds:[si], al + shr bh, 1 ; Next write plane + loop @@ResetLoop +; Exit + .pop ds, si + ret +mxLoadLatches ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxln.asm b/16/x/mxln.asm new file mode 100755 index 00000000..fbc4ab94 --- /dev/null +++ b/16/x/mxln.asm @@ -0,0 +1,414 @@ +;----------------------------------------------------------- +; +; MXLN.ASM - Line function +; Copyright (c) 1993,1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +NOWARN RES +INCLUDE MODEX.DEF + +PUBLIC mxLine + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +EXTRN mx_BytesPerLine : WORD +EXTRN mx_VideoSegment : WORD + +EXTRN mx_ClipX1 : WORD +EXTRN mx_ClipY1 : WORD +EXTRN mx_ClipX2 : WORD +EXTRN mx_ClipY2 : WORD + +tblDrawFunc LABEL WORD + DW subWidthMove + DW subHeightMove + DW subWidthOp + DW subHeightOp + +;----------------------------------------------------------- +; +; Draws a line from (X1,Y1) to (X2,Y2) using the Bresenham +; algorithm. +; +; Input: +; X1, Y1 = start point +; X2, Y2 = end point +; Color = line color +; Op = raster operator +; Output: +; none +; +; Note: the end point (X2,Y2) *IS* drawed. I don't like this very much +; but clipping is much simpler. +; +mxLine PROC FAR + ARG Op:WORD, \ + Color:WORD, \ + Y2:WORD, \ + X2:WORD, \ + Y1:WORD, \ + X1:WORD = ARG_SIZE + LOCAL Width:WORD, \ + Height:WORD, \ + ErrorAdd:WORD, \ + ErrorSub:WORD, \ + DeltaX:WORD, \ + DeltaY:WORD, \ + P1:BYTE, \ + P2:BYTE, \ + WritePlane:BYTE = AUTO_SIZE + .enter AUTO_SIZE + .push ds, si, di + ASSUME ds:NOTHING + + mov ax, [X1] + mov bx, [Y1] + mov cx, [X2] + mov dx, [Y2] + call subClipLine + jc @@Exit ; Line is full clipped + +; Get width + mov si, cx + xchg ax, si ; SI = X1, AX = X2 + sub ax, si + jge @@1 +; Swap points, we want X1 < X2 + xchg si, cx ; Swap X1 and X2 + xchg bx, dx ; Swap Y1 and Y2 + neg ax +@@1: + mov [Width], ax + +; Get height + mov cx, [mx_BytesPerLine] ; We don't need X2 anymore + mov ax, dx + sub ax, bx + jge @@2 + neg cx ; Move from bottom to top + neg ax ; Get absolute value of AX +@@2: + mov [Height], ax + mov [DeltaY], cx + +; Get pixel address and write plane + mov ax, bx + mul [mx_BytesPerLine] + mov cx, si ; CX = X1 + shr si, 1 + shr si, 1 + add si, ax ; SI = pixel offset + and cl, 03h + mov ax, 1102h + shl ah, cl + mov [WritePlane], ah + mov dx, TS + out dx, ax ; Set write plane + mov ax, [mx_VideoSegment] + mov ds, ax ; DS:SI points to (X1,Y1) + +; Select the function to handle the drawing loop + xor bx, bx + mov al, BYTE PTR [Op] + cmp al, OP_MOVE + je @@3 + and al, 03h + shl al, 1 + shl al, 1 + shl al, 1 + mov ah, al + mov al, 03h + mov dx, GDC + out dx, ax ; Set logical function + inc bx + inc bx +@@3: + mov ax, [Width] + mov cx, [Height] +; Horizontal, vertical and diagonal lines are not optimized yet + cmp ax, cx + jae @@4 + inc bx +@@4: + shl bx, 1 + call tblDrawFunc[bx] + +; Reset logical function if needed + cmp BYTE PTR [Op], OP_MOVE + je @@Exit + mov ax, 0003h + mov dx, GDC + out dx, ax + +@@Exit: + xor ax, ax + .pop ds, si, di + .leave ARG_SIZE + +;----------------------------------------------------------- +; +; Checks the coordinates of a line against the active +; clip region. +; Uses a variation of the Cohen-Sutherland algorithm developed +; by Victor Duvanenko. +; +; Input: +; AX, BX = X1, Y1 +; CX, DX = X2, Y2 +; Output: +; CF = set if line is full clipped +; AX, BX = clipped X1, Y1 +; CX, DX = clipped X2, Y2 +; Note: +; destroys SI, DI +; +subClipLine PROC NEAR + mov di, ax ; Copy X1 to DI and free AX + mov si, dx ; Copy Y2 to SI and free DX +; Compute clip codes for point (X2,Y2)=(CX,SI) + xor al, al +@@P2X1: cmp cx, [mx_ClipX1] + jge @@P2X2 + or al, 1 +@@P2X2: cmp cx, [mx_ClipX2] + jle @@P2Y1 + or al, 2 +@@P2Y1: cmp si, [mx_ClipY1] + jge @@P2Y2 + or al, 4 +@@P2Y2: cmp si, [mx_ClipY2] + jle @@P2XY + or al, 8 +@@P2XY: mov [P2], al +; Compute clip codes for point (X1,Y1)=(DI,BX) + xor al, al +@@P1X1: cmp di, [mx_ClipX1] + jge @@P1X2 + or al, 1 +@@P1X2: cmp di, [mx_ClipX2] + jle @@P1Y1 + or al, 2 +@@P1Y1: cmp bx, [mx_ClipY1] + jge @@P1Y2 + or al, 4 +@@P1Y2: cmp bx, [mx_ClipY2] + jle @@P1XY + or al, 8 +@@P1XY: mov [P1], al +; Check codes for trivial cases + mov ah, [P2] + test al, ah ; Is line invisible? + jnz @@FullClip ; Yes, exit + or ah, al ; Both points clipped? + jz @@Done ; Yes, exit +; Calculate deltas + mov ax, cx + sub ax, di + mov [DeltaX], ax + mov ax, si + sub ax, bx + mov [DeltaY], ax + mov al, [P1] ; Init clipping code +; Clipping loop +@@ClipLoop: + test al, al ; Is first point clipped? + jnz @@ClipX1 ; No, continue + xchg cx, di ; Swap points... + xchg bx, si + xchg al, [P2] ; ...and codes +; Clip left: Y1 = Y1 + DeltaY*(mx_ClipX1-X1)/DeltaX +@@ClipX1: + test al, 1 + jz @@ClipX2 + mov ax, [mx_ClipX1] + sub ax, di + mov di, [mx_ClipX1] + jmp @@ClipX1X2 +; Clip right: Y1 = Y1 + DeltaY*(mx_ClipX2-X1)/DeltaX +@@ClipX2: + test al, 2 + jz @@ClipY1 + mov ax, [mx_ClipX2] + sub ax, di + mov di, [mx_ClipX2] +@@ClipX1X2: + imul [DeltaY] + idiv [DeltaX] + add bx, ax + mov al, 8 + cmp bx, [mx_ClipY2] + jg @@CheckLoop + mov al, 4 + cmp bx, [mx_ClipY1] + jl @@CheckLoop + xor al, al + jmp @@CheckLoop +; Clip top: X1 = X1 + DeltaX*(mx_ClipY1-Y1)/DeltaY +@@ClipY1: + test al, 4 + jz @@ClipY2 + mov ax, [mx_ClipY1] + sub ax, bx + mov bx, [mx_ClipY1] + jmp @@ClipY1Y2 +; Clip bottom: X1 = X1 + DeltaX*(mx_ClipY2-Y1)/DeltaY +@@ClipY2: + mov ax, [mx_ClipY2] + sub ax, bx + mov bx, [mx_ClipY2] +@@ClipY1Y2: + imul [DeltaX] + idiv [DeltaY] + add di, ax + mov al, 1 + cmp di, [mx_ClipX1] + jl @@CheckLoop + mov al, 2 + cmp di, [mx_ClipX2] + jg @@CheckLoop + xor al, al +@@CheckLoop: + mov ah, [P2] + test al, ah + jnz @@FullClip + or ah, al + jnz @@ClipLoop + +@@Done: + mov ax, di + mov dx, si + clc + ret +@@FullClip: + stc + ret +subClipLine ENDP + +; Called when Width >= Height and Op = OP_MOVE +subWidthMove PROC NEAR + mov di, ax + neg di ; Initialize error term + shl cx, 1 + mov [ErrorAdd], cx + mov cx, ax + shl ax, 1 + mov [ErrorSub], ax + mov al, 02h + mov ah, [WritePlane] + mov bl, BYTE PTR [Color] + mov dx, TS + inc cx +@@Loop: + mov ds:[si], bl + dec cx + jz @@Exit + rol ah, 1 + adc si, 0 + out dx, ax + add di, [ErrorAdd] + jl @@Loop + add si, [DeltaY] + sub di, [ErrorSub] + jmp @@Loop +@@Exit: + ret +subWidthMove ENDP + +; Called when Width < Height and Op = OP_MOVE +subHeightMove PROC NEAR + mov di, cx + neg di ; Initialize error term + shl ax, 1 + mov [ErrorAdd], ax + mov ax, cx + shl ax, 1 + mov [ErrorSub], ax + mov bl, BYTE PTR [Color] + mov ah, [WritePlane] + mov al, 02h + mov dx, TS + inc cx +@@Loop: + mov ds:[si], bl + dec cx + jz @@Exit + add si, [DeltaY] + add di, [ErrorAdd] + jl @@Loop + rol ah, 1 ; Next write plane + adc si, 0 ; Bump video offset if plane overflows + out dx, ax + sub di, [ErrorSub] ; Adjust error down + jmp @@Loop +@@Exit: + ret +subHeightMove ENDP + +; Called when Width >= Height and Op <> OP_MOVE +subWidthOp PROC NEAR + mov di, ax + neg di ; Initialize error term + shl cx, 1 + mov [ErrorAdd], cx + mov cx, ax + shl ax, 1 + mov [ErrorSub], ax + mov al, 02h + mov ah, [WritePlane] + mov bl, BYTE PTR [Color] + mov dx, TS + inc cx +@@Loop: + mov bh, ds:[si] ; Latch data + mov ds:[si], bl + dec cx + jz @@Exit + rol ah, 1 + adc si, 0 + out dx, ax + add di, [ErrorAdd] + jl @@Loop + add si, [DeltaY] + sub di, [ErrorSub] + jmp @@Loop +@@Exit: + ret +subWidthOp ENDP + +; Called when Width < Height and Op <> OP_MOVE +subHeightOp PROC NEAR + mov di, cx + neg di ; Initialize error term + shl ax, 1 + mov [ErrorAdd], ax + mov ax, cx + shl ax, 1 + mov [ErrorSub], ax + mov bl, BYTE PTR [Color] + mov ah, [WritePlane] + mov al, 02h + mov dx, TS + inc cx +@@Loop: + mov bh, ds:[si] + mov ds:[si], bl + dec cx + jz @@Exit + add si, [DeltaY] + add di, [ErrorAdd] + jl @@Loop + rol ah, 1 ; Next write plane + adc si, 0 ; Bump video offset if plane overflows + out dx, ax + sub di, [ErrorSub] ; Adjust error down + jmp @@Loop +@@Exit: + ret +subHeightOp ENDP + +mxLine ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxot.asm b/16/x/mxot.asm new file mode 100755 index 00000000..62547665 --- /dev/null +++ b/16/x/mxot.asm @@ -0,0 +1,330 @@ +;----------------------------------------------------------- +; +; MXOT.ASM - Text functions +; Copyright (c) 1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +NOWARN RES ; We use the reserved name 'WIDTH' +INCLUDE MODEX.DEF + +PUBLIC mxOutChar +PUBLIC mxOutText +PUBLIC mxSetFont +PUBLIC mxSetTextColor +PUBLIC mxGetTextStep +PUBLIC mxSetTextStep + +MAX_WIDTH EQU 16 ; Must be <= 16 +MAX_HEIGHT EQU 32 + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +EXTRN mx_CodeSegment : WORD +EXTRN mxPutImage : FAR + +; Default 8x8 font +fnt_Default LABEL + INCLUDE DEFAULT.FNT + +; Table of system fonts +tbl_SystemFont LABEL WORD + DW fnt_Default, 8, 8 + +MX_MAXSYSFONT EQU ($-OFFSET tbl_SystemFont) SHR 2 + +mx_FontPtr DW OFFSET fnt_Default, SEG MX_TEXT +mx_FontWidth DW 8 ; Font width in pixels +mx_FontHeight DW 8 ; Font height in pixels +mx_FontCharSize DW 8 ; Size in bytes of a font character +mx_FontColor DW 00FFh ; Color: foreground + background*256 +mx_FontOp DW OP_MOVE ; Raster op +mx_DeltaX DW 8 ; Horizontal step +mx_DeltaY DW 0 ; Vertical step + +;----------------------------------------------------------- +; +; Sets the current font. +; +; Input: +; Font = pointer to font data +; Width = width of font character in pixels +; Height = height of font character in pixels +; Output: +; AX = 0 on success, else invalid parameters +; +; Note: when the high word of Font (i.e. the segment) is zero, the low +; word is used to select one of the system fonts. +; +mxSetFont PROC FAR + ARG Height:WORD, \ + Width:WORD, \ + Font:DWORD = ARG_SIZE + .enter 0 + .push ds + + mov ds, [mx_CodeSegment] + ASSUME ds:MX_TEXT + + mov ax, WORD PTR Font[2] ; Get font segment + test ax, ax ; Null segment? + jnz @@UserFont ; No, install user font + +; Install system font + mov ax, WORD PTR Font[0] ; Get font number + cmp ax, MX_MAXSYSFONT ; Check range + jb @@SystemFont + xor ax, ax ; Out of range, use default font +@@SystemFont: + shl ax, 1 + shl ax, 1 + mov bx, ax + mov ax, tbl_SystemFont[bx] ; Get font offset + mov WORD PTR mx_FontPtr[0], ax + mov WORD PTR mx_FontPtr[2], cs + mov al, BYTE PTR tbl_SystemFont[bx+2] + xor ah, ah + mov [mx_FontWidth], ax + mov [mx_DeltaX], ax + mov dl, BYTE PTR tbl_SystemFont[bx+3] + xor dh, dh + mov [mx_FontHeight], dx + mul dx + mov [mx_FontCharSize], ax + mov [mx_DeltaX], ax + xor ax, ax + mov [mx_DeltaY], ax + jmp @@Exit + +; Install user font +@@UserFont: + mov ax, -1 ; Assume an error + mov bx, [Width] + cmp bx, MAX_WIDTH + ja @@Exit ; Invalid character width + mov dx, [Height] + cmp dx, MAX_HEIGHT + ja @@Exit ; Invalid character height + mov [mx_FontWidth], bx + mov [mx_FontHeight], dx + mov ax, bx + add ax, 7 + .shr ax, 3 + mul dx + mov [mx_FontCharSize], ax + mov ax, WORD PTR Font[0] + mov WORD PTR mx_FontPtr[0], ax + mov ax, WORD PTR Font[2] + mov WORD PTR mx_FontPtr[2], ax + xor ax, ax + +@@Exit: + .pop ds + ASSUME ds:NOTHING + .leave ARG_SIZE +mxSetFont ENDP + +;----------------------------------------------------------- +; +; Sets the text color and raster op. +; +; Input: +; Color = text color (foreground + background*256) +; Op = raster op +; Output: +; none +; +mxSetTextColor PROC FAR + ARG Op:WORD, \ + Color:WORD = ARG_SIZE + .enter 0 + .push ds + + mov ds, [mx_CodeSegment] + ASSUME ds:MX_TEXT + + mov ax, [Color] + mov [mx_FontColor], ax + mov ax, [Op] + mov [mx_FontOp], ax + + xor ax, ax + .pop ds + ASSUME ds:NOTHING + .leave ARG_SIZE +mxSetTextColor ENDP + +;----------------------------------------------------------- +; +; Writes a character using the current font and attributes. +; +; Input: +; X, Y = video coordinates +; C = character to print +; Output: +; none +; +mxOutChar PROC FAR + ARG C:BYTE:2, \ + Y:WORD, \ + X:WORD = ARG_SIZE + LOCAL Image:BYTE:MAX_WIDTH*MAX_HEIGHT, \ + Count:WORD = AUTO_SIZE + .enter AUTO_SIZE + .push ds, si, es, di + ASSUME ds:NOTHING + +; Gets the pointer to font data for the selected character + lds si, DWORD PTR [mx_FontPtr] + mov al, [C] + xor ah, ah + mul [mx_FontCharSize] ; Offset into font + add si, ax ; DS:SI -> font data for character + +; Converts font data into a 256-color linear image + mov ax, ss + mov es, ax + lea di, [Image] + mov dx, [mx_FontColor] + mov ax, [mx_FontHeight] + mov [Count], ax +@@HeightLoop: + mov cx, [mx_FontWidth] + mov bh, ds:[si] + inc si ; Get a byte from font data + cmp cx, 8 + jbe @@WidthLoop ; Ok for width <= 8 + mov bl, ds:[si] ; Get another byte + inc si +@@WidthLoop: + mov al, dl ; Assume foreground color + shl bx, 1 ; Is font bit set? + jc @@1 ; Yes, foreground is just great + mov al, dh ; Get background color +@@1: + mov es:[di], al ; Put pixel into image + inc di + dec cx + jnz @@WidthLoop + dec [Count] + jnz @@HeightLoop + +; Now pass image to mx_PutImage + lea ax, [Image] + push es + push ax ; Pointer to image + push [X] + push [Y] ; Image coordinates + push [mx_FontWidth] + push [mx_FontHeight] ; Image size + push [mx_FontOp] ; Raster op + call mxPutImage ; Write character + + xor ax, ax + .pop ds, si, es, di + .leave ARG_SIZE +mxOutChar ENDP + +;----------------------------------------------------------- +; +; Writes a string at the coordinates specified. +; +; Input: +; X, Y = text coordinates +; S = pointer to ASCIIZ string +; Output: +; none +; +mxOutText PROC FAR + ARG S:DWORD, \ + Y:WORD, \ + X:WORD = ARG_SIZE + .enter 0 + .push ds, si + ASSUME ds:NOTHING + + lds si, [S] +@@Loop: + mov al, ds:[si] + test al, al ; End of string? + jz @@Exit ; Yes, exit + inc si + push [X] ; Display character + push [Y] + push ax + call mxOutChar + mov ax, [mx_DeltaX] + add [X], ax ; Bump X coordinate + mov ax, [mx_DeltaY] + add [Y], ax ; Bump Y coordinate + dec [Count] + jnz @@Loop + +@@Exit: + xor ax, ax + .pop ds, si + .leave ARG_SIZE + ret +mxOutText ENDP + +;----------------------------------------------------------- +; +; Sets the distance between characters. +; +; Input: +; DeltaX = horizontal distance in pixels +; DeltaY = vertical distance in pixels +; Output: +; none +; +; Note: this function may be used to set the text direction. +; +mxSetTextStep PROC FAR + ARG DeltaY:WORD, \ + DeltaX:WORD = ARG_SIZE + .enter 0 + .push ds + + mov ds, [mx_CodeSegment] + ASSUME ds:MX_TEXT + + mov ax, [DeltaX] + mov [mx_DeltaX], ax + mov ax, [DeltaY] + mov [mx_DeltaY], ax + + .pop ds + .leave ARG_SIZE +mxSetTextStep ENDP + +;----------------------------------------------------------- +; +; Gets the current distance between characters. +; +; Input: +; DeltaX = pointer to horizontal distance in pixels (integer) +; DeltaY = pointer to vertical distance in pixels (integer) +; Output: +; none +; +mxGetTextStep PROC FAR + ARG DeltaY:DWORD, \ + DeltaX:DWORD = ARG_SIZE + .enter 0 + .push ds, si + ASSUME ds:NOTHING + + mov ax, [mx_DeltaX] + lds si, [DeltaX] + mov ds:[si], ax + mov ax, [mx_DeltaY] + lds si, [DeltaY] + mov ds:[si], ax + + .pop ds, si + .leave ARG_SIZE +mxGetTextStep ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxpb.asm b/16/x/mxpb.asm new file mode 100755 index 00000000..8c6aa449 --- /dev/null +++ b/16/x/mxpb.asm @@ -0,0 +1,22 @@ +;----------------------------------------------------------- +; +; MXPB.ASM - Scan buffer for convex polygon fills +; Copyright (c) 1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +NOWARN RES +INCLUDE MODEX.DEF + +PUBLIC mx_ScanBuffer + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +ALIGN 4 + +mx_ScanBuffer LABEL + DW POLYSCANBUFSIZE DUP(?) + +MX_TEXT ENDS +END diff --git a/16/x/mxpf.asm b/16/x/mxpf.asm new file mode 100755 index 00000000..db0da898 --- /dev/null +++ b/16/x/mxpf.asm @@ -0,0 +1,420 @@ +;----------------------------------------------------------- +; +; MXPG.ASM - Convex polygon fill +; Copyright (c) 1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +NOWARN RES +INCLUDE MODEX.DEF + +PUBLIC mxFillPoly + +;----------------------------------------------------------- +; +; "Local" definitions +; +TPOINT STRUC + X DW ? + Y DW ? +TPOINT ENDS + +; Do NOT change order! +TSCAN STRUC + Y1 DW ? + Y2 DW ? +TSCAN ENDS + +MAXSCANCOLUMNS EQU POLYSCANBUFSIZE / SIZE TSCAN + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +EXTRN mx_VideoSegment : WORD +EXTRN mx_CodeSegment : WORD +EXTRN mx_BytesPerLine : WORD +EXTRN mx_ClipX1 : WORD +EXTRN mx_ClipY1 : WORD +EXTRN mx_ClipX2 : WORD +EXTRN mx_ClipY2 : WORD +EXTRN mx_ScanBuffer : NEAR + +;----------------------------------------------------------- +; +; Scans an edge using the DDA (digital differential analyzer) algorithm. +; +; Input: +; DS:BX = pointer to start point (X1, Y1) +; DS:SI = pointer to end point (X2, Y2) +; ES:DI = pointer to edge buffer +; Output: +; ES:DI = updated pointer to edge buffer +; Notes: +; must preserve DS:SI. +; +subScan PROC NEAR + mov cx, ds:[si].X + sub cx, ds:[bx].X ; Get width + jg @@1 + ret +@@1: + push bp ; Save BP + + mov ax, ds:[si].Y + mov bx, ds:[bx].Y + sub ax, bx ; Get height + jg @@T2B ; Scan top to bottom + jl @@B2T ; Scan bottom to top + +; Special case: vertical line + mov ax, bx +@@V: + mov es:[di].Y1, ax + add di, SIZE TSCAN + dec cx + jnz @@V + jmp @@Exit + +; Scan top to bottom +@@T2B: + cwd + div cx + mov bp, ax + xor ax, ax + div cx + xchg ax, bx ; BP:BX = fixed 16:16 step + mov dx, 8000h +@@T2BLoop: + mov es:[di].Y1, ax + add di, SIZE TSCAN + add dx, bx + adc ax, bp + dec cx + jnz @@T2BLoop + jmp @@Exit + +; Scan bottom to top +@@B2T: + neg ax + cwd + div cx + mov bp, ax + xor ax, ax + div cx + xchg ax, bx + mov dx, 8000h +@@B2TLoop: + mov es:[di].Y1, ax + add di, SIZE TSCAN + sub dx, bx + sbb ax, bp + dec cx + jnz @@B2TLoop + +@@Exit: + pop bp ; Restore BP + ret +subScan ENDP + +;----------------------------------------------------------- +; +; Fills a convex polygon with the specified color. +; +; Input: +; Count = number of vertexes +; Map = indexes of points and colors (integer) +; Points = array of points (integer X, Y coordinates) +; Color = base color +; Output: +; none +; Notes: +; vertexes must be in counterclockwise order, arrays are 0-based. +; +mxFillPoly PROC FAR + ARG Color:WORD, \ + Points:DWORD, \ + Map:DWORD, \ + Count:WORD = ARG_SIZE + LOCAL WritePlane:BYTE:2, \ + ScanOffsetT:WORD, \ + ScanOffsetB:WORD, \ + ScanCount:WORD, \ + Holder:WORD, \ + Height:WORD, \ + MinIdxT:WORD, \ + MinIdxB:WORD, \ + MaxIdx:WORD, \ + Width:WORD, \ + BoxX1:WORD, \ + BoxY1:WORD, \ + BoxX2:WORD, \ + BoxY2::WORD = AUTO_SIZE + .enter AUTO_SIZE + .push ds, si, es, di + ASSUME ds:NOTHING + +; Check that at least three vertexes are specified + mov cx, [Count] + cmp cx, 3 + jb @@Exit + +;------------------------------ +; Find bounding box for polygon + les di, [Map] + lds si, [Points] ; Pointer to vertex array + mov [BoxX1], 32767 + mov [BoxX2], -32768 + mov [BoxY1], 32767 + mov [BoxY2], -32768 + + xor dx, dx +@@MinMaxLoop: + mov bx, es:[di] ; Get index of vertex + .shl bx, 2 ; Get offset in point array + add bx, si + +; Check X range +@@CheckMinX: + mov ax, ds:[bx].X ; Get X coordinate + cmp ax, [BoxX1] + jge @@CheckMaxX + mov [BoxX1], ax + mov [MinIdxT], dx + mov [MinIdxB], dx +@@CheckMaxX: + cmp ax, [BoxX2] + jle @@CheckMinY + mov [BoxX2], ax + mov [MaxIdx], dx + +; Check Y range +@@CheckMinY: + mov ax, ds:[bx].Y + cmp ax, [BoxY1] + jge @@CheckMaxY + mov [BoxY1], ax +@@CheckMaxY: + cmp ax, [BoxY2] + jle @@CheckDone + mov [BoxY2], ax + +; Repeat thru all points +@@CheckDone: + inc di ; Next map entry + inc dx + inc di + inc dx + dec cx + jnz @@MinMaxLoop + +;--------------------------------- +; Check if polygon is full clipped + mov ax, [BoxX2] + cmp ax, [mx_ClipX1] ; Is poly full clipped? + jl @@Exit + mov bx, [BoxX1] + cmp bx, [mx_ClipX2] ; Is poly full clipped? + jg @@Exit + sub ax, bx ; Get width + jle @@Exit ; Exit if not positive + mov ax, [BoxY2] + cmp ax, [mx_ClipY1] ; Is poly full clipped? + jl @@Exit + mov bx, [BoxY1] + cmp bx, [mx_ClipY2] ; Is poly full clipped? + jg @@Exit + sub ax, bx ; Get height + jle @@Exit ; Exit if not positive + + dec [Count] + shl [Count], 1 ; We'll work with word offsets + mov es, [mx_CodeSegment] + +;-------------- +; Scan top edge + mov ax, OFFSET mx_ScanBuffer + mov [ScanOffsetT], ax + mov si, [MinIdxT] ; Offset of bottom point index +@@STLoop: + lds bx, [Map] ; DS:BX -> map table + mov di, ds:[bx+si] ; Index of top point #1 + dec si ; Next point + dec si + test si, si + jnl @@ST1 + mov si, [Count] +@@ST1: + mov [MinIdxT], si ; Save new index of top point + mov si, ds:[bx+si] ; Get index of top point #2 + .shl di, 2 ; Convert indexes to offsets + .shl si, 2 + lds bx, [Points] ; DS:BX -> point array + add si, bx ; DS:SI -> top point #2 + add bx, di ; DS:BX -> top point #1 + mov di, [ScanOffsetT] + call subScan ; Scan edge + mov [ScanOffsetT], di + mov si, [MinIdxT] + cmp si, [MaxIdx] ; End of edge? + jne @@STLoop ; No, continue + +;----------------- +; Scan bottom edge + mov ax, OFFSET mx_ScanBuffer + OFFSET Y2 + mov [ScanOffsetB], ax + mov si, [MinIdxB] ; Offset of bottom point index +@@SBLoop: + lds bx, [Map] ; DS:BX -> map table + mov di, ds:[bx+si] ; Index of bottom point #1 + inc si ; Next bottom point + inc si + cmp si, [Count] + jbe @@SB1 + xor si, si +@@SB1: + mov [MinIdxB], si ; Save new index of bottom point + mov si, ds:[bx+si] ; Get index of bottom point #2 + .shl di, 2 ; Convert indexes to offsets + .shl si, 2 + lds bx, [Points] ; DS:BX -> point array + add si, bx ; DS:SI -> top point #2 + add bx, di ; DS:BX -> top point #1 + mov di, [ScanOffsetB] + call subScan ; Scan edge + mov [ScanOffsetB], di + mov si, [MinIdxB] + cmp si, [MaxIdx] ; End of edge? + jne @@SBLoop ; No, continue + +;-------------------- +; Clip left and right + mov si, OFFSET mx_ScanBuffer + mov ax, [BoxX1] + mov cx, [BoxX2] + sub cx, ax ; CX = bounding box width + mov bx, [mx_ClipX1] + sub bx, ax + jle @@ClipL1 ; No need to clip left + sub cx, bx ; Update width + add ax, bx ; BoxX1 = mx_ClipX1 + mov [BoxX1], ax + .shl bx, 2 ; Warning!!! This is an hand-coded + add si, bx ; multiply by the size of TSCAN +@@ClipL1: + mov bx, ax + add bx, cx ; Last scan column + sub bx, [mx_ClipX2] + jle @@ClipL2 ; No need to clip right + sub cx, bx ; Clip right +@@ClipL2: + test cx, cx ; Is clipped width positive? + jle @@Exit ; No, exit + mov [ScanCount], cx ; Save number of columns to draw + mov [ScanOffsetT], si ; Remember offset of (clipped) buffer + mov ds, [mx_CodeSegment] ; DS:SI -> scan buffer + +;------------------------------ +; Check if Y clipping is needed + mov ax, [BoxY1] + cmp ax, [mx_ClipY1] + jl @@ClipTB ; Need to clip top + mov ax, [BoxY2] + cmp ax, [mx_ClipY2] + jg @@ClipTB ; Need to clip bottom + jmp @@ClipYExit ; Skip Y clipping + +;-------------------- +; Clip top and bottom +@@ClipTB: + mov di, cx ; DI = scan count + inc di ; Increment count for pre-loop test + sub si, SIZE TSCAN +@@ClipYLoop: + dec di ; Any column left? + jz @@ClipYExit ; No, exit + add si, SIZE TSCAN + mov ax, ds:[si].Y1 ; Y1 + mov cx, ds:[si].Y2 ; Y2 + mov dx, [mx_ClipY2] + cmp ax, dx ; Full clipped? + jg @@ClipYClip ; Yes, skip this column + cmp cx, dx ; Need to clip bottom? + jle @@ClipY1 ; No, continue +; Clip bottom + mov ds:[si].Y2, dx + mov bx, cx + sub bx, dx ; Clip distance + sub cx, ax ; Height + jle @@ClipYClip + mov cx, ds:[si].Y2 +@@ClipY1: + mov dx, [mx_ClipY1] + cmp cx, dx ; Full top clipped? + jl @@ClipYClip ; Yes, skip + sub cx, ax ; Get height + jle @@ClipYClip ; Skip if not positive + cmp ax, dx ; Need to clip top? + jge @@ClipYLoop ; No, continue +; Clip top + mov ds:[si].Y1, dx ; Y1 = mx_ClipY1 + sub dx, ax ; DX = number of pixels clipped + cmp cx, dx + ja @@ClipYLoop ; Not clipped, continue +@@ClipYClip: + mov ds:[si].Y1, -1 ; Mark column as clipped + jmp @@ClipYLoop +@@ClipYExit: + +;------------- +; Draw columns + mov es, [mx_VideoSegment] + mov si, [ScanOffsetT] + mov cl, BYTE PTR [BoxX1] ; Init write plane + and cl, 03h + mov al, 11h + shl al, cl + mov [WritePlane], al + .shr [BoxX1], 2 +@@DrawLoop: + mov ax, ds:[si].Y1 + test ax, ax ; Was column clipped? + js @@DrawNext ; Yes, skip + mov cx, ds:[si].Y2 + sub cx, ax ; CX = height + jle @@DrawNext + mul [mx_BytesPerLine] ; Get pixel address + add ax, [BoxX1] + mov di, ax + mov ah, [WritePlane] + mov dx, TS + mov al, 02h + out dx, ax + mov ax, [Color] + mov dx, [mx_BytesPerLine] + shr cx, 1 + jnc @@FillScan + mov es:[di], al + add di, dx + jcxz @@DrawNext +@@FillScan: + mov es:[di], al + add di, dx + mov es:[di], al + add di, dx + dec cx + jnz @@FillScan +@@DrawNext: + rol [WritePlane], 1 + adc [BoxX1], 0 ; Bump pointer to video memory if needed + add si, SIZE TSCAN + dec [ScanCount] + jnz @@DrawLoop + +@@Exit: + xor ax, ax + .pop ds, si, es, di + .leave ARG_SIZE +mxFillPoly ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxpg.asm b/16/x/mxpg.asm new file mode 100755 index 00000000..caa7cf1b --- /dev/null +++ b/16/x/mxpg.asm @@ -0,0 +1,589 @@ +;----------------------------------------------------------- +; +; MXPG.ASM - Convex polygon fill with Gouraud shading +; Copyright (c) 1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +NOWARN RES +INCLUDE MODEX.DEF + +PUBLIC mxGouraudPoly + +;----------------------------------------------------------- +; +; "Local" definitions +; +TPOINT STRUC + X DW ? + Y DW ? +TPOINT ENDS + +; Do NOT change order! +TSCAN STRUC + Y1 DW ? + E1 DB ? + C1 DB ? + Y2 DW ? + E2 DB ? + C2 DB ? +TSCAN ENDS + +MAXSCANCOLUMNS EQU POLYSCANBUFSIZE / SIZE TSCAN + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +EXTRN mx_VideoSegment : WORD +EXTRN mx_CodeSegment : WORD +EXTRN mx_BytesPerLine : WORD +EXTRN mx_ClipX1 : WORD +EXTRN mx_ClipY1 : WORD +EXTRN mx_ClipX2 : WORD +EXTRN mx_ClipY2 : WORD +EXTRN mx_ScanBuffer : NEAR + +;----------------------------------------------------------- +; +; Scans an edge using the DDA (digital differential analyzer) algorithm. +; Also interpolates color for shading. +; +; Input: +; DS:BX = pointer to start point (X1, Y1) +; DS:SI = pointer to end point (X2, Y2) +; ES:DI = pointer to edge buffer +; DX = start color +; AX = end color +; Output: +; ES:DI = updated pointer to edge buffer +; Notes: +; must preserve DS:SI. +; +subScan PROC NEAR + mov cx, ds:[si].X + sub cx, ds:[bx].X ; Get width + jg @@1 + ret +@@1: + push bp ; Save BP + push di ; Save scan info offset + push cx ; Save height + push ax ; Save colors + push dx + + mov ax, ds:[si].Y + mov bx, ds:[bx].Y + sub ax, bx ; Get height + jg @@T2B ; Scan top to bottom + jl @@B2T ; Scan bottom to top + +; Special case: vertical line + mov ax, bx +@@V: + mov es:[di].Y1, ax + add di, SIZE TSCAN + dec cx + jnz @@V + jmp @@GetColorInfo + +; Scan top to bottom +@@T2B: + cwd + div cx + mov bp, ax + xor ax, ax + div cx + xchg ax, bx ; BP:BX = fixed 16:16 step + mov dx, 8000h +@@T2BLoop: + mov es:[di].Y1, ax + add di, SIZE TSCAN + add dx, bx + adc ax, bp + dec cx + jnz @@T2BLoop + jmp @@GetColorInfo + +; Scan bottom to top +@@B2T: + neg ax + cwd + div cx + mov bp, ax + xor ax, ax + div cx + xchg ax, bx + mov dx, 8000h +@@B2TLoop: + mov es:[di].Y1, ax + add di, SIZE TSCAN + sub dx, bx + sbb ax, bp + dec cx + jnz @@B2TLoop + +; Now get the color info +@@GetColorInfo: + pop bx ; Restore colors + pop ax + pop cx ; Height + pop di ; ES:DI -> scan info + + sub ax, bx ; Get color range + jg @@CL2R + jl @@CR2L + +; Special case: same color + mov ah, bl + mov al, 80h +@@CV: + mov WORD PTR es:[di].E1, ax + add di, SIZE TSCAN + dec cx + jnz @@CV + jmp @@Exit + +; Scan left to right +@@CL2R: + cwd + div cx + mov bp, ax + xor ax, ax + div cx + xchg ax, bx ; BP:BX = fixed 16:16 step + mov dx, 8000h +@@CL2RLoop: + mov es:[di].C1, al + mov es:[di].E1, dh + add di, SIZE TSCAN + add dx, bx + adc ax, bp + dec cx + jnz @@CL2RLoop + jmp @@Exit + +; Scan right to left +@@CR2L: + neg ax + cwd + div cx + mov bp, ax + xor ax, ax + div cx + xchg ax, bx + mov dx, 8000h + +@@CR2LLoop: + mov es:[di].C1, al + mov es:[di].E1, dh + add di, SIZE TSCAN + sub dx, bx + sbb ax, bp + dec cx + jnz @@CR2LLoop + +@@Exit: + pop bp + ret +subScan ENDP + +;----------------------------------------------------------- +; +; Fills a scan column. +; +; Input: +; DS:SI = current TSCAN +; ES:DI = address of top pixel +; CX = number of pixels to write +; DX = base color +; Output: +; none +; +subFillScan PROC NEAR + mov ax, WORD PTR ds:[si].E2 + mov bx, WORD PTR ds:[si].E1 + cmp ah, bh + jg @@L2R ; Color increases + jl @@R2L ; Color decreases + +; Special case: color doesn't change + add ax, dx + mov dx, [mx_BytesPerLine] +@@V: + mov es:[di], ah + add di, dx + dec cx + jnz @@V + ret + +; Color increases +@@L2R: + .push bp, si + mov si, bx + add si, dx ; Relocate color + sub ax, bx + xor dx, dx + div cx + mov bp, ax ; BP = color step, integer part + xor ax, ax + div cx + mov bx, ax ; BX = color step, fractional part + mov dx, 8000h + mov ax, [mx_BytesPerLine] + xchg si, ax +@@L2RLoop: + mov es:[di], ah + add dx, bx + adc ax, bp + add di, si + dec cx + jnz @@L2RLoop + .pop bp, si + ret + +; Color decreases +@@R2L: + .push bp, si + mov si, bx + add si, dx ; Relocate color + sub ax, bx + neg ax + xor dx, dx + div cx + mov bp, ax ; BP = color step, integer part + xor ax, ax + div cx + mov bx, ax ; BX = color step, fractional part + mov dx, 8000h + mov ax, [mx_BytesPerLine] + xchg si, ax +@@R2LLoop: + mov es:[di], ah + sub dx, bx + sbb ax, bp + add di, si + dec cx + jnz @@R2LLoop + .pop bp, si + ret +subFillScan ENDP + +;----------------------------------------------------------- +; +; Fills a convex polygon with the specified color. +; Interpolates pixel colors using the Gouraud algorithm. +; +; Input: +; Count = number of vertexes +; Map = indexes of points and colors (integer) +; Points = array of points (integer X, Y coordinates) +; Colors = array of colors (integer) +; Color = base color +; Output: +; none +; Notes: +; vertexes must be in counterclockwise order, arrays are 0-based. +; +mxGouraudPoly PROC FAR + ARG Color:WORD, \ + Colors:DWORD, \ + Points:DWORD, \ + Map:DWORD, \ + Count:WORD = ARG_SIZE + LOCAL WritePlane:BYTE:2, \ + ScanOffsetT:WORD, \ + ScanOffsetB:WORD, \ + ScanCount:WORD, \ + Holder:WORD, \ + Height:WORD, \ + MinIdxT:WORD, \ + MinIdxB:WORD, \ + MaxIdx:WORD, \ + Width:WORD, \ + BoxX1:WORD, \ + BoxY1:WORD, \ + BoxX2:WORD, \ + BoxY2::WORD = AUTO_SIZE + .enter AUTO_SIZE + .push ds, si, es, di + ASSUME ds:NOTHING + +; Check that at least three vertexes are specified + mov cx, [Count] + cmp cx, 3 + jb @@Exit + +;------------------------------ +; Find bounding box for polygon + les di, [Map] + lds si, [Points] ; Pointer to vertex array + mov [BoxX1], 32767 + mov [BoxX2], -32768 + mov [BoxY1], 32767 + mov [BoxY2], -32768 + + xor dx, dx +@@MinMaxLoop: + mov bx, es:[di] ; Get index of vertex + .shl bx, 2 ; Get offset in point array + add bx, si + +; Check X range +@@CheckMinX: + mov ax, ds:[bx].X ; Get X coordinate + cmp ax, [BoxX1] + jge @@CheckMaxX + mov [BoxX1], ax + mov [MinIdxT], dx + mov [MinIdxB], dx +@@CheckMaxX: + cmp ax, [BoxX2] + jle @@CheckMinY + mov [BoxX2], ax + mov [MaxIdx], dx + +; Check Y range +@@CheckMinY: + mov ax, ds:[bx].Y + cmp ax, [BoxY1] + jge @@CheckMaxY + mov [BoxY1], ax +@@CheckMaxY: + cmp ax, [BoxY2] + jle @@CheckDone + mov [BoxY2], ax + +; Repeat thru all points +@@CheckDone: + inc di ; Next map entry + inc di + inc dx + inc dx + dec cx + jnz @@MinMaxLoop + +;--------------------------------- +; Check if polygon is full clipped + mov ax, [BoxX2] + cmp ax, [mx_ClipX1] ; Is poly full clipped? + jl @@Exit + mov bx, [BoxX1] + cmp bx, [mx_ClipX2] ; Is poly full clipped? + jg @@Exit + sub ax, bx ; Get width + jle @@Exit ; Exit if not positive + mov ax, [BoxY2] + cmp ax, [mx_ClipY1] ; Is poly full clipped? + jl @@Exit + mov bx, [BoxY1] + cmp bx, [mx_ClipY2] ; Is poly full clipped? + jg @@Exit + sub ax, bx ; Get height + jle @@Exit ; Exit if not positive + + dec [Count] + shl [Count], 1 ; We'll work with word offsets + mov es, [mx_CodeSegment] + +;-------------- +; Scan top edge + mov ax, OFFSET mx_ScanBuffer + mov [ScanOffsetT], ax + mov si, [MinIdxT] ; Offset of bottom point index +@@STLoop: + lds bx, [Map] ; DS:BX -> map table + mov di, ds:[bx+si] ; Index of top point #1 + dec si ; Next point + dec si + test si, si + jnl @@ST1 + mov si, [Count] +@@ST1: + mov [MinIdxT], si ; Save new index of top point + mov si, ds:[bx+si] ; Get index of top point #2 + lds bx, [Colors] ; Get pointer to color array + shl di, 1 ; Convert indexes to offsets + shl si, 1 + mov ax, ds:[bx+si] ; Get colors + mov dx, ds:[bx+di] + lds bx, [Points] ; DS:BX -> point array + shl si, 1 + shl di, 1 + add si, bx ; DS:SI -> top point #2 + add bx, di ; DS:BX -> top point #1 + mov di, [ScanOffsetT] + call subScan ; Scan edge + mov [ScanOffsetT], di + mov si, [MinIdxT] + cmp si, [MaxIdx] ; End of edge? + jne @@STLoop ; No, continue + +;----------------- +; Scan bottom edge + mov ax, OFFSET mx_ScanBuffer + OFFSET Y2 + mov [ScanOffsetB], ax + mov si, [MinIdxB] ; Offset of bottom point index +@@SBLoop: + lds bx, [Map] ; DS:BX -> map table + mov di, ds:[bx+si] ; Index of bottom point #1 + inc si ; Next bottom point + inc si + cmp si, [Count] + jbe @@SB1 + xor si, si +@@SB1: + mov [MinIdxB], si ; Save new index of bottom point + mov si, ds:[bx+si] ; Get index of bottom point #2 + lds bx, [Colors] ; Get pointer to color array + shl di, 1 ; Convert indexes to offsets + shl si, 1 + mov ax, ds:[bx+si] ; Get colors + mov dx, ds:[bx+di] + lds bx, [Points] ; DS:BX -> point array + shl si, 1 + shl di, 1 + add si, bx ; DS:SI -> top point #2 + add bx, di ; DS:BX -> top point #1 + mov di, [ScanOffsetB] + call subScan ; Scan edge + mov [ScanOffsetB], di + mov si, [MinIdxB] + cmp si, [MaxIdx] ; End of edge? + jne @@SBLoop ; No, continue + +;-------------------- +; Clip left and right + mov si, OFFSET mx_ScanBuffer + mov ax, [BoxX1] + mov cx, [BoxX2] + sub cx, ax ; CX = bounding box width + mov bx, [mx_ClipX1] + sub bx, ax + jle @@ClipL1 ; No need to clip left + sub cx, bx ; Update width + add ax, bx ; BoxX1 = mx_ClipX1 + mov [BoxX1], ax + .shl bx, 3 ; Warning!!! This is an hand-coded + add si, bx ; multiply by the size of TSCAN +@@ClipL1: + mov bx, ax + add bx, cx ; Last scan column + sub bx, [mx_ClipX2] + jle @@ClipL2 ; No need to clip right + sub cx, bx ; Clip right +@@ClipL2: + test cx, cx ; Is clipped width positive? + jle @@Exit ; No, exit + mov [ScanCount], cx ; Save number of columns to draw + mov [ScanOffsetT], si ; Remember offset of (clipped) buffer + mov ds, [mx_CodeSegment] ; DS:SI -> scan buffer + +;------------------------------ +; Check if Y clipping is needed + mov ax, [BoxY1] + cmp ax, [mx_ClipY1] + jl @@ClipTB ; Need to clip top + mov ax, [BoxY2] + cmp ax, [mx_ClipY2] + jg @@ClipTB ; Need to clip bottom + jmp @@ClipYExit ; Skip Y clipping + +;-------------------- +; Clip top and bottom +@@ClipTB: + mov di, cx ; DI = scan count + inc di ; Increment count for pre-loop test + sub si, SIZE TSCAN +@@ClipYLoop: + dec di ; Any column left? + jz @@ClipYExit ; No, exit + add si, SIZE TSCAN + mov ax, ds:[si].Y1 ; Y1 + mov cx, ds:[si].Y2 ; Y2 + mov dx, [mx_ClipY2] + cmp ax, dx ; Full clipped? + jg @@ClipYClip ; Yes, skip this column + cmp cx, dx ; Need to clip bottom? + jle @@ClipY1 ; No, continue +; Clip bottom, need to scale colors too + mov ds:[si].Y2, dx + mov bx, cx + sub bx, dx ; Clip distance + sub cx, ax ; Height + jle @@ClipYClip + mov ax, WORD PTR ds:[si].E1 + sub ax, WORD PTR ds:[si].E2 + imul bx + idiv cx + add WORD PTR ds:[si].E2, ax + mov ax, ds:[si].Y1 ; Restore AX and CX + mov cx, ds:[si].Y2 +@@ClipY1: + mov dx, [mx_ClipY1] + cmp cx, dx ; Full top clipped? + jl @@ClipYClip ; Yes, skip + sub cx, ax ; Get height + jle @@ClipYClip ; Skip if not positive + cmp ax, dx ; Need to clip top? + jge @@ClipYLoop ; No, continue +; Clip top, need to scale colors too + mov ds:[si].Y1, dx ; Y1 = mx_ClipY1 + sub dx, ax ; DX = number of pixels clipped + cmp cx, dx + jbe @@ClipYClip ; Full clipped, skip + mov ax, WORD PTR ds:[si].E2 + sub ax, WORD PTR ds:[si].E1 ; AX = color distance + imul dx + idiv cx + add WORD PTR ds:[si].E1, ax ; Update starting color + jmp @@ClipYLoop +@@ClipYClip: + mov ds:[si].Y1, -1 ; Mark column as clipped + jmp @@ClipYLoop +@@ClipYExit: + +;------------- +; Draw columns + mov es, [mx_VideoSegment] + mov si, [ScanOffsetT] + mov cl, BYTE PTR [BoxX1] ; Init write plane + and cl, 03h + mov al, 11h + shl al, cl + mov [WritePlane], al + .shr [BoxX1], 2 + mov ax, [Color] ; Make 8:8 fixed color + mov ah, al + xor al, al + mov [Color], ax +@@DrawLoop: + mov ax, ds:[si].Y1 + test ax, ax ; Was column clipped? + js @@DrawNext ; Yes, skip + mov cx, ds:[si].Y2 + sub cx, ax ; CX = height + jle @@DrawNext + mul [mx_BytesPerLine] ; Get pixel address + add ax, [BoxX1] + mov di, ax + mov ah, [WritePlane] + mov al, 02h + mov dx, TS + out dx, ax + mov dx, [Color] + call subFillScan +@@DrawNext: + rol [WritePlane], 1 + adc [BoxX1], 0 ; Bump pointer to video memory if needed + add si, SIZE TSCAN + dec [ScanCount] + jnz @@DrawLoop + +@@Exit: + xor ax, ax + .pop ds, si, es, di + .leave ARG_SIZE +mxGouraudPoly ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxpi.asm b/16/x/mxpi.asm new file mode 100755 index 00000000..9e8525f5 --- /dev/null +++ b/16/x/mxpi.asm @@ -0,0 +1,267 @@ +;----------------------------------------------------------- +; +; MXPI.ASM - Put image +; Copyright (c) 1993,1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +NOWARN RES +INCLUDE MODEX.DEF + +PUBLIC mxPutImage + +EXTRN subClipImage : NEAR + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +EXTRN mx_VideoSegment : WORD +EXTRN mx_BytesPerLine : WORD + +mxTable LABEL WORD ; Raster ops + DW subMove + DW subAnd + DW subOr + DW subXor + DW subTrans + DW subAdd + +;----------------------------------------------------------- +; +; Move functions. +; Note: loops unrolled and optimized for CX even, no check for CX = 0. +; +subMove PROC NEAR + shr cx, 1 ; Make CX even + jc @@Odd ; Special case if odd byte +@@Loop: movsb + add si, 3 + movsb + add si, 3 + dec cx + jnz @@Loop +@@Exit: ret +@@Odd: movsb + add si, 3 + jcxz @@Exit + jmp @@Loop +subMove ENDP +; +subAnd PROC NEAR + shr cx, 1 + jc @@Odd +@@Loop: mov al, ds:[si] + mov ah, ds:[si+4] + and es:[di], ax + inc di + inc di + add si, 8 + dec cx + jnz @@Loop +@@Exit: ret +@@Odd: lodsb + and es:[di], al + inc di + add si, 3 + jcxz @@Exit + jmp @@Loop +subAnd ENDP +; +subOr PROC NEAR + shr cx, 1 + jc @@Odd +@@Loop: mov al, ds:[si] + mov ah, ds:[si+4] + or es:[di], ax + inc di + inc di + add si, 8 + dec cx + jnz @@Loop +@@Exit: ret +@@Odd: lodsb + or es:[di], al + inc di + add si, 3 + jcxz @@Exit + jmp @@Loop +subOr ENDP +; +subXor PROC NEAR + shr cx, 1 + jc @@Odd +@@Loop: mov al, ds:[si] + mov ah, ds:[si+4] + xor es:[di], ax + inc di + inc di + add si, 8 + dec cx + jnz @@Loop +@@Exit: ret +@@Odd: lodsb + xor es:[di], al + inc di + add si, 3 + jcxz @@Exit + jmp @@Loop +subXor ENDP +; +subTrans PROC NEAR +@@Loop: mov al, ds:[si] + cmp al, ah + je @@Skip + mov es:[di], al +@@Skip: inc di + add si, 4 + dec cx + jnz @@Loop +@@Exit: ret +subTrans ENDP +; +subAdd PROC NEAR +@@Loop: mov al, ds:[si] + add es:[di], al + inc di + add si, 4 + dec cx + jnz @@Loop + ret +subAdd ENDP + +;----------------------------------------------------------- +; +; Copies a "raw" image from memory to screen. +; +; Input: +; Image = pointer to image +; X, Y = coordinates of destination +; Width = width of image in pixels +; Height = height of image in pixels +; Op = raster op (OP_xxx) +; Output: +; none +; +mxPutImage PROC FAR + ARG Op:WORD, \ + Height:WORD, \ + Width:WORD, \ + Y:WORD, \ + X:WORD, \ + Image:DWORD = ARG_SIZE + LOCAL PlaneWidth:WORD:4, \ + PixelOffset:WORD, \ + MoveFunction:WORD, \ + Count:BYTE, \ + ReadPlane:BYTE, \ + OpInfo:BYTE, \ + WritePlane:BYTE = AUTO_SIZE + ASSUME ds:NOTHING + .enter AUTO_SIZE + .push ds, si, es, di + +; Clip image + mov bx, [X] + mov ax, [Y] + mov cx, [Width] + mov dx, [Height] + call subClipImage + jc @@Exit ; Full clipped + mov [Height], dx + add WORD PTR Image[0], si ; Skip clipped pixels + +; Get pixel address + mul [mx_BytesPerLine] + mov di, bx + shr di, 1 + shr di, 1 + add di, ax + mov [PixelOffset], di + mov es, [mx_VideoSegment] ; ES:DI points to pixel + and bl, 03h + mov [ReadPlane], bl + +; Compute extra bytes and width count for each plane + mov bx, cx + shr bx, 1 + shr bx, 1 ; Width for each plane + and cl, 03h + mov al, 00001000b + shr al, cl + mov si, 3 SHL 1 +@@PatchLoop: + mov PlaneWidth[si], bx + shr al, 1 + adc bx, 0 + dec si + dec si + jge @@PatchLoop + +; Setup planes for output to VGA registers + mov cl, [ReadPlane] + mov al, 00010001b + shl al, cl + mov [WritePlane], al + +; Install move function + mov bx, [Op] + mov [OpInfo], bh ; Remember additional info if needed + xor bh, bh + cmp bl, OP_ADD + jbe @@SetMoveFunction + xor bl, bl +@@SetMoveFunction: + shl bx, 1 + mov ax, mxTable[bx] + mov [MoveFunction], ax + +; Put image + cld + mov [Count], 4 ; Four planes + lea bx, PlaneWidth ; SS:[BX] = width in bytes for plane + mov ds, WORD PTR Image[2] +@@PlaneLoop: + cmp WORD PTR ss:[bx], 0 ; Exit if nothing more to do + je @@Exit ; (also, never try to move zero bytes!) + mov si, WORD PTR Image[0] + mov ah, [WritePlane] + and ah, 0Fh + mov al, 02h + mov dx, TS + out dx, ax ; Select write plane + mov ah, [ReadPlane] + and ah, 03h + mov al, 04h + mov dx, GDC + out dx, ax ; Select read plane + mov dx, [Height] + mov di, [PixelOffset] +@@Loop: + push si + push di + mov cx, WORD PTR ss:[bx] ; Number of bytes to move + mov ah, [OpInfo] ; Transparent color for subTrans + call [MoveFunction] + pop di + pop si + add si, [Width] ; Go to next image line + add di, [mx_BytesPerLine] ; Go to next screen row + dec dx + jnz @@Loop ; Repeat for all lines + inc bx + inc bx ; Select width for next plane + inc [ReadPlane] + rol [WritePlane], 1 + adc [PixelOffset], 0 + inc WORD PTR Image[0] + dec [Count] + jnz @@PlaneLoop ; Repeat for all planes + +@@Exit: + xor ax, ax + .pop ds, si, es, di + .leave ARG_SIZE +mxPutImage ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxpn.asm b/16/x/mxpn.asm new file mode 100755 index 00000000..eaaf61b4 --- /dev/null +++ b/16/x/mxpn.asm @@ -0,0 +1,60 @@ +;----------------------------------------------------------- +; +; MXPN.ASM - Panning function +; Copyright (c) 1993,1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +INCLUDE MODEX.DEF + +PUBLIC mxPan + +EXTRN mxWaitDisplay : FAR +EXTRN mxStartAddress : FAR + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +EXTRN mx_BytesPerLine : WORD + +;----------------------------------------------------------- +; +; Moves the screen. +; +; Input: +; X, Y = new X, Y coordinates of view screen +; Output: +; none +; +mxPan PROC FAR + ARG Y:WORD, \ + X:WORD = ARG_SIZE + ASSUME ds:NOTHING + .enter 0 + + mov ax, [Y] + mul [mx_BytesPerLine] + mov dx, [X] + shr dx, 1 + shr dx, 1 + add ax, dx + push ax ; Push the start address + call mxWaitDisplay + call mxStartAddress + + mov dx, 03DAh ; Set the pixel pan register + in al, dx + mov dx, 03C0h + mov al, 33h + out dx, al + mov al, BYTE PTR [X] + and al, 3 + shl al, 1 + out dx, al + + xor ax, ax + .leave ARG_SIZE +mxPan ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxpp.asm b/16/x/mxpp.asm new file mode 100755 index 00000000..fc1755a3 --- /dev/null +++ b/16/x/mxpp.asm @@ -0,0 +1,121 @@ +;----------------------------------------------------------- +; +; MXPP.ASM - Get/put pixel functions +; Copyright (c) 1993,1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +INCLUDE MODEX.DEF + +PUBLIC mxGetPixel +PUBLIC mxPutPixel + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +EXTRN mx_BytesPerLine : WORD +EXTRN mx_VideoSegment : WORD +EXTRN mx_ClipX1 : WORD +EXTRN mx_ClipY1 : WORD +EXTRN mx_ClipX2 : WORD +EXTRN mx_ClipY2 : WORD + +;----------------------------------------------------------- +; +; Gets a pixel. +; +; Input: +; X, Y = pixel coordinates +; Output: +; pixel color +; +mxGetPixel PROC FAR + ARG Y:WORD, \ + X:WORD = ARG_SIZE + ASSUME ds:NOTHING + .enter 0 + .push ds, si + + xor ax, ax + mov si, [X] + cmp si, [mx_ClipX1] + jl @@Exit + cmp si, [mx_ClipX2] + jg @@Exit + mov bx, [Y] + cmp bx, [mx_ClipY1] + jl @@Exit + cmp bx, [mx_ClipY2] + jg @@Exit + + mov al, 04h ; Set read plane + mov ah, BYTE PTR [X] + and ah, 3 + mov dx, GDC + out dx, ax + + mov ds, [mx_VideoSegment] + mov ax, bx + mul [mx_BytesPerLine] + .shr si, 2 + add si, ax + + mov al, ds:[si] ; Get pixel value + xor ah, ah + +@@Exit: + .pop ds, si + .leave ARG_SIZE +mxGetPixel ENDP + +;----------------------------------------------------------- +; +; Puts a pixel of the specified color. +; +; Input: +; X, Y = pixel coordinates +; Color = pixel color +; Output: +; none +; +mxPutPixel PROC FAR + ARG Color:BYTE:2, \ + Y:WORD, \ + X:WORD = ARG_SIZE + .enter 0 + .push ds, si + + mov si, [X] + cmp si, [mx_ClipX1] + jl @@Exit + cmp si, [mx_ClipX2] + jg @@Exit + mov ax, [Y] + cmp ax, [mx_ClipY1] + jl @@Exit + cmp ax, [mx_ClipY2] + jg @@Exit + + mov ds, [mx_VideoSegment] + mul [mx_BytesPerLine] + .shr si, 2 + add si, ax + + mov cl, BYTE PTR [X] ; Set write plane + and cl, 3 + mov ax, 0102h + shl ah, cl + mov dx, TS + out dx, ax + + mov al, [Color] ; Write pixel + mov ds:[si], al + +@@Exit: + xor ax, ax + .pop ds, si + .leave ARG_SIZE +mxPutPixel ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxra.asm b/16/x/mxra.asm new file mode 100755 index 00000000..dd8e6839 --- /dev/null +++ b/16/x/mxra.asm @@ -0,0 +1,37 @@ +;----------------------------------------------------------- +; +; MXRA.ASM - Row address +; Copyright (c) 1993,1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +INCLUDE MODEX.DEF + +PUBLIC mxRowAddress + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +;----------------------------------------------------------- +; +; Sets the row address register. +; +; Input: +; RowAddress = row size in words +; Output: +; none +; +mxRowAddress PROC FAR + ARG RowAddress:BYTE:2 = ARG_SIZE + ASSUME ds:NOTHING + .enter 0 + mov dx, CRTC + mov al, 13h + mov ah, [RowAddress] + out dx, ax + xor ax, ax + .leave ARG_SIZE +mxRowAddress ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxrp.asm b/16/x/mxrp.asm new file mode 100755 index 00000000..de820c16 --- /dev/null +++ b/16/x/mxrp.asm @@ -0,0 +1,101 @@ +;----------------------------------------------------------- +; +; MXRP.ASM - Rotate palette function +; Copyright (c) 1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +INCLUDE MODEX.DEF + +PUBLIC mxRotatePalette + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +;----------------------------------------------------------- +; +; Rotates the palette of the specified number of colors. +; +; Input: +; Palette = pointer to palette +; Count = number of colors to rotate +; Step = step size +; Output: +; none +; +; Note: if Step is positive palette is rotated left to right, otherwise +; right to left. +; +mxRotatePalette PROC FAR + ARG Step:WORD, \ + Count:WORD, \ + Palette:DWORD = ARG_SIZE + LOCAL Holder:BYTE:768 = AUTO_SIZE + ASSUME ds:NOTHING + .enter AUTO_SIZE + .push ds, si, es, di + + mov bx, [Count] + add bx, bx + add bx, [Count] ; BX = Count*3 + + lds si, [Palette] ; DS:SI -> palette + push ss + pop es + lea di, Holder ; ES:DI -> local space + cld + + mov ax, [Step] + mov dx, ax + test ax, ax + jz @@Exit ; Nothing to do, exit + jl @@RightToLeft + +@@LeftToRight: + add ax, ax + add dx, ax ; DX = Step*3 + sub bx, dx ; BX = (Count-Step)*3 + add si, bx + push si + mov cx, dx + rep movsb + mov es, WORD PTR Palette[2] + mov di, si + dec di ; ES:DI -> last byte of palette + pop si + dec si + mov cx, bx + std + rep movsb + push ss + pop ds + lea si, Holder + les di, [Palette] + mov cx, dx + cld + rep movsb + jmp @@Exit + +@@RightToLeft: + add ax, ax + add dx, ax + neg dx ; DX = Step*3 + sub bx, dx ; BX = (Count-Step)*3 + mov cx, dx + rep movsb + les di, [Palette] + mov cx, bx + rep movsb + push ss + pop ds + lea si, Holder + mov cx, dx + rep movsb + +@@Exit: + .pop ds, si, es, di + .leave ARG_SIZE +mxRotatePalette ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxsa.asm b/16/x/mxsa.asm new file mode 100755 index 00000000..3ebae67d --- /dev/null +++ b/16/x/mxsa.asm @@ -0,0 +1,44 @@ +;----------------------------------------------------------- +; +; MXSA.ASM - Start address function +; Copyright (c) 1993,1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +INCLUDE MODEX.DEF + +PUBLIC mxStartAddress + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +;----------------------------------------------------------- +; +; Modifies the starting address of video memory. +; +; Input: +; StartAddr = new start address of video memory +; Output: +; none +; +mxStartAddress PROC FAR + ARG StartAddr:WORD = ARG_SIZE + ASSUME ds:NOTHING + .enter 0 + + mov bx, [StartAddr] + mov dx, CRTC + mov al, 0Ch ; Linear Starting Address high + mov ah, bh + cli + out dx, ax + mov al, 0Dh ; Linear Starting Address low + mov ah, bl + out dx, ax + sti + + .leave ARG_SIZE +mxStartAddress ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxsc.asm b/16/x/mxsc.asm new file mode 100755 index 00000000..bcae45e6 --- /dev/null +++ b/16/x/mxsc.asm @@ -0,0 +1,50 @@ +;----------------------------------------------------------- +; +; MXSC.ASM - Set color function +; Copyright (c) 1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +INCLUDE MODEX.DEF + +PUBLIC mxSetColor + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +;----------------------------------------------------------- +; +; Updates the selected DAC register. +; +; Input: +; Index = index of color to set +; R, G, B = color components +; Output: +; none +; +mxSetColor PROC FAR + ARG B:BYTE:2, \ + G:BYTE:2, \ + R:BYTE:2, \ + Index:WORD = ARG_SIZE + .enter 0 + .push ds, si + + mov ax, [Index] + mov dx, 3C8h ; PEL write address register + out dx, al + inc dx + + mov al, [R] + out dx, al + mov al, [G] + out dx, al + mov al, [B] + out dx, al + + .pop ds, si + .leave ARG_SIZE +mxSetColor ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxsi.asm b/16/x/mxsi.asm new file mode 100755 index 00000000..b88d3b11 --- /dev/null +++ b/16/x/mxsi.asm @@ -0,0 +1,317 @@ +;----------------------------------------------------------- +; +; MXPI.ASM - Stretch image +; Copyright (c) 1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +NOWARN RES +INCLUDE MODEX.DEF + +PUBLIC mxStretchImage + +EXTRN subClipBox : NEAR + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +EXTRN mx_VideoSegment : WORD +EXTRN mx_BytesPerLine : WORD + +mxTable LABEL WORD ; Raster ops + DW subMove + DW subAnd + DW subOr + DW subXor + DW subTrans + DW subAdd + +;----------------------------------------------------------- +; +; Stretches and copies a "raw" image from memory to screen. +; +; Input: +; Image = pointer to image +; X, Y = coordinates of destination +; Width = width of image in pixels +; Height = height of image in pixels +; NewWidth = new width of image in pixels +; NewHeight = new height of image in pixels +; Op = raster op (OP_xxx) +; Output: +; none +; +mxStretchImage PROC FAR + ARG Op:WORD, \ + NewHeight:WORD, \ + NewWidth:WORD, \ + Height:WORD, \ + Width:WORD, \ + Y:WORD, \ + X:WORD, \ + Image:DWORD = ARG_SIZE + LOCAL PixelOffset:WORD, \ + MoveFunction:WORD, \ + ReadPlane:BYTE, \ + OpInfo:BYTE, \ + WidthStep:DWORD, \ + HeightStep:DWORD, \ + ImageLo:WORD, \ + WritePlane:BYTE = AUTO_SIZE + ASSUME ds:NOTHING + .enter AUTO_SIZE + .push ds, si, es, di + +; Get width stretch factor + IF USE386 EQ TRUE + movzx edx, [Width] + xor eax, eax + movzx ebx, [NewWidth] + shl ebx, 16 + idiv ebx + mov [WidthStep], eax + ELSE + xor dx, dx ; Width stretch factor + mov ax, [Width] + mov bx, [NewWidth] + div bx + mov WORD PTR WidthStep[2], ax + xor ax, ax + div bx + mov WORD PTR WidthStep[0], ax + ENDIF +; Get height stretch factor + IF USE386 EQ TRUE + movzx edx, [Height] + xor eax, eax + movzx ebx, [NewHeight] + shl ebx, 16 + idiv ebx + mov [HeightStep], eax + ELSE + xor dx, dx + mov ax, [Height] + mov bx, [NewHeight] + div bx + mov WORD PTR HeightStep[2], ax + xor ax, ax + div bx + mov WORD PTR HeightStep[0], ax + ENDIF + +; Clip image + mov bx, [X] + mov ax, [Y] + mov cx, [NewWidth] + mov dx, [NewHeight] + call subClipBox + jc @@Exit ; Full clipped + mov [NewWidth], cx + mov [NewHeight], dx + sub [X], bx + sub [Y], ax + +; Get pixel address + mul [mx_BytesPerLine] + mov di, bx + shr di, 1 + shr di, 1 + add di, ax + mov [PixelOffset], di + mov es, [mx_VideoSegment] ; ES:DI points to pixel + and bl, 03h + mov [ReadPlane], bl ; Set read plane + mov cl, bl + mov al, 00010001b + shl al, cl + mov [WritePlane], al ; Set write plane + +; Relocate image origin if previously clipped + mov ax, [Y] + test ax, ax + jz @@OriginYDone + IF USE386 EQ TRUE + shl eax, 16 + imul [HeightStep] + mov ax, [Width] + mul dx + ELSE + mov bx, ax + mul WORD PTR HeightStep[0] + mov cx, dx + mov ax, bx + mul WORD PTR HeightStep[2] + add ax, cx + mul [Width] + ENDIF + add WORD PTR [Image], ax +@@OriginYDone: + mov ax, [X] + test ax, ax + jz @@OriginXDone + IF USE386 EQ TRUE + shl eax, 16 + imul [WidthStep] + add WORD PTR [Image], dx + ELSE + mov bx, ax + mul WORD PTR WidthStep[0] + mov cx, dx + mov ax, bx + mul WORD PTR WidthStep[2] + add ax, cx + add WORD PTR [Image], ax + ENDIF +@@OriginXDone: + mov ax, WORD PTR HeightStep[2] + mul [Width] + mov WORD PTR HeightStep[2], ax + +; Install move function + mov bx, [Op] + mov [OpInfo], bh ; Remember additional info if needed + xor bh, bh + cmp bl, OP_ADD + jbe @@SetMoveFunction + xor bl, bl +@@SetMoveFunction: + shl bx, 1 + mov ax, mxTable[bx] + mov [MoveFunction], ax + +; Put image + mov ds, WORD PTR Image[2] + xor ax, ax + mov [ImageLo], ax +@@Loop: + mov si, WORD PTR Image[0] ; Get pointer to image + mov ah, [WritePlane] + and ah, 0Fh + mov al, 02h + mov dx, TS + out dx, ax ; Select write plane + mov ah, [ReadPlane] + and ah, 03h + mov al, 04h + mov dx, GDC + out dx, ax ; Select read plane + mov cx, [NewHeight] + mov di, [PixelOffset] ; ES:DI points to video memory + mov ah, [OpInfo] ; Additional raster op info + xor bx, bx + mov dx, [mx_BytesPerLine] + call [MoveFunction] ; Draw column + inc [ReadPlane] ; Next read plane + rol [WritePlane], 1 ; Next write plane + adc [PixelOffset], 0 ; Update video offset if needed + mov dx, WORD PTR WidthStep[0] + mov ax, WORD PTR WidthStep[2] + add [ImageLo], dx + adc WORD PTR Image[0], ax ; Next image column + dec [NewWidth] + jnz @@Loop ; Repeat for all columns + +@@Exit: + xor ax, ax + .pop ds, si, es, di + .leave ARG_SIZE + +;----------------------------------------------------------- +; +; Move functions, on entry: +; AH = additional raster op info (e.g. transparent color) +; BX = 0, +; CX = pixel count, +; DX = mx_BytesPerLine. +; +subMove PROC NEAR +@@Loop: mov al, ds:[si] + mov es:[di], al + add di, dx + dec cx + jz @@Exit + add si, WORD PTR HeightStep[2] + add bx, WORD PTR HeightStep[0] + jnc @@Loop + add si, [Width] + jmp @@Loop +@@Exit: ret +subMove ENDP +; +subAnd PROC NEAR +@@Loop: mov al, ds:[si] + and es:[di], al + add di, dx + dec cx + jz @@Exit + add si, WORD PTR HeightStep[2] + add bx, WORD PTR HeightStep[0] + jnc @@Loop + add si, [Width] + jmp @@Loop +@@Exit: ret +subAnd ENDP +; +subOr PROC NEAR +@@Loop: mov al, ds:[si] + or es:[di], al + add di, dx + dec cx + jz @@Exit + add si, WORD PTR HeightStep[2] + add bx, WORD PTR HeightStep[0] + jnc @@Loop + add si, [Width] + jmp @@Loop +@@Exit: ret +subOr ENDP +; +subXor PROC NEAR +@@Loop: mov al, ds:[si] + xor es:[di], al + add di, dx + dec cx + jz @@Exit + add si, WORD PTR HeightStep[2] + add bx, WORD PTR HeightStep[0] + jnc @@Loop + add si, [Width] + jmp @@Loop +@@Exit: ret +subXor ENDP +; +subTrans PROC NEAR +@@Loop: mov al, ds:[si] + cmp al, ah + je @@Skip + mov es:[di], al +@@Skip: + add di, dx + dec cx + jz @@Exit + add si, WORD PTR HeightStep[2] + add bx, WORD PTR HeightStep[0] + jnc @@Loop + add si, [Width] + jmp @@Loop +@@Exit: ret +subTrans ENDP +; +subAdd PROC NEAR +@@Loop: mov al, ds:[si] + add es:[di], al + add di, dx + dec cx + jz @@Exit + add si, WORD PTR HeightStep[2] + add bx, WORD PTR HeightStep[0] + jnc @@Loop + add si, [Width] + jmp @@Loop +@@Exit: ret +subAdd ENDP + +mxStretchImage ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxsl.asm b/16/x/mxsl.asm new file mode 100755 index 00000000..d7908855 --- /dev/null +++ b/16/x/mxsl.asm @@ -0,0 +1,62 @@ +;----------------------------------------------------------- +; +; MXLN.ASM - Start line function +; Copyright (c) 1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +NOWARN RES +INCLUDE MODEX.DEF + +PUBLIC mxStartLine + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +EXTRN mx_BytesPerLine : WORD + +;----------------------------------------------------------- +; +; Changes the video start address to the specified line. +; +; Input: +; Line = new start line +; Output: +; none +; +mxStartLine PROC FAR + ARG Line:WORD = ARG_SIZE + .enter 0 + ASSUME ds:NOTHING + + mov ax, [Line] ; Get video offset + mul [mx_BytesPerLine] + xchg ax, bx ; Copy it into BX + +; Wait display + mov dx, STATUS +@@1: in al, dx + test al, 08h + jnz @@1 + +; Set starting address + mov dx, CRTC + mov al, 0Ch ; Linear Starting Address high + mov ah, bh + cli + out dx, ax + mov al, 0Dh ; Linear Starting Address low + mov ah, bl + out dx, ax + sti + +; Wait retrace + mov dx, STATUS +@@2: in al,dx + test al, 08h + jz @@2 + + xor ax, ax + .leave ARG_SIZE +MX_TEXT ENDS +END diff --git a/16/x/mxsm.asm b/16/x/mxsm.asm new file mode 100755 index 00000000..183fba1e --- /dev/null +++ b/16/x/mxsm.asm @@ -0,0 +1,508 @@ +;----------------------------------------------------------- +; +; MXSM.ASM - Set/change mode functions +; Copyright (c) 1993,1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +INCLUDE MODEX.DEF + +PUBLIC mxChangeMode +PUBLIC mxGetAspect +PUBLIC mxGetScreenSize +PUBLIC mxSetMode + +PUBLIC mx_ScreenWidth +PUBLIC mx_ScreenHeight +PUBLIC mx_BytesPerLine + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +EXTRN mxSetSysClipRegion : FAR + +EXTRN mx_VideoSegment : WORD +EXTRN mx_CodeSegment : WORD + +mx_ScreenWidth DW ? ; Current screen width +mx_ScreenHeight DW ? +mx_AspectX DW ? ; Aspect ratio for current mode +mx_AspectY DW ? +mx_BytesPerLine DW 0 ; Bytes per line + +; +; Tables for setting video modes, sources: +; - MODEX.ASM, Matt Pritchard +; - Dr. Dobb's Journal, Michael Abrash +; - Fractint VIDEO.ASM module +; +TBL_SingleLine LABEL WORD ; CRTC + DW 04009h ; Cell height: 1 scan line + DW 00014h ; Double word mode off + DW 0E317h ; Byte mode on + DW 0 +TBL_DoubleLine LABEL WORD ; CRTC + DW 04109h ; Cell height: 2 scan lines + DW 00014h + DW 0E317h + DW 0 +TBL_Width320 LABEL WORD ; CRTC + DW 05F00h ; Horizontal total + DW 04F01h ; Horizontal displayed + DW 05002h ; Start horizontal blanking + DW 08203h ; End horizontal blanking + DW 05404h ; Start horizontal sync + DW 08005h ; End horizontal sync + DW 02813h ; Row address + DW 0 +TBL_Width360 LABEL WORD ; CRTC + DW 06B00h ; Horizontal total + DW 05901h ; Horizontal displayed + DW 05A02h ; Start horizontal blanking + DW 08E03h ; End horizontal blanking + DW 05E04h ; Start horizontal sync + DW 08A05h ; End horizontal sync + DW 02D13h ; Row address + DW 0 +TBL_Height175 LABEL WORD ; CRTC + DW 0BF06h ; Vertical total + DW 01F07h ; Overflow + DW 08310h ; Start vertical sync + DW 08511h ; End vertical sync + DW 05D12h ; Vertical displayed + DW 06315h ; Start vertical blanking + DW 0BA16h ; End vertical blanking + DW 0 +TBL_Height200 LABEL WORD ; CRTC + DW 0BF06h ; Vertical total + DW 01F07h ; Overflow + DW 09C10h ; Start vertical sync + DW 08E11h ; End vertical sync + DW 08F12h ; Vertical displayed + DW 09615h ; Start vertical blanking + DW 0B916h ; End vertical blanking + DW 0 +TBL_Height240 LABEL WORD ; CRTC + DW 00D06h ; Vertical total + DW 03E07h ; Overflow + DW 0EA10h ; Start vertical sync + DW 08C11h ; End vertical sync + DW 0DF12h ; Vertical displayed + DW 0E715h ; Start vertical blanking + DW 00616h ; End vertical blanking + DW 0 +TBL_Tweak400x600: + DW 07400h + DW 06301h + DW 06402h + DW 09703h + DW 06804h + DW 09505h + DW 08606h + DW 0F007h + DW 06009h + DW 0310Fh + DW 05B10h + DW 08D11h + DW 05712h + DW 03213h + DW 00014h + DW 06015h + DW 08016h + DW 0E317h + DW 0 + +TBL_320x200: + DB 63h ; 400 scan lines, 25 MHz clock + DW 6, 5 ; Aspect: 6/5 = 1.2:1 + DW 320, 200 ; Size + DW TBL_Width320, TBL_Height200, TBL_DoubleLine, 0 + DW 819 ; Max height +TBL_320x240: + DB 0E3h ; 400 scan lines, 25 MHz clock + DW 1, 1 ; Aspect: 1/1 = 1:1 + DW 320, 240 ; Size + DW TBL_Width320, TBL_Height240, TBL_DoubleLine, 0 + DW 819 ; Max height +TBL_320x400: + DB 63h ; 480 scan lines, 25 MHz clock + DW 6, 10 ; Aspect: 6/10 = 0.6:1 + DW 320, 400 ; Size + DW TBL_Width320, TBL_Height200, TBL_SingleLine, 0 + DW 819 ; Max height +TBL_320x480: + DB 0E3h ; 480 scan lines, 25 MHz clock + DW 1, 2 ; Aspect: 1/2 = 0.5:1 + DW 320, 480 ; Size + DW TBL_Width320, TBL_Height240, TBL_SingleLine, 0 + DW 819 ; Max height +TBL_360x200: + DB 067h ; 400 scan lines, 28 MHz clock + DW 27, 20 ; Aspect: 27/20 = 1.35:1 + DW 360, 200 ; Size + DW TBL_Width360, TBL_Height200, TBL_DoubleLine, 0 + DW 728 ; Max height +TBL_360x240: + DB 0E7h ; 480 scan lines, 28 MHz clock + DW 9, 8 ; Aspect: 9/8 = 1.125:1 + DW 360, 240 ; Size + DW TBL_Width360, TBL_Height240, TBL_DoubleLine, 0 + DW 728 ; Max height +TBL_360x400: + DB 067h ; 400 scan lines, 28 MHz clock + DW 27, 40 ; Aspect: 27/40 = 0.675:1 + DW 360, 400 ; Size + DW TBL_Width360, TBL_Height200, TBL_SingleLine, 0 + DW 728 ; Max height +TBL_360x480: + DB 0E7h ; 480 scan lines, 28 MHz clock + DW 9, 16 ; Aspect: 9/16 = 0.5625:1 + DW 360, 480 ; Size + DW TBL_Width360, TBL_Height240, TBL_SingleLine, 0 + DW 728 ; Max height +TBL_320x175: + DB 0A3h + DW 0, 0 ; Aspect: + DW 320, 175 + DW TBL_Width320, TBL_Height175, TBL_DoubleLine, 0 + DW 819 +TBL_320x350: + DB 0A3h + DW 0, 0 ; Aspect: + DW 320, 175 + DW TBL_Width320, TBL_Height175, TBL_SingleLine, 0 + DW 819 +TBL_360x175: + DB 0A7h + DW 0, 0 ; Aspect: + DW 360, 480 ; Size + DW TBL_Width360, TBL_Height175, TBL_DoubleLine, 0 + DW 728 ; Max height +TBL_360x350: + DB 0A7h + DW 0, 0 ; Aspect: + DW 360, 480 ; Size + DW TBL_Width360, TBL_Height175, TBL_SingleLine, 0 + DW 728 ; Max height +TBL_400x600: + DB 0E7h ; 28 MHz clock + DW 1, 2 ; Aspect: 1/2 = 0.5:1 + DW 400, 600 ; Size + DW TBL_Tweak400x600, 0 + DW 655 ; Max height + +TBL_Mode LABEL WORD + DW TBL_320x175 + DW TBL_320x200 + DW TBL_320x240 + DW TBL_320x350 + DW TBL_320x400 + DW TBL_320x480 + DW TBL_360x175 + DW TBL_360x200 + DW TBL_360x240 + DW TBL_360x350 + DW TBL_360x400 + DW TBL_360x480 + DW TBL_400x600 + +MAXVMODE EQU ($-OFFSET TBL_Mode) / 2 + +;----------------------------------------------------------- +; +; Enables 80x25 color text mode +; +subText PROC NEAR + ASSUME ds:MX_TEXT + mov ax, 0003h + int 10h ; Call BIOS set mode + + mov [mx_ScreenHeight], 0 + mov [mx_BytesPerLine], 0 + ret +subText ENDP + +;----------------------------------------------------------- +; +; Enables the selected graphics mode. +; +; Input: +; Mode = mode to select (MX_???x???) +; Output: +; none +; +mxSetMode PROC FAR + ARG Mode:WORD = ARG_SIZE + ASSUME ds:NOTHING + .enter 0 + .push ds, si, es, di + +; Set DS to code segment alias + mov ds, [mx_CodeSegment] + ASSUME ds:MX_TEXT + + mov si, [Mode] + cmp si, MAXVMODE ; Is it a valid mode? + ja @@Exit ; No, exit + test si, si ; Text mode? + jnz @@Set ; No, handle it + + call subText ; Back to text mode + jmp @@Exit ; Exit now + +; Set video mode +@@Set: + dec si ; Skip text mode + shl si, 1 + mov si, TBL_Mode[si] + cld + +; Use BIOS to set 320x200x256 linear mode + push si ; Save SI + mov ax, 0013h + int 10h ; Use BIOS to set 320x200 linear mode + pop si ; Restore SI + + mov dx, TS + mov ax, 0604h + out dx, ax ; Disable chain-4 mode + mov ax, 0100h + out dx, ax ; Reset + mov dx, MISC + lodsb + out dx, al ; New timing/size + mov dx, TS + mov ax, 0300h + out dx, ax ; Restart sequencer + +; Unlock CRTC registers 0-7 + mov dx, CRTC + mov al, 11h + out dx, al ; Vertical sync end register + inc dx + in al, dx + and al, 7Fh ; Clear write protect bit + out dx, al + + lodsw ; Get X aspect + mov [mx_AspectX], ax + lodsw ; Get Y aspect + mov [mx_AspectY], ax + lodsw ; Get screen width + mov [mx_ScreenWidth], ax + shr ax, 1 + shr ax, 1 ; Divide by four to get bytes per line + mov [mx_BytesPerLine], ax + lodsw ; Get screen height + mov [mx_ScreenHeight], ax + +; Set CRTC registers + mov bx, si + mov dx, CRTC +@@TableLoop: + mov si, ds:[bx] ; DS:SI -> table of CRTC registers + inc bx + inc bx ; DS:BX -> offset of next table + test si, si ; Last table? + jz @@EndLoop ; Yes, exit loop +@@Loop: + lodsw ; Get CRTC register index and value + test ax, ax ; End of table? + jz @@TableLoop ; Yes, go to next table + out dx, ax ; Set register AL to value AH + jmp @@Loop ; Get next register/value +@@EndLoop: + +; Set virtual screen and system clip region + push [mx_ScreenWidth] + push WORD PTR ds:[bx] + call mxSetSysClipRegion + +; Clear video memory + mov dx, TS + mov ax, 0F02h + out dx, ax ; Enable all planes + mov es, [mx_VideoSegment] + xor di, di + mov cx, 8000h + xor ax, ax + rep stosw + +@@Done: +; Lock CRTC registers 0-7 (some cards need this) + mov dx, CRTC + mov al, 11h + out dx, al ; Vertical sync end register + inc dx + in al, dx + or al, 80h ; Set write protect bit + out dx, al + +@@Exit: + xor ax, ax + mov ax, [mx_ScreenWidth] + .pop ds, si, es, di + .leave ARG_SIZE +mxSetMode ENDP + +;----------------------------------------------------------- +; +; Changes from the current mode the selected graphics mode. +; +; Input: +; Mode = mode to select (MX_???x???) +; Output: +; none +; Notes: +; this function assumes that mxSetMode and mxSetVirtualScreen +; have been called first. View size is rearranged to match the +; specified mode, but video memory is not cleared. +; Differences from mxSetMode: +; - video BIOS is not called to initialize graphics; +; - row address register is not modified; +; - video memory is not cleared; +; - mx_BytesPerLine is not modified; +; - system clip region is not modified. +; +mxChangeMode PROC FAR + ARG Mode:WORD = ARG_SIZE + ASSUME ds:NOTHING + .enter 0 + .push ds, si, es, di + +; Set DS to code segment alias + mov ds, [mx_CodeSegment] + ASSUME ds:MX_TEXT + + mov si, [Mode] + cmp si, MAXVMODE ; Is it a valid mode? + ja @@Exit ; No, exit + test si, si ; Text mode? + jz @@Exit ; Yes, exit + + dec si ; Skip text mode + shl si, 1 + mov si, TBL_Mode[si] + cld + + mov dx, TS + mov ax, 0604h + out dx, ax ; Disable chain-4 mode + mov ax, 0100h + out dx, ax ; Reset + mov dx, MISC + lodsb + out dx, al ; New timing/size + mov dx, TS + mov ax, 0300h + out dx, ax ; Restart sequencer + +; Unlock CRTC registers 0-7 + mov dx, CRTC + mov al, 11h + out dx, al ; Vertical sync end register + inc dx + in al, dx + and al, 7Fh ; Clear write protect bit + out dx, al + + lodsw ; Get X aspect + mov [mx_AspectX], ax + lodsw ; Get Y aspect + mov [mx_AspectY], ax + lodsw ; Get screen width + mov [mx_ScreenWidth], ax + lodsw ; Get screen height + mov [mx_ScreenHeight], ax + +; Set CRTC registers + mov bx, si + mov dx, CRTC +@@TableLoop: + mov si, ds:[bx] ; DS:SI -> table of CRTC registers + inc bx + inc bx ; DS:BX -> offset of next table + test si, si ; Last table? + jz @@EndLoop ; Yes, exit loop +@@Loop: + lodsw ; Get CRTC register index and value + test ax, ax ; End of table? + jz @@TableLoop ; Yes, go to next table + cmp al, 13h ; Row address register? + je @@Loop ; Yes, ignore it + out dx, ax ; Set register AL to value AH + jmp @@Loop ; Get next register/value +@@EndLoop: + +; Lock CRTC registers 0-7 (some cards need this) + mov dx, CRTC + mov al, 11h + out dx, al ; Vertical sync end register + inc dx + in al, dx + or al, 80h ; Set write protect bit + out dx, al + +@@Exit: + xor ax, ax + mov ax, [mx_ScreenWidth] + .pop ds, si, es, di + .leave ARG_SIZE +mxChangeMode ENDP + +;----------------------------------------------------------- +; +; Returns the aspect ratio for the current mode. +; +; Input: +; AspectX = pointer to aspect X +; AspectY = pointer to aspect Y +; +; A rectangle of width AspectX and height AspectY looks like a square. +; +mxGetAspect PROC FAR + ARG AspectY:DWORD, \ + AspectX:DWORD = ARG_SIZE + .enter 0 + .push ds, si + ASSUME ds:NOTHING + + lds si, [AspectX] + mov ax, [mx_AspectX] + mov ds:[si], ax + lds si, [AspectY] + mov ax, [mx_AspectY] + mov ds:[si], ax + + .pop ds, si + .leave ARG_SIZE +mxGetAspect ENDP + +;----------------------------------------------------------- +; +; Returns the current screen size. +; +; Input: +; Width = pointer to screen width +; Height = pointer to screen height +; +mxGetScreenSize PROC FAR + ARG SizeY:DWORD, \ + SizeX:DWORD = ARG_SIZE + .enter 0 + .push ds, si + ASSUME ds:NOTHING + + lds si, [SizeX] + mov ax, [mx_ScreenWidth] + mov ds:[si], ax + lds si, [SizeY] + mov ax, [mx_ScreenHeight] + mov ds:[si], ax + + .pop ds, si + .leave ARG_SIZE +mxGetScreenSize ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxsp.asm b/16/x/mxsp.asm new file mode 100755 index 00000000..1d08e711 --- /dev/null +++ b/16/x/mxsp.asm @@ -0,0 +1,57 @@ +;----------------------------------------------------------- +; +; MXSP.ASM - Set palette function +; Copyright (c) 1993,1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +INCLUDE MODEX.DEF + +PUBLIC mxSetPalette + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +;----------------------------------------------------------- +; +; Updates the VGA palette. +; +; Input: +; Buffer = pointer to palette data (R,G,B) +; Start = index of first color to set +; Count = number of color to set +; Output: +; none +; +mxSetPalette PROC FAR + ARG Count:WORD, \ + Start:WORD, \ + Buffer:DWORD = ARG_SIZE + ASSUME ds:NOTHING + .enter 0 + .push ds, si + + lds si, [Buffer] + mov cx, [Count] + mov ax, [Start] + mov dx, 3C8h ; PEL write address register + out dx, al + inc dx + cld + cli ; Disable interrupts +@@Loop: + lodsb + out dx, al ; Red + lodsb + out dx, al ; Green + lodsb + out dx, al ; Blue + loop @@Loop ; Loop until done + sti ; Enable interrupts + + .pop ds, si + .leave ARG_SIZE +mxSetPalette ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxss.asm b/16/x/mxss.asm new file mode 100755 index 00000000..97df7366 --- /dev/null +++ b/16/x/mxss.asm @@ -0,0 +1,72 @@ +;----------------------------------------------------------- +; +; MXSS.ASM - Split screen function +; Copyright (c) 1993,1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +INCLUDE MODEX.DEF + +PUBLIC mxSplitScreen + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +;----------------------------------------------------------- +; +; Splits the screen. +; +; Input: +; Line = scan line at which screen has to be splitted +; Output: +; none +; +mxSplitScreen PROC FAR + ARG Line:WORD = ARG_SIZE + ASSUME ds:NOTHING + .enter 0 + +; Modify the line compare value: bits 0-7 are in the Line Compare +; register (CRTC #18), bit 8 is in the Overflow Low register (CRTC #7) +; and bit 9 is in the Maximum Row Address register (CRTC #9) + mov ax, [Line] + shl ax, 1 ; Adjust line for mode "X" + mov bh, ah + mov bl, ah + and bx, 0201h + mov cl, 4 + shl bx, cl + shl bh, 1 + mov dx, CRTC +; Write bits 0-7 to line compare register + mov ah, al + mov al, 18h + out dx, ax +; Write bit 8 to overflow register + mov al, 07h + out dx, al + inc dx + in al, dx + dec dx + mov ah, al + and ah, 11101111b + or ah, bl + mov al, 07h + out dx, ax +; Write bit 9 to maximum row address register + mov al, 09h + out dx, al + inc dx + in al, dx + dec dx + mov ah, al + and ah, 10111111b + or ah, bh + mov al, 09h + out dx, ax + + .leave ARG_SIZE +mxSplitScreen ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxtl.asm b/16/x/mxtl.asm new file mode 100755 index 00000000..69900c88 --- /dev/null +++ b/16/x/mxtl.asm @@ -0,0 +1,169 @@ +;----------------------------------------------------------- +; +; MXTL.ASM - Put tile +; Copyright (c) 1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +NOWARN RES +INCLUDE MODEX.DEF + +PUBLIC mxPutTile +PUBLIC mxTransPutTile + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +EXTRN mx_VideoSegment : WORD +EXTRN mx_BytesPerLine : WORD + +;----------------------------------------------------------- +; +; Copies a "mode-x" tile from memory to screen. +; +; Input: +; Image = pointer to tile +; X, Y = coordinates of destination +; Width = width of image in pixels (Width and 3 = 0) +; Height = height of image in pixels +; Output: +; none +; Note: +; no clipping is performed on tiles! +; +mxPutTile PROC FAR + ARG Height:WORD, \ + Width:WORD, \ + Y:WORD, \ + X:WORD, \ + Image:DWORD = ARG_SIZE + ASSUME ds:NOTHING + .enter 0 + .push ds, si, es, di + + mov ax, [Y] ; Get pixel address + mul [mx_BytesPerLine] + mov di, [X] + .shr di, 2 + add di, ax + mov es, [mx_VideoSegment] + + lds si, [Image] ; Get tile address + .shr [Width], 2 ; Number of bytes per plane + mov cl, BYTE PTR [X] + and cl, 3 + mov ah, 11h ; AH = plane mask + shl ah, cl ; Align mask to first plane + + mov [Y], 4 ; Number of planes + mov bx, [mx_BytesPerLine] + sub bx, [Width] ; Extra bytes per line +@@Loop: + mov al, 02h + mov dx, TS + out dx, ax ; Set write plane + mov [X], di ; Save video offset + mov dx, [Height] +@@Loop2: + mov cx, [Width] ; Number of bytes to move + + shr cx, 1 ; Move line + rep movsw + rcl cx, 1 + rep movsb + + add di, bx ; Move video offset to next line + dec dx ; Done all lines? + jnz @@Loop2 ; No, continue + mov di, [X] ; Restore video offset + rol ah, 1 ; Next plane + adc di, 0 ; Bump video offset if needed + dec [Y] ; Any plane left? + jnz @@Loop ; Yes, keep looping + + xor ax, ax + .pop ds, si, es, di + .leave ARG_SIZE +mxPutTile ENDP + +;----------------------------------------------------------- +; +; Copies a "mode-x" tile from memory to screen. +; Skips over color 0. +; +; Input: +; Image = pointer to tile +; X, Y = coordinates of destination +; Width = width of image in pixels (Width and 3 = 0) +; Height = height of image in pixels +; Output: +; none +; Note: +; no clipping is performed on tiles! +; +mxTransPutTile PROC FAR + ARG Height:WORD, \ + Width:WORD, \ + Y:WORD, \ + X:WORD, \ + Image:DWORD = ARG_SIZE + ASSUME ds:NOTHING + .enter 0 + .push ds, si, es, di + + mov ax, [Y] ; Get pixel address + mul [mx_BytesPerLine] + mov di, [X] + .shr di, 2 + add di, ax + mov es, [mx_VideoSegment] + + lds si, [Image] ; Get tile address + .shr [Width], 2 ; Number of bytes per plane + mov cl, BYTE PTR [X] + and cl, 3 + mov ah, 11h ; AH = plane mask + shl ah, cl ; Align mask to first plane + + mov [Y], 4 ; Number of planes + mov bx, [mx_BytesPerLine] + sub bx, [Width] ; Extra bytes per line +@@Loop: + mov al, 02h + mov dx, TS + out dx, ax ; Set write plane + mov [X], di ; Save video offset + mov dx, [Height] +@@Loop2: + mov cx, [Width] ; Number of bytes to move + +; Move one line + jcxz @@MoveLineDone +@@MoveLineLoop: + mov al, ds:[si] + test al, al + jz @@MoveLineNext + mov es:[di], al +@@MoveLineNext: + inc si + inc di + dec cx + jnz @@MoveLineLoop +@@MoveLineDone: + + add di, bx ; Move video offset to next line + dec dx ; Done all lines? + jnz @@Loop2 ; No, continue + mov di, [X] ; Restore video offset + rol ah, 1 ; Next plane + adc di, 0 ; Bump video offset if needed + dec [Y] ; Any plane left? + jnz @@Loop ; Yes, keep looping + + xor ax, ax + .pop ds, si, es, di + .leave ARG_SIZE +mxTransPutTile ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxvs.asm b/16/x/mxvs.asm new file mode 100755 index 00000000..992eabab --- /dev/null +++ b/16/x/mxvs.asm @@ -0,0 +1,110 @@ +;----------------------------------------------------------- +; +; MXVS.ASM - Set/get virtual screen +; Copyright (c) 1993,1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +NOWARN RES +INCLUDE MODEX.DEF + +PUBLIC mxSetVirtualScreen +PUBLIC mxGetVirtualScreen + +EXTRN mxRowAddress : FAR +EXTRN mxSetSysClipRegion : FAR + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +EXTRN mx_BytesPerLine : WORD +EXTRN mx_CodeSegment : WORD + +mx_VirtualWidth DW ? ; Virtual screen size +mx_VirtualHeight DW ? + +;----------------------------------------------------------- +; +; Sets the virtual screen. +; +; Input: +; Width = virtual screen width +; Height = virtual screen height +; Output: +; 0 on success, else invalid parameters +; +mxSetVirtualScreen PROC FAR + ARG Height:WORD, \ + Width:WORD = ARG_SIZE + ASSUME ds:NOTHING + .enter 0 + .push ds + +; Set DS to code segment + mov ds, [mx_CodeSegment] + ASSUME ds:MX_TEXT + + mov ax, 1 ; Assume an error + cmp [Width], 320 ; Check width + jb @@Exit + push ax ; Save return code + mov dx, 0004h + xor ax, ax ; DX:AX = 256K + div [Width] ; Max height in AX + cmp [Height], ax + pop ax ; Restore return code + ja @@Exit ; Exit if bad heigth + + mov ax, [Width] + and ax, 0FFF8h ; Align to byte + mov [mx_VirtualWidth], ax + shr ax, 1 + shr ax, 1 + mov [mx_BytesPerLine], ax + shr ax, 1 + push ax + call mxRowAddress ; Set row address + mov ax, [Height] + mov [mx_VirtualHeight], ax + + push [Width] + push [Height] + call mxSetSysClipRegion + xor ax, ax + +@@Exit: + .pop ds + .leave ARG_SIZE +mxSetVirtualScreen ENDP + +;----------------------------------------------------------- +; +; Returns the current virtual screen size. +; +; Input: +; Width = pointer to virtual screen width +; Height = pointer to virtual screen height +; Output: +; none +; +mxGetVirtualScreen PROC FAR + ARG Height:DWORD, \ + Width:DWORD = ARG_SIZE + ASSUME ds:NOTHING + .enter 0 + .push ds, si + + mov ax, [mx_VirtualWidth] + lds si, [Width] + mov ds:[si], ax + mov ax, [mx_VirtualHeight] + lds si, [Height] + mov ds:[si], ax + + xor ax, ax + .pop ds, si + .leave ARG_SIZE +mxGetVirtualScreen ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxwd.asm b/16/x/mxwd.asm new file mode 100755 index 00000000..de55208f --- /dev/null +++ b/16/x/mxwd.asm @@ -0,0 +1,28 @@ +;----------------------------------------------------------- +; +; MXWD.ASM - Wait display function +; Copyright (c) 1993,1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +INCLUDE MODEX.DEF + +PUBLIC mxWaitDisplay + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +;----------------------------------------------------------- +; +; Waits for display start. +; +mxWaitDisplay PROC FAR + mov dx, STATUS +@@1: in al, dx + test al, 08h + jnz @@1 + ret +mxWaitDisplay ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxwm.asm b/16/x/mxwm.asm new file mode 100755 index 00000000..06158859 --- /dev/null +++ b/16/x/mxwm.asm @@ -0,0 +1,39 @@ +;----------------------------------------------------------- +; +; MXWM.ASM - Set write mode function +; Copyright (c) 1993,1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +INCLUDE MODEX.DEF + +PUBLIC mxWriteMode + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +;----------------------------------------------------------- +; +; Sets the write mode. +; +; Input: +; Mode = write mode (0,1,2,3) +; Output: +; none +; +mxWriteMode PROC FAR + ARG Mode:BYTE:2 = ARG_SIZE + .enter 0 + + mov dx, GDC + mov ah, [Mode] + and ah, 00000011b + or ah, 01000000b + mov al, 05h + out dx, ax + + .leave ARG_SIZE +mxWriteMode ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxwp.asm b/16/x/mxwp.asm new file mode 100755 index 00000000..19ca99d0 --- /dev/null +++ b/16/x/mxwp.asm @@ -0,0 +1,62 @@ +;----------------------------------------------------------- +; +; MXWP.ASM - Set write/read plane functions +; Copyright (c) 1993,1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +INCLUDE MODEX.DEF + +PUBLIC mxWritePlane +PUBLIC mxReadPlane + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +;----------------------------------------------------------- +; +; Sets the write plane(s). +; +; Input: +; Plane = write plane(s) to set (bit 0 enables plane 0, +; bit 1 enables plane 1 and so on, different planes +; may be selected at the same time) +; Output: +; none +; +mxWritePlane PROC FAR + ARG Plane:BYTE:2 = ARG_SIZE + .enter 0 + + mov ah, [Plane] + and ah, 00001111b ; Mask off unused bits + mov al, 02h + mov dx, TS + out dx, ax + + .leave ARG_SIZE +mxWritePlane ENDP + +;----------------------------------------------------------- +; +; Sets the read plane. +; +; Input: +; Plane = read plane to set (0,1,2,3) +; Output: +; none +; +mxReadPlane PROC FAR + ARG Plane:BYTE:2 = ARG_SIZE + ASSUME ds:NOTHING + .enter 0 + mov al, 04h + mov ah, [Plane] + and ah, 0000011b ; Mask off unused bits + mov dx, GDC + out dx, ax + .leave ARG_SIZE +mxReadPlane ENDP + +MX_TEXT ENDS +END diff --git a/16/x/mxwr.asm b/16/x/mxwr.asm new file mode 100755 index 00000000..bd29fe59 --- /dev/null +++ b/16/x/mxwr.asm @@ -0,0 +1,28 @@ +;----------------------------------------------------------- +; +; MXWR.ASM - Wait vertical retrace function +; Copyright (c) 1993,1994 by Alessandro Scotti +; +;----------------------------------------------------------- +WARN PRO +INCLUDE MODEX.DEF + +PUBLIC mxWaitRetrace + +MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING + +;----------------------------------------------------------- +; +; Waits for vertical retrace start. +; +mxWaitRetrace PROC FAR + mov dx, STATUS +@@1: in al,dx + test al, 08h + jz @@1 + ret +mxWaitRetrace ENDP + +MX_TEXT ENDS +END diff --git a/bakapi.exe b/bakapi.exe index 2665e03a..f4b011b4 100755 Binary files a/bakapi.exe and b/bakapi.exe differ diff --git a/exmmtest.exe b/exmmtest.exe index 68cd10b2..4a5e0d20 100755 Binary files a/exmmtest.exe and b/exmmtest.exe differ diff --git a/makefile b/makefile index dd3c816e..2b458453 100755 --- a/makefile +++ b/makefile @@ -91,8 +91,8 @@ all: $(EXEC) comp 16.exe: 16.$(OBJ) mapread.$(OBJ) jsmn.$(OBJ) $(16LIBOBJS) gfx.lib wcl $(FLAGS) $(16FLAGS) 16.$(OBJ) mapread.$(OBJ) jsmn.$(OBJ) $(16LIBOBJS) gfx.lib -fm=16.map -bakapi.exe: bakapi.$(OBJ) $(16LIBOBJS) gfx.lib c_utils.$(OBJ) modex.$(OBJ) - wcl $(FLAGS) $(BAKAPIFLAGS) bakapi.$(OBJ) $(16LIBOBJS) gfx.lib c_utils.$(OBJ) modex.$(OBJ) -fm=bakapi.map +bakapi.exe: bakapi.$(OBJ) $(16LIBOBJS) gfx.lib modex.lib + wcl $(FLAGS) $(BAKAPIFLAGS) bakapi.$(OBJ) $(16LIBOBJS) gfx.lib modex.lib -fm=bakapi.map # #Test Executables! # @@ -387,7 +387,10 @@ modex.$(OBJ): $(MODEXLIB_)modex.asm clean: .symbolic @$(REMOVECOMMAND) $(EXEC) @$(REMOVECOMMAND) *.$(OBJ) - @$(REMOVECOMMAND) *.lib + @$(REMOVECOMMAND) 16.lib + @$(REMOVECOMMAND) gfx.lib + @$(REMOVECOMMAND) doslib.lib + @$(REMOVECOMMAND) vgmsnd.lib @wlib -n 16.lib @wlib -n gfx.lib @wlib -n doslib.lib diff --git a/planrpcx.exe b/planrpcx.exe index 7babadd3..865a95c4 100755 Binary files a/planrpcx.exe and b/planrpcx.exe differ diff --git a/scroll.exe b/scroll.exe index 95ddffb4..11bedbfa 100755 Binary files a/scroll.exe and b/scroll.exe differ diff --git a/src/bakapi.c b/src/bakapi.c index 5022f0da..1f7cd159 100755 --- a/src/bakapi.c +++ b/src/bakapi.c @@ -53,8 +53,8 @@ main(int argc, char *argvar[]) /* setup camera and screen~ */ gvar.video.page[0] = modexDefaultPage(&gvar.video.page[0]); - gvar.video.page[0].width += (TILEWH*2); - gvar.video.page[0].height += (TILEWH*2); + //gvar.video.page[0].width += (TILEWH*2); + //gvar.video.page[0].height += (TILEWH*2); textInit(); //modexPalUpdate(bmp.palette); //____ diff --git a/src/lib/bakapee.c b/src/lib/bakapee.c index 1e94aea0..09125984 100755 --- a/src/lib/bakapee.c +++ b/src/lib/bakapee.c @@ -68,6 +68,7 @@ void dingpp(page_t *page, bakapee_t *pee) { #ifdef TILE //fill_block(pee->xx, pee->yy, pee->xx+TILEWH, pee->yy+TILEWH, pee->coor); + //mxFillBox(pee->xx, pee->yy, TILEWH, TILEWH, pee->coor, OP_SET); modexClearRegion(page, pee->xx, pee->yy, TILEWH, TILEWH, pee->coor); #else modexputPixel(page, pee->xx, pee->yy, pee->coor); diff --git a/src/lib/bakapee.h b/src/lib/bakapee.h index d1596109..5f46f256 100755 --- a/src/lib/bakapee.h +++ b/src/lib/bakapee.h @@ -25,7 +25,8 @@ #include "src/lib/16_head.h" #include "src/lib/modex16.h" -#include "src/lib/modex/modex.h" +//#include "src/lib/modex/modex.h" +#include "16/x/modex.h" #define TILEWH 16 #define QUADWH TILEWH/2 diff --git a/test.exe b/test.exe index 61d44b65..5f1f4b9b 100755 Binary files a/test.exe and b/test.exe differ