Here is some modex code I found

Discuss whatever you want here--both QB and non-QB related. Anything from the DEF INT command to the meaning of life!

Moderators: Pete, Mods

Post Reply
TRANERAECK
Coder
Posts: 29
Joined: Thu Mar 24, 2011 3:08 am

Here is some modex code I found

Post by TRANERAECK » Mon Apr 04, 2011 1:48 pm

I found this by Jason Plackey on a web site thought I'd share:

Code: Select all



DECLARE SUB ModeX () '
DECLARE SUB OutPort (PortAddr&, vh%, vl%) '
DECLARE SUB Standard () '
DECLARE SUB SetVOffset (Offset&) '
'
SCREEN 13: DEF SEG = &HA000: CALL ModeX'
'

FOR count% = 0 TO 63'
redval& = count%'
greenval& = 256 * count%'
blueval& = 65536 * count%'
rgbval& = blueval& + greenval& + redval&'
PALETTE count%, redval&'
PALETTE count% + 64, greenval& '
PALETTE count% + 128, blueval& '
PALETTE count% + 192, rgbval& '
NEXT count%'
'
FOR Offset& = 0 TO 15999'
rgbbase% = Offset& MOD 64'
POKE Offset&, rgbbase%'
POKE Offset& + 16000, rgbbase% + 64 '
POKE Offset& + 32000, rgbbase% + 128'
POKE Offset& + 48000, rgbbase% + 192'
NEXT Offset&'
'
Offset& = 0: OffsetInc% = 80: Frame% = 0'
'
DO'
Offset& = Offset& + OffsetInc%'
CALL SetVOffset(Offset&): WAIT &H3DA, 8'
Frame% = Frame% + 1'
IF Frame% = 99 THEN OffsetInc% = 81'
IF Frame% = 199 THEN OffsetInc% = 79'
IF Frame% = 299 THEN OffsetInc% = 80'
IF Frame% = 499 THEN OffsetInc% = -80'
IF Frame% = 599 THEN OffsetInc% = -79'
IF Frame% = 699 THEN OffsetInc% = -81'
IF Frame% = 799 THEN OffsetInc% = -80'
IF Frame% = 899 THEN '
CLS : PALETTE'
CALL SetVOffset(0): CALL Standard'
END'
END IF'
FOR delay% = 1 TO 10: NEXT delay%'
LOOP'

'
' Regarding the example code... Change the delay% value to
'accommodate your CPU's speed. The TIMER function is
'relatively inaccurate when dealing with fractions of a
'second, and I had insufficient space to include my own timer
'routine.
'
' If you have any questions, feel free to ask.
'Happy coding! Jason Plackey
'
'
'
SUB ModeX '
CALL OutPort(&H3C4, 6, 4): CLS '
CALL OutPort(&H3D4, 227, 23)'
CALL OutPort(&H3D4, 0, 20)'
CALL OutPort(&H3C4, 15, 2)'
END SUB'

'
SUB OutPort (PortAddr&, vh%, vl%) '
OUT PortAddr&, vl%: OUT PortAddr& + 1, vh%'
END SUB'

'
SUB SetVOffset (Offset&) '
V& = Offset&'
CALL OutPort(&H3D4, V& \ 256, 12)'
CALL OutPort(&H3D4, V& AND 255, 13)'
END SUB'

'
SUB Standard '
CALL OutPort(&H3C4, 14, 4)'
CALL OutPort(&H3D4, 163, &H17)'
CALL OutPort(&H3D4, 64, &H14)'
CALL OutPort(&H3C4, 15, &H2)'
END SUB'

Hope this helps with modex. :roll:

Anonymous

Post by Anonymous » Mon Apr 04, 2011 4:10 pm

I have also made modex routines, but they may not work on all systems. It works for me in dosbox

Code: Select all

DEFINT A-Z

DECLARE SUB modex ()
DECLARE SUB page (active, visual)
DECLARE SUB pixel (x, y, c)

modex
page 0, 0

COLOR 12

OUT &H3C4, &H2
OUT &H3C5, &HFF

