Advertisement
LBASIC

320X240.BAS

Jun 5th, 2023
582
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QBasic 5.49 KB | Source Code | 0 0
  1. 'From: DAVE SHEA                 Conference: QUIK_BAS -Qui (298)
  2. '      Digital Encounters * Kamloops BC Canada 250/374-6168 (1:353/710)
  3. '>>> Page 1 of 320X240.BAS begins here. TYPE:BAS
  4. 'Example of how to achieve ModeX in QuickBasic, from Douglas Lusher
  5.  DECLARE SUB XCLS (Page%)
  6.  DECLARE SUB ShowPage (Page%)
  7.  DECLARE SUB Set320x240mode ()
  8.  DECLARE SUB XPRINT (X%, Y%, Text$, Culler%, Page%)
  9.  DECLARE SUB PutPixel (X%, Y%, Culler%, Page%)
  10.  DEFINT A-Z
  11.  '$INCLUDE: 'QB.BI'
  12.  
  13.  DIM BitMask%(7)
  14.  FOR Bit% = 0 TO 7: BitMask%(Bit%) = 2 ^ Bit%: NEXT
  15.  Test$ = "The quick brown fox jumps over lazy dogs"
  16.  CALL XPRINT(0, 0, "", 0, 0)   'initialize the print routine
  17.  
  18.  CALL Set320x240mode: SLEEP 1
  19.  HMax% = 320: VMax% = 240: Pg% = 0
  20.  FOR X% = 0 TO HMax% - 1
  21.     CALL PutPixel(X%, 0, 2, Pg%)
  22.     CALL PutPixel(X%, VMax% - 1, 2, Pg%)
  23.  NEXT
  24.  FOR Y% = 0 TO VMax% - 1
  25.     CALL PutPixel(0, Y%, 2, P%)
  26.     CALL PutPixel(HMax% - 1, Y%, 2, Pg%)
  27.  NEXT
  28.  CALL XPRINT(0, 0, "This is 320x240x256 mode, 3 pages", 15, P%)
  29.  FOR Y% = 1 TO 14
  30.     CALL XPRINT(0, Y% * 16, Test$, Y%, Pg%)
  31.  NEXT
  32.  BEEP: a$ = INPUT$(1)
  33.  CALL XCLS(0)
  34.  CALL XPRINT(0, 0, "This is page 0", 1, 0)
  35.  CALL XPRINT(0, 64, "Press 0, 1, or 2 to see the pages", 1, 0)
  36.  CALL XPRINT(0, 80, "Press ESC to exit", 1, 0)
  37.  CALL XPRINT(0, 16, "This is page 1", 2, 1)
  38.  CALL XPRINT(0, 64, "Press 0, 1, or 2 to see the pages", 2, 1)
  39.  CALL XPRINT(0, 80, "Press ESC to exit", 2, 1)
  40.  CALL XPRINT(0, 32, "This is page 2", 4, 2)
  41.  CALL XPRINT(0, 64, "Press 0, 1, or 2 to see the pages", 4, 2)
  42.  CALL XPRINT(0, 80, "Press ESC to exit", 4, 2)
  43.  DO
  44.  a$ = INPUT$(1)
  45.  SELECT CASE a$
  46.     CASE "0": CALL ShowPage(0)
  47.     CASE "1": CALL ShowPage(1)
  48.     CASE "2": CALL ShowPage(2)
  49.     CASE CHR$(27): EXIT DO
  50.     CASE ELSE: BEEP
  51.  END SELECT
  52.  LOOP
  53.  SCREEN 13: SCREEN 0: WIDTH 80
  54.  END
  55.            
  56.  
  57.  SUB GetPixel (X%, Y%, Culler%, Page%)
  58.  SELECT CASE Page%
  59.     CASE 0: VidSegment% = &HA000
  60.     CASE 1: VidSegment% = &HA4F0
  61.     CASE 2: VidSegment% = &HA9E0
  62.     CASE ELSE: ERROR 5
  63.  END SELECT
  64.  OUT &H3CE, 4: OUT &H3CF, X% AND 3
  65.  DEF SEG = VidSegment%
  66.  Culler% = PEEK((Y% * 80) + (X% \ 4))
  67.  END SUB
  68.  
  69.  SUB PutPixel (X%, Y%, Culler%, Page%)
  70.  SHARED BitMask%()
  71.  SELECT CASE Page%
  72.     CASE 0: VidSegment% = &HA000
  73.     CASE 1: VidSegment% = &HA4F0
  74.     CASE 2: VidSegment% = &HA9E0
  75.     CASE ELSE: ERROR 5
  76.  END SELECT
  77.  OUT &H3C4, 2: OUT &H3C5, BitMask%(X% AND 3)
  78.  DEF SEG = VidSegment%
  79.  POKE (Y% * 80) + (X% \ 4), Culler%
  80.  END SUB
  81.  
  82.  SUB Set320x240mode
  83.  'begin with standard 320x200x256 mode
  84.  SCREEN 13
  85.  'disable "chain4" mode
  86.  OUT &H3C4, &H4: OUT &H3C5, &H6
  87.  'enable writes to all four planes
  88.  OUT &H3C4, &H2: OUT &H3C5, &HF
  89.  'clear video memory
  90.  CLS
  91.  'synchronous reset while switching clocks
  92.  OUT &H3C4, 0: OUT &H3C5, &H1
  93.  'select 25 Mhz dot clock and 60 hz scanning rate
  94.  OUT &H3C2, &HE3
  95.  'restart the sequencer
  96.  OUT &H3C4, 0: OUT &H3C5, &H3
  97.  'to reprogram the CRT controller,
  98.  'remove write protect from the registers
  99.  OUT &H3D4, &H11: OUT &H3D5, INP(&H3D5) AND &H7F
  100.  OUT &H3D4, &H6: OUT &H3D5, &HD     'total vertical pixels
  101.  OUT &H3D4, &H7: OUT &H3D5, &H3E    'overflow
  102.  OUT &H3D4, &H9: OUT &H3D5, &H41    'turn off double double-scan
  103.  OUT &H3D4, &H10: OUT &H3D5, &HEA   'vertical sync start
  104.  OUT &H3D4, &H11: OUT &H3D5, &HAC   'vertical sync end, reprotect_
  105. ' registers
  106.  OUT &H3D4, &H12: OUT &H3D5, &HDF   'vertical pixels displayed
  107.  OUT &H3D4, &H14: OUT &H3D5, 0      'turn off dword mode
  108.  OUT &H3D4, &H15: OUT &H3D5, &HE7   'vertical blank start
  109.  OUT &H3D4, &H16: OUT &H3D5, &H6    'vertical blank end
  110.  OUT &H3D4, &H17: OUT &H3D5, &HE3   'turn on byte mode
  111.  END SUB
  112.  
  113.  SUB ShowPage (Page%)
  114.  SELECT CASE Page%
  115.     CASE 0: OUT &H3D4, &HC: OUT &H3D5, 0
  116.     CASE 1: OUT &H3D4, &HC: OUT &H3D5, &H4F
  117.     CASE 2: OUT &H3D4, &HC: OUT &H3D5, &H9E
  118.     CASE ELSE: ERROR 5          'illegal function call
  119.  END SELECT
  120.  END SUB
  121.  
  122.  SUB XCLS (Page%)
  123.  SELECT CASE Page%
  124.     CASE 0: VidSegment% = &HA000
  125.     CASE 1: VidSegment% = &HA4F0
  126.     CASE 2: VidSegment% = &HA9E0
  127.     CASE ELSE: ERROR 5
  128.  END SELECT
  129.  OUT &H3C4, &H2: OUT &H3C5, &HF
  130.  DEF SEG = VidSegment%
  131.  FOR Address% = 0 TO 19199: POKE Address%, 0: NEXT
  132.  END SUB
  133.  
  134.  SUB XPRINT (X%, Y%, Text$, Culler%, Page%)
  135.  STATIC HiNibble%(), LoNibble%()
  136.  IF LEN(Text$) GOTO StartXPRINT
  137.  REDIM HiNibble%(255, 15), LoNibble%(255, 15)
  138.  REDIM BitMask%(15)
  139.  BitMask%(0) = 0:  BitMask%(1) = 8:   BitMask%(2) = 4
  140.  BitMask%(3) = 12: BitMask%(4) = 2:   BitMask%(5) = 10
  141.  BitMask%(6) = 6:  BitMask%(7) = 14:  BitMask%(8) = 1
  142.  BitMask%(9) = 9:  BitMask%(10) = 5:  BitMask%(11) = 13
  143.  BitMask%(12) = 3: BitMask%(13) = 11: BitMask%(14) = 7
  144.  BitMask%(15) = 15
  145.  DIM Regs AS RegTypeX
  146.  Regs.AX = &H1130
  147.  Regs.BX = &H600
  148.  CALL InterruptX(&H10, Regs, Regs)
  149.  CharSegment% = Regs.ES: CharOffset% = Regs.BP
  150.  DEF SEG = CharSegment%
  151.  FOR Char% = 0 TO 255
  152.     FOR Ln% = 0 TO 15
  153.       BitPattern% = PEEK(CharOffset%)
  154.       HiNibble%(Char%, Ln%) = BitMask%(BitPattern% \ 16)
  155.       LoNibble%(Char%, Ln%) = BitMask%(BitPattern% AND 15)
  156.       CharOffset% = CharOffset% + 1
  157.     NEXT
  158.  NEXT
  159.  ERASE BitMask%
  160.  
  161. StartXPRINT:
  162.  SELECT CASE Page%
  163.     CASE 0: VidSegment% = &HA000
  164.     CASE 1: VidSegment% = &HA4F0
  165.     CASE 2: VidSegment% = &HA9E0
  166.     CASE ELSE: ERROR 5
  167.  END SELECT
  168.  OUT &H3C4, 2
  169.  DEF SEG = VidSegment%
  170.  VidPtr% = (Y% * 80) + (X% \ 4)
  171.  FOR Ptr% = 1 TO LEN(Text$)
  172.     Char% = ASC(MID$(Text$, Ptr%, 1))
  173.     VidOffset% = VidPtr%
  174.     FOR Ln% = 0 TO 15
  175.       OUT &H3C5, HiNibble%(Char%, Ln%)
  176.       POKE VidOffset%, Culler%
  177.       OUT &H3C5, LoNibble%(Char%, Ln%)
  178.       POKE VidOffset% + 1, Culler%
  179.       VidOffset% = VidOffset% + 80
  180.     NEXT
  181.     VidPtr% = VidPtr% + 2
  182.  NEXT
  183.  END SUB
  184.  
  185.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement