"Define a representation of the fb_fix_screeninfo structure." CStruct subclass: #FixedScreenInfo declaration: #( (#id (#array #uChar 16)) (#smemStart #uLong) (#smemLen #uInt) (#type #uInt) (#typeAux #uInt) (#visual #uInt) (#xPanStep #uShort) (#yPanStep #uShort) (#yWrapStep #uShort) (#lineLength #uInt) (#mmioStart #uLong) (#mmioLen #uInt) (#accel #uInt) (#reserved (#array #uShort 3))) classVariableNames: '' poolDictionaries: '' category: 'FrameBuffer Support' ! "Define a representation of the fb_bitfield structure used by the fb_var_screeninfo structure." CStruct subclass: #FbBitField declaration: #( (#offset #uInt) (#length #uInt) (#msbRight #uInt)) classVariableNames: '' poolDictionaries: '' category: 'FrameBuffer Support' ! "Define a representation of the fb_var_screeninfo structure." CStruct subclass: #VariableScreenInfo declaration: #( (#xRes #uInt) (#yRes #uInt) (#xResVirtual #uInt) (#yResVirtual #uInt) (#xOffset #uInt) (#yOffset #uInt) (#bitsPerPixel #uInt) (#grayScale #uInt) (#red #FbBitField) (#green #FbBitField) (#blue #FbBitField) (#transp #FbBitField) (#nonStd #uInt) (#activate #uInt) (#height #uInt) (#width #uInt) (#accelFlags #uInt) (#pixClock #uInt) (#leftMargin #uInt) (#rightMargin #uInt) (#upperMargin #uInt) (#lowerMargin #uInt) (#hSyncLen #uInt) (#vSyncLen #uInt) (#sync #uInt) (#vMode #uInt) (#reserved (#array #uInt 6))) classVariableNames: '' poolDictionaries: '' category: 'FrameBuffer Support' ! "Declare Smalltalk access to the C functions." SystemDictionary defineCFunc: 'openFrameBuffer' withSelectorArgs: 'openFrameBuffer: aString' returning: #int args: #(#string) ! SystemDictionary defineCFunc: 'closeFrameBuffer' withSelectorArgs: 'closeFrameBuffer: anInteger' returning: #int args: #(#int) ! SystemDictionary defineCFunc: 'fixedScreenInfo' withSelectorArgs: 'fixedScreenInfoFor: anInteger into: aFixedScreenInfo' returning: #int args: #(#int #cObject) ! SystemDictionary defineCFunc: 'variableScreenInfo' withSelectorArgs: 'variableScreenInfoFor: anInteger into: aVariableScreenInfo' returning: #int args: #(#int #cObject) ! "Just for testing, add some global variables." Smalltalk at: #Pstring put: nil! Smalltalk at: #XRes put: nil! Smalltalk at: #YRes put: nil! Smalltalk at: #BitsPerPixel put: nil! Smalltalk at: #ScreenSize put: nil! Smalltalk at: #MyFB put: nil! Smalltalk at: #MyFixedInfo put: nil! Smalltalk at: #MyVariableInfo put: nil! Smalltalk at: #FBTypes put: nil! Smalltalk at: #FBVisuals put: nil! "Decode of the framebuffer type." FBTypes := #('packed pixels' 'non interleaved planes' 'interleaved planes' 'text/attributes' 'EGA/VGA planes')! "Decode of the framebuffer visual." FBVisuals := #('monochr 1=black 0=white' 'monochr 1=white 0=black' 'true colour' 'pseudo colour' 'direct colour' 'fixed pseudo colour')! "Initialise the values of the structures. This is required as the C functions will put their results here." MyFixedInfo := FixedScreenInfo new! MyVariableInfo := VariableScreenInfo new! "Call the functions and get the data." MyFB := Smalltalk openFrameBuffer: '/dev/fb0'! Smalltalk fixedScreenInfoFor: MyFB into: MyFixedInfo! Smalltalk variableScreenInfoFor: MyFB into: MyVariableInfo! Smalltalk closeFrameBuffer: MyFB! "Display the information obtained. Note that the id is a C array so subscripts start at 0." Transcript nextPutAll: 'ID: '! 0 to: 15 do: [ :i | (MyFixedInfo id at: i) >= $ and: [ (MyFixedInfo id at: i) <= $z and: [ Transcript nextPut: (MyFixedInfo id at: i) ] ] ]! Transcript nextPutAll: ', len: '; nextPutAll: MyFixedInfo smemLen value printString; cr; nextPutAll: 'Framebuffer type '; nextPutAll: MyFixedInfo type value printString; nextPutAll: ': '; nextPutAll: (FBTypes at: MyFixedInfo type value + 1 ifAbsent: [ 'unknown' ]); cr; nextPutAll: 'Framebuffer visual '; nextPutAll: MyFixedInfo visual value printString; nextPutAll: ': '; nextPutAll: (FBVisuals at: MyFixedInfo visual value + 1 ifAbsent: [ 'unknown' ]); cr; nextPutAll: 'line len: '; nextPutAll: MyFixedInfo lineLength value printString; nextPutAll: ', accel: '; nextPutAll: MyFixedInfo accel value printString; cr; nextPutAll: 'xres: '; nextPutAll: MyVariableInfo xRes value printString; nextPutAll: ', yres: '; nextPutAll: MyVariableInfo yRes value printString; nextPutAll: ', xoff: '; nextPutAll: MyVariableInfo xOffset value printString; nextPutAll: ', yoff: '; nextPutAll: MyVariableInfo yOffset value printString; cr; nextPutAll: 'bits per pixel: '; nextPutAll: MyVariableInfo bitsPerPixel value printString; cr; nextPutAll: ' Offset Length MSBR'; cr; nextPutAll: 'red '! Pstring := MyVariableInfo red offset value printString! 1 to: (7 - Pstring size) do: [ :i | Transcript nextPut: $ ]! Transcript nextPutAll: Pstring! Pstring := MyVariableInfo red length value printString! 1 to: (8 - Pstring size) do: [ :i | Transcript nextPut: $ ]! Transcript nextPutAll: Pstring; nextPutAll: ' '; nextPutAll: MyVariableInfo red msbRight value printString; cr; nextPutAll: 'green '! Pstring := MyVariableInfo green offset value printString! 1 to: (7 - Pstring size) do: [ :i | Transcript nextPut: $ ]! Transcript nextPutAll: Pstring! Pstring := MyVariableInfo green length value printString! 1 to: (8 - Pstring size) do: [ :i | Transcript nextPut: $ ]! Transcript nextPutAll: Pstring; nextPutAll: ' '; nextPutAll: MyVariableInfo green msbRight value printString; cr; nextPutAll: 'blue '! Pstring := MyVariableInfo blue offset value printString! 1 to: (7 - Pstring size) do: [ :i | Transcript nextPut: $ ]! Transcript nextPutAll: Pstring! Pstring := MyVariableInfo blue length value printString! 1 to: (8 - Pstring size) do: [ :i | Transcript nextPut: $ ]! Transcript nextPutAll: Pstring; nextPutAll: ' '; nextPutAll: MyVariableInfo blue msbRight value printString; cr; nextPutAll: 'transp '! Pstring := MyVariableInfo transp offset value printString! 1 to: (7 - Pstring size) do: [ :i | Transcript nextPut: $ ]! Transcript nextPutAll: Pstring! Pstring := MyVariableInfo transp length value printString! 1 to: (8 - Pstring size) do: [ :i | Transcript nextPut: $ ]! Transcript nextPutAll: Pstring; nextPutAll: ' '; nextPutAll: MyVariableInfo transp msbRight value printString; cr; nextPutAll: 'screen size: '! XRes := MyVariableInfo xRes value! YRes := MyVariableInfo yRes value! BitsPerPixel := MyVariableInfo bitsPerPixel value! ScreenSize := XRes * YRes * BitsPerPixel / 8! Transcript nextPutAll: ScreenSize printString; cr !