FOR i! = 0 TO 2 * 3.1415926# STEP .01
   pixel 160 + COS(i!) * 100, 120 + SIN(i!) * 100, 50 + INT(i!)
NEXT

SLEEP
SYSTEM

SUB modex
   SCREEN 13
   OUT &H3C4, &H4: OUT &H3C5, &H6: OUT &H3C4, &H0
   OUT &H3C5, &H1: OUT &H3C2, &HE3: OUT &H3C4, &H0
   OUT &H3C5, &H3: OUT &H3D4, &H11: x = INP(&H3D5) AND &H7F
   OUT &H3D5, x: OUT &H3D4, &H6: OUT &H3D5, &HD
   OUT &H3D4, &H7: OUT &H3D5, &H3E: OUT &H3D4, &H9
   OUT &H3D5, &H41: OUT &H3D4, &H10: OUT &H3D5, &HEA
   OUT &H3D4, &H11: OUT &H3D5, &HAC: OUT &H3D4, &H12
   OUT &H3D5, &HDF: OUT &H3D4, &H14: OUT &H3D5, &H0
   OUT &H3D4, &H15: OUT &H3D5, &HE7: OUT &H3D4, &H16
   OUT &H3D5, &H6: OUT &H3D4, &H17: OUT &H3D5, &HE3
END SUB

SUB page (active, visual)
   OUT &H3D4, &HC
   OUT &H3D5, &H4B * visual
   OUT &H3D4, &HD
   OUT &H3D5, 0
   DEF SEG = &HA000 + &H4B0 * active
END SUB

SUB pixel (x, y, c)
   OUT &H3C4, &H2
   OUT &H3C5, 2 ^ (x AND 3)

   POKE x \ 4 + y * 80, c
END SUB

This is my demo using the hardware scrolling capabilities of modex

Code: Select all

DEFINT A-Z
DECLARE SUB modex ()
modex
OUT &H3C4, &H2
OUT &H3C5, &HFF
FOR i = 383 TO 550
   k& = (i - 383) * 320&
   DEF SEG = &HFFA6
   x = PEEK(14 + i)
   DEF SEG = &HA000
   FOR j = 0 TO 16
      d = ((x AND (2 ^ (16 - j))) <> 0) * -14
      POKE k& + j, d
      POKE k& + j + 79.99999999999998, d
      POKE k& + j + 160&, d
      POKE k& + j + 240&, d
   NEXT
NEXT
j = 1
i = 0
DO
  i = i + 80 * j
  j = j XOR 2 * ((i = 32000) XOR (i = 0))
  OUT &H3D4, &HC
  OUT &H3D5, i \ 256
  OUT &H3D4, &HD
  OUT &H3D5, i
  WAIT &H3DA, 8
  WAIT &H3DA, 8, 8
LOOP UNTIL INP(&H60) = 1
SYSTEM

DEFSNG A-Z
SUB modex
   SCREEN 13
   OUT &H3C4, &H4: OUT &H3C5, &H6: OUT &H3C4, &H0
   OUT &H3C5, &H1: OUT &H3C2, &HE3: OUT &H3C4, &H0
   OUT &H3C5, &H3: OUT &H3D4, &H11: x = INP(&H3D5) AND &H7F
   OUT &H3D5, x: OUT &H3D4, &H6: OUT &H3D5, &HD
   OUT &H3D4, &H7: OUT &H3D5, &H3E: OUT &H3D4, &H9
   OUT &H3D5, &H41: OUT &H3D4, &H10: OUT &H3D5, &HEA
   OUT &H3D4, &H11: OUT &H3D5, &HAC: OUT &H3D4, &H12
   OUT &H3D5, &HDF: OUT &H3D4, &H14: OUT &H3D5, &H0
   OUT &H3D4, &H15: OUT &H3D5, &HE7: OUT &H3D4, &H16
   OUT &H3D5, &H6: OUT &H3D4, &H17: OUT &H3D5, &HE3
END SUB

I have also made a MODEX bitmap loarder that utilises VGA hardware to quickly and smoothly pan the image on mouse click & drag.

Code: Select all

