home *** CD-ROM | disk | FTP | other *** search
- // Copyright (c) 1993 NeXT Computer, Inc. All rights reserved.
- //
- // s3.vp - S3 928 video driver P-code.
- //
- // HISTORY
- // 29 July 1993 Derek B Clegg
- // Created.
- //
- //
-
- #define S3_XCRTC_COUNT 48
-
- #define S3_CHIP_ID_INDEX 0x30 // Chip ID/REV register.
- #define S3_CHIP_ID_MASK 0xF0
- #define S3_CHIP_ID_805 0xA0
- #define S3_CHIP_ID_928 0x90
- #define S3_REVISION_MASK 0x0F
-
- #define S3_LAW_CTL 0x58 // Linear address window control
- // register.
- #define S3_LAW_SIZE_MASK 0x03
- #define S3_LAW_SIZE_64K 0x00
- #define S3_LAW_SIZE_1M 0x01
- #define S3_LAW_SIZE_2M 0x02
- #define S3_LAW_SIZE_4M 0x03
-
- #define RS_00 0x3C8
- #define RS_01 0x3C9
- #define RS_02 0x3C6
- #define RS_03 0x3C7
-
- #define DAC_Unknown -1
- #define DAC_Bt484 0x40
- #define DAC_Bt485 0x80
- #define DAC_Bt485A 0x20
-
- .text
-
- // Initialize the mode.
-
- getDisplayInfo:
- debug // Turn on debugging info.
- load @modeWidth, s0
- load @modeHeight, s1
- load @modeTotalWidth, s2
- load @modeRowBytes, s3
- load @modeRefresh, s4
- load @modeBitsPerPixel, s5
- load @modeColorSpace, s6
- load @modeFlags, s7
- return
-
- getPixelEncoding:
- debug // Turn on debugging info.
- load pixelEncoding, r0
- load @r0, s0
- add 1, r0, r0
- load @r0, s1
- add 1, r0, r0
- load @r0, s2
- add 1, r0, r0
- load @r0, s3
- return
-
- setDefaultMode:
- debug // Turn on debugging info.
- return
-
- // verifyConfiguration
- // Arguments: none.
- // Returns: s0: Zero if selected mode is valid, nonzero otherwise.
- //
- verifyConfiguration:
- debug // Turn on debugging info.
- call unlockRegisters
-
- // Get the adapter type; make sure that this is an S3 928.
-
- inx VGA_CRTC_INDEX, S3_CHIP_ID_INDEX, r0
- and r0, S3_CHIP_ID_MASK, r0
- cmp r0, S3_CHIP_ID_928
- bne invalidConfiguration
-
- // We only support the Bt484, Bt485, or Bt485A dacs.
- call determineDACtype
- load @dacType, r0
- cmp r0, DAC_Unknown
- beq invalidConfiguration
-
- // Get the memory configuration.
-
- inx VGA_CRTC_INDEX, 0x36, r0
- and r0, 0xC0, r0
- cmp r0, 0x00 // 4 Megabytes
- beq _4M
- cmp r0, 0x40 // 3 Megabytes
- beq _3M
- cmp r0, 0x80 // 2 Megabytes
- beq _2M
- load 1, r0 // 1 Megabyte
- br checkMemoryConfiguration
- _4M: load 4, r0
- br checkMemoryConfiguration
- _3M: load 3, r0
- br checkMemoryConfiguration
- _2M: load 2, r0
-
- checkMemoryConfiguration:
- load @modeMemorySize, r1
- cmp r0, r1
- blt invalidConfiguration
- load 0, s0
- call lockRegisters
- return
-
- invalidConfiguration:
- load -1, s0
- call lockRegisters
- return
-
- initializeMode:
- debug
-
- // Load the sequencer.
- load seqxParameters, r0
- load 0, r1
- 0: load @r0, r2
- outx VGA_SEQ_INDEX, r1, r2
- add 1, r0, r0
- add 1, r1, r1
- cmp r1, VGA_SEQ_COUNT
- blt 0b
-
- // Turn off the screen.
- inx VGA_SEQ_INDEX, 0x01, r0
- or 0x20, r0, r0
- outx VGA_SEQ_INDEX, 0x01, r0
-
- // Unlock the S3 extended registers.
- call unlockRegisters
-
- // Unlock the CRTC registers.
- call unlockCRTC
-
- // Set up the CRTC parameters.
- load crtcParameters, r0
- load 0, r1
- 0: load @r0, r2
- outx VGA_CRTC_INDEX, r1, r2
- add 1, r0, r0
- add 1, r1, r1
- cmp r1, VGA_CRTC_COUNT
- blt 0b
-
- // Initialize the address flip-flop for the attribute controller.
- inb VGA_INPUT_STATUS_1, r0
-
- // Set up the attribute controller registers.
- load attrParameters, r0
- load 0, r1
- 0: load @r0, r2
- outb VGA_ATTR_INDEX, r1
- outb VGA_ATTR_DATA, r2
- add 1, r0, r0
- add 1, r1, r1
- cmp r1, VGA_ATTR_COUNT
- blt 0b
-
- // Start the sequencer.
-
- outx VGA_SEQ_INDEX, 0x00, 0x03
-
- // Set up the graphics controller registers.
-
- load grfxParameters, r0
- load 0, r1
- 0: load @r0, r2
- outx VGA_GRFX_INDEX, r1, r2
- add 1, r0, r0
- add 1, r1, r1
- cmp r1, VGA_GRFX_COUNT
- blt 0b
-
- // Set the miscellaneous output register (0x3C2).
-
- load @miscOutputRegister, r0
- outb VGA_MISC_OUTPUT, r0
-
- // Reset the address flip-flop for the attribute controller and
- // enable the palette.
-
- inb VGA_INPUT_STATUS_1, r0
- outb VGA_ATTR_INDEX, 0x20
-
- // Set up the extended CRTC registers.
-
- load 0, r1
- load xCrtcParameters, r0
- 0: load @r0, r2
- add r0, 1, r0
- load @r0, r3
- add r0, 1, r0
- outx VGA_CRTC_INDEX, r2, r3
- add 2, r1, r1
- cmp r1, S3_XCRTC_COUNT
- blt 0b
-
- // Set the mode control register.
- load @modeControl, r0
- outx VGA_CRTC_INDEX, 0x42, r0
-
- // Unlock access to the enhanced commands registers.
-
- inx VGA_CRTC_INDEX, 0x40, r0
- or 0x01, r0, r0
- outx VGA_CRTC_INDEX, 0x40, r0
-
- // Set the advanced function control register (0x4AE8).
-
- load @advFunctionControl, r0
- outw 0x4AE8, r0
-
- // Lock the register set.
-
- inx VGA_CRTC_INDEX, 0x40, r0
- and ~0x01, r0, r0
- outx VGA_CRTC_INDEX, 0x40, r0
-
- // Program the DAC.
- call programDAC
-
- // Lock the registers.
- call lockRegisters
-
- // Enable the screen.
- inx VGA_SEQ_INDEX, 0x01, r0
- and ~0x20, r0, r0
- outx VGA_SEQ_INDEX, 0x01, r0
-
- return
-
- .data
- lawSize:
- .word -1 // 0 megabytes
- .word S3_LAW_SIZE_1M // 1 megabyte
- .word S3_LAW_SIZE_2M // 2 megabytes
- .word S3_LAW_SIZE_4M // 3 megabytes
- .word S3_LAW_SIZE_4M // 4 megabytes
-
- .text
- //
- // videoRamAddress in s0.
- //
- enableLinearFrameBuffer:
- debug
- call unlockRegisters
-
- // Tell the chip where the frame buffer is mapped in.
- lsr s0, 16, r1
- and r1, 0xFF, r1
- outx VGA_CRTC_INDEX, 0x5A, r1
-
- lsr s0, 24, r1
- and r1, 0xFF, r1
- outx VGA_CRTC_INDEX, 0x59, r1
-
- // Set the linear address window size.
- load @modeMemorySize, r0
- load lawSize, r1
- add r0, r1, r0
- load @r0, r0
-
- inx VGA_CRTC_INDEX, 0x58, r1
- and r1, 0xFC, r1
- or r1, r0, r1
- outx VGA_CRTC_INDEX, 0x58, r1
-
- // Disable 8514 register access.
-
- call disable_8514
-
- // Turn off mmio.
- inx VGA_CRTC_INDEX, 0x53, r0
- and r0, 0xEF, r0
- outx VGA_CRTC_INDEX, 0x53, r0
-
- // Enable fast write buffer (write posting into FIFO).
- inx VGA_CRTC_INDEX, 0x40, r0
- or r0, 0x08, r0
- outx VGA_CRTC_INDEX, 0x40, r0
-
- // Enable read-ahead cache.
- inx VGA_CRTC_INDEX, 0x58, r0
- or r0, 0x04, r0
- outx VGA_CRTC_INDEX, 0x58, r0
-
- // Max out the read-ahead cache.
- inx VGA_CRTC_INDEX, 0x54, r0
- or r0, 0x07, r0
- outx VGA_CRTC_INDEX, 0x54, r0
-
- // Turn on the linear address window.
- inx VGA_CRTC_INDEX, 0x58, r0
- or r0, 0x10, r0
- outx VGA_CRTC_INDEX, 0x58, r0
-
- call lockRegisters
-
- return
-
- .data
- vgaXCrtcParameters:
- .word 0x31, 0x85, 0x32, 0x10, 0x33, 0x00, 0x34, 0x00, 0x35, 0x00
- .word 0x3A, 0x85, 0x3B, 0x5A, 0x3C, 0x10, 0x40, 0x58, 0x43, 0x00
- .word 0x50, 0x00, 0x51, 0x00, 0x53, 0x00, 0x54, 0x38, 0x56, 0x00
- .word 0x57, 0x00, 0x5C, 0x31, 0x5D, 0x00, 0x5E, 0x00, 0x5F, 0x00
- .word 0x60, 0x07, 0x61, 0x80, 0x62, 0xA1, 0x63, 0xA1
-
- .text
- resetVGA:
- // Disable the linear framebuffer.
-
- call unlockRegisters
-
- // Disable 8514 register access.
- call disable_8514
-
- // Turn off the linear address window.
- inx VGA_CRTC_INDEX, 0x58, r0
- and ~0x10, r0, r0
- outx VGA_CRTC_INDEX, 0x58, r0
-
- // Turn off the display.
- inx VGA_SEQ_INDEX, 0x01, r0
- or 0x20, r0, r0
- outx VGA_SEQ_INDEX, 0x01, r0
-
- // Unlock the CRTC registers.
- call unlockCRTC
-
- // Unlock access to the enhanced commands registers.
- inx VGA_CRTC_INDEX, 0x40, r0
- or 0x01, r0, r0
- outx VGA_CRTC_INDEX, 0x40, r0
-
- // Set VGA mode.
- outw 0x4AE8, 0x02
-
- // Set the DAC for VGA mode.
- call resetDAC
-
- // Set up the extended CRTC registers.
- load vgaXCrtcParameters, r0
- load 0, r1
- 0: load @r0, r2
- add r0, 1, r0
- load @r0, r3
- add r0, 1, r0
- outx VGA_CRTC_INDEX, r2, r3
- add 2, r1, r1
- cmp r1, S3_XCRTC_COUNT
- blt 0b
-
- // Set mode 0x03.
- call vgaSetMode3
-
- call lockRegisters
-
- return
-
- setCommandRegister0:
- outx VGA_CRTC_INDEX, 0x55, 0x01
- outb RS_02, s0
- outx VGA_CRTC_INDEX, 0x55, 0x00
- return
-
- setCommandRegister1:
- outx VGA_CRTC_INDEX, 0x55, 0x02
- outb RS_00, s0
- outx VGA_CRTC_INDEX, 0x55, 0x00
- return
-
- setCommandRegister2:
- outx VGA_CRTC_INDEX, 0x55, 0x02
- outb RS_01, s0
- outx VGA_CRTC_INDEX, 0x55, 0x00
- return
-
- setCommandRegister3:
- // Don't set command register 3 if this is a Bt484.
- load @dacType, r0
- cmp r0, DAC_Bt484
- beq 1f
-
- outx VGA_CRTC_INDEX, 0x55, 0x01
- inb RS_02, r0 // Save command register 0.
- move r0, r7
- or r7, 0x80, r7
- outb RS_02, r7 // Set the high bit of command reg 0.
- outx VGA_CRTC_INDEX, 0x55, 0x00;
- inb RS_00, r1 // Save the address register.
- outb RS_00, 0x01
- outx VGA_CRTC_INDEX, 0x55, 0x02
- outb RS_02, s0
- outx VGA_CRTC_INDEX, 0x55, 0x01;
- outb RS_02, r0 // Restore command register 0.
- outx VGA_CRTC_INDEX, 0x55, 0x00;
- outb RS_00, r1 // Restore the address register.
- 1: return
-
- programDAC:
- load @commandRegister0, s0
- call setCommandRegister0
-
- load @commandRegister1, s0
- call setCommandRegister1
-
- load @commandRegister2, s0
- call setCommandRegister2
-
- load @commandRegister3, s0
- call setCommandRegister3
-
- load @crtc_0x45, r0
- outx VGA_CRTC_INDEX, 0x45, r0
-
- load @crtc_0x53, r0
- outx VGA_CRTC_INDEX, 0x53, r0
-
- load @crtc_0x55, r0
- outx VGA_CRTC_INDEX, 0x55, r0
-
- // Restore the PIXEL mask.
- outb RS_02, 0xFF
-
- // Set correct falling edge mode.
- inx VGA_CRTC_INDEX, 0x43, r0
- and r0, ~0x01, r0
- outx VGA_CRTC_INDEX, 0x43, r0
-
- return
-
- .data
- dacType: .word DAC_Unknown
-
- .text
- determineDACtype:
- // Save the value of command register 0.
- outx VGA_CRTC_INDEX, 0x55, 0x01
- inb RS_02, r0
-
- // Write a zero to bit 7 of command register 0.
- and r0, 0x7F, r1
- outb RS_02, r1
-
- // Read the status register.
- outx VGA_CRTC_INDEX, 0x55, 0x02
- inb RS_02, r1
- and r1, 0xF0, r1
- cmp r1, DAC_Bt484
- beq 1f
- cmp r1, DAC_Bt485
- beq 1f
- cmp r1, DAC_Bt485A
- beq 1f
- load DAC_Unknown, r1
- 1: store r1, @dacType
-
- move r0, s0
- call setCommandRegister0
-
- // Make sure that we are addressing RS(00xx).
- outx VGA_CRTC_INDEX, 0x55, 0x00
-
- return
-
- resetDAC:
- load 0x00, s0
- call setCommandRegister0
- load 0x00, s0
- call setCommandRegister1
- load 0x00, s0
- call setCommandRegister2
- load 0x00, s0
- call setCommandRegister3
-
- outx VGA_CRTC_INDEX, 0x45, 0x00
- outx VGA_CRTC_INDEX, 0x53, 0x00
- outx VGA_CRTC_INDEX, 0x55, 0x00
-
- // Restore the PIXEL mask.
- outb RS_02, 0xFF
-
- // Set correct falling edge mode.
- inx VGA_CRTC_INDEX, 0x43, r0
- and ~0x01, r0, r0
- outx VGA_CRTC_INDEX, 0x43, r0
-
- return
-
- // Stored as xrgb.
- .data
-
- transferTable:
- .space 256
-
- .text
-
- setTransferTable:
- debug
- outb RS_00, 0x00
- load 0, r0
- load transferTable, r1
- 0: load @r1, r2
- add 1, r1, r1
- lsr r2, 16, r3 // Red
- and r3, 0xFF, r3
- outb RS_01, r3
- lsr r2, 8, r3 // Green
- and r3, 0xFF, r3
- outb RS_01, r3
- and r2, 0xFF, r3 // Blue
- outb RS_01, r3
- add 1, r0, r0
- cmp r0, 256
- blt 0b
- return
-