DEFINT A-Z
DECLARE SUB modex ()
DIM yy AS LONG

DIM a(10) AS LONG
a(0) = &H8BE58955
a(1) = &H33CD0C46
a(2) = &H890A768B
a(3) = &H8768B1C
a(4) = &H768B0C89
a(5) = &H5D148906
a(6) = &H8CA

DIM r AS STRING * 1, g AS STRING * 1, b AS STRING * 1
DIM s AS LONG

SCREEN 0
'PRINT "Enter filename of 8bit bmp less then 512x495 in size"
'LINE INPUT f$

modex

OUT &H3D4, &H13
OUT &H3D5, 64

DEF SEG = &HA000

f$ = "city7.bmp"
k = 1
OPEN f$ FOR BINARY AS #1

GET #1, 1, x
GET #1, 29, y
IF x <> &H4D42 AND y <> 8 THEN SYSTEM
GET #1, 19, x
GET #1, 23, y
'GET #1, 35, size
GET #1, 54, b
OUT &H3C8, 0
FOR i = 0 TO 255
   GET #1, , b
   GET #1, , g
   GET #1, , r
   OUT &H3C9, ASC(r) \ 4
   OUT &H3C9, ASC(g) \ 4
   OUT &H3C9, ASC(b) \ 4
   GET #1, , b
NEXT
IF x MOD 4 THEN z$ = SPACE$(4 - (x MOD 4))
OUT &H3C4, &H2
FOR i = 0 TO y - 1
   yy = (y - i - 1) * 128&
   FOR j = 0 TO x - 1
      GET #1, , b
      k = k * 2 MOD 15
      OUT &H3C5, k
      POKE j \ 4 + yy, ASC(b)
   NEXT
   GET #1, , z$
NEXT
CLOSE

x = 0
y = 0
DEF SEG = VARSEG(a(0))
CALL absolute(BYVAL 0, mb, mx, my, VARPTR(a(0)))
DO
   CALL absolute(BYVAL 3, mb, mx, my, VARPTR(a(0)))
   IF mb = 1 THEN
      ox = mx + x
      oy = my + y
      DO
         CALL absolute(BYVAL 3, mb, mx, my, VARPTR(a(0)))

         x = ox - mx
         y = oy - my

         IF x < 1 THEN x = 0
         IF y < 1 THEN y = 0
         IF x > 384 THEN x = 384
         IF y > 250 THEN y = 250

         s = y * 128& + x \ 8
         OUT &H3D4, &HC
         OUT &H3D5, s \ 256
         OUT &H3D4, &HD
         OUT &H3D5, s

         i = INP(&H3DA)
         OUT &H3C0, &H33
         OUT &H3C0, (x AND &HFFFE) MOD 8
      LOOP WHILE mb = 1
   END IF
LOOP UNTIL INP(&H60) = 1

OUT &H3D4, &H13
OUT &H3D5, 40
SCREEN 0

SYSTEM

SUB modex
SCREEN 13
OUT &H3C4, &H4: OUT &H3C5, &H6: OUT &H3C4, &H0
OUT &H3C5, &H1: OUT &H3C2, &HE3: OUT &H3C4, &H0
OUT &H3C5, &H3: OUT &H3D4, &H11: x = INP(&H3D5) AND &H7F
OUT &H3D5, x: OUT &H3D4, &H6: OUT &H3D5, &HD
OUT &H3D4, &H7: OUT &H3D5, &H3E: OUT &H3D4, &H9
OUT &H3D5, &H41: OUT &H3D4, &H10: OUT &H3D5, &HEA
OUT &H3D4, &H11: OUT &H3D5, &HAC: OUT &H3D4, &H12
OUT &H3D5, &HDF: OUT &H3D4, &H14: OUT &H3D5, &H0
OUT &H3D4, &H15: OUT &H3D5, &HE7: OUT &H3D4, &H16
OUT &H3D5, &H6: OUT &H3D4, &H17: OUT &H3D5, &HE3
END SUB

you can use any image that is of size, but this demo uses this sample image: http://qbasic.orgfree.com/city7.bmp

Post Reply