Trench demo in VGA
Still stuggling away....
I've been trying to get the trench demo to run in vga. I think I have most of it done - my monitor does display something! I commented out most of the graphics and just have it set the tile colours, but that ends up showing the tiles as a mishmash of colours with random looking noise in then. I'm probably just missing one little thing that'd make it all work and I'm hoping someone can spot it.
graphics.spin and vga.spin have not been modified in any way (one file at a time is quite enough for me!)
I've been trying to get the trench demo to run in vga. I think I have most of it done - my monitor does display something! I commented out most of the graphics and just have it set the tile colours, but that ends up showing the tiles as a mishmash of colours with random looking noise in then. I'm probably just missing one little thing that'd make it all work and I'm hoping someone can spot it.
graphics.spin and vga.spin have not been modified in any way (one file at a time is quite enough for me!)
' //////////////////////////////////////////////////////////////////////
' Color rotation demo, creates 3D trench effect
' AUTHOR: Andre' LaMothe
' LAST MODIFIED: 5.15.06
' VERSION 1.0
' 256x192, 4 colors, bitmapped, quadrant I, mapped to screen, (0,0) at
' lower bottom left
' Use the gamepad up/down to speed up/slow down the color rotation
' //////////////////////////////////////////////////////////////////////
'///////////////////////////////////////////////////////////////////////
' CONSTANTS SECTION ////////////////////////////////////////////////////
'///////////////////////////////////////////////////////////////////////
CON
_clkmode = xtal2 + pll8x ' enable external clock and pll times 4
_xinfreq = 10_000_000 + 0000 ' set frequency to 10 MHZ plus some error
_stack = ($3000 + $3000 + 64) >> 2 ' accomodate display memory and stack
' graphics driver and screen constants
PARAMCOUNT = 21
'OFFSCREEN_BUFFER = $2000 ' offscreen buffer, unused in this template
ONSCREEN_BUFFER = $3000 ' onscreen buffer ** Originally $5000 but [url=mailto:320x240@2bpp]320x240@2bpp[/url] is 19,200 bytes $4B00
' size of graphics tile map $7FFF - $4B00 = $34FF so $5000 wouldn't be good
X_TILES = 20
Y_TILES = 15
SCREEN_WIDTH = 320
SCREEN_HEIGHT = 240
' color constant's to make setting colors for parallax graphics setup easier
COL_Black = %0000_0010
COL_DarkGrey = %0000_0011
COL_Grey = %0000_0100
COL_LightGrey = %0000_0101
COL_BrightGrey = %0000_0110
COL_White = %0000_0111
COL_PowerBlue = %0000_1_100
COL_Blue = %0001_1_100
COL_SkyBlue = %0010_1_100
COL_AquaMarine = %0011_1_100
COL_LightGreen = %0100_1_100
COL_Green = %0101_1_100
COL_GreenYellow = %0110_1_100
COL_Yellow = %0111_1_100
COL_Gold = %1000_1_100
COL_Orange = %1001_1_100
COL_Red = %1010_1_100
COL_VioletRed = %1011_1_100
COL_Pink = %1100_1_100
COL_Magenta = %1101_1_100
COL_Violet = %1110_1_100
COL_Purple = %1111_1_100
' each palette entry is a LONG arranged like so: color 3 | color 2 | color 1 | color 0
COLOR_0 = (COL_Black << 0)
COLOR_1 = (COL_Red << 8)
COLOR_2 = (COL_Red << 16)
COLOR_3 = (COL_White << 24)
' button ids/bit masks
' NES bit encodings general for state bits
NES_RIGHT = %00000001
NES_LEFT = %00000010
NES_DOWN = %00000100
NES_UP = %00001000
NES_START = %00010000
NES_SELECT = %00100000
NES_B = %01000000
NES_A = %10000000
'//////////////////////////////////////////////////////////////////////////////
' VARIABLES SECTION ///////////////////////////////////////////////////////////
'//////////////////////////////////////////////////////////////////////////////
VAR
long vga_status 'status: off/visible/invisible read-only (21 contiguous longs)
long vga_enable 'enable: off/on write-only
long vga_pins 'pins: byte(2),topbit(3) write-only
long vga_mode 'mode: interlace,hpol,vpol write-only
long vga_videobase 'video base @word write-only
long vga_colorbase 'color base @long write-only
long vga_hc 'horizontal cells write-only
long vga_vc 'vertical cells write-only
long vga_hx 'horizontal cell expansion write-only
long vga_vx 'vertical cell expansion write-only
long vga_ho 'horizontal offset write-only
long vga_vo 'vertical offset write-only
long vga_hd 'horizontal display pixels write-only
long vga_hf 'horizontal front-porch pixels write-only
long vga_hs 'horizontal sync pixels write-only
long vga_hb 'horizontal back-porch pixels write-only
long vga_vd 'vertical display lines write-only
long vga_vf 'vertical front-porch lines write-only
long vga_vs 'vertical sync lines write-only
long vga_vb 'vertical back-porch lines write-only
long vga_rate 'pixel rate (Hz) write-only
long vga_screen 'pointer to screen (words) write-only
long vga_colors 'pointer to colors (longs)
{ word screen[noparse][[/noparse]screensize]
long col, row, color
long boxcolor,ptr
long stack[noparse][[/noparse]100]
}
{VAR
long vga_status '0/1/2 = off/visible/invisible read-only
long vga_enable '0/? = off/on write-only
long vga_pins '%ppmmm = pins write-only
long vga_mode '%ccinp = chroma,interlace,ntsc/pal,swap write-only
long vga_screen 'pointer to screen (words) write-only
long vga_colors 'pointer to colors (longs) write-only
long vga_hc 'horizontal cells write-only
long vga_vc 'vertical cells write-only
long vga_hx 'horizontal cell expansion write-only
long vga_vx 'vertical cell expansion write-only
long vga_ho 'horizontal offset write-only
long vga_vo 'vertical offset write-only
long vga_broadcast 'broadcast frequency (Hz) write-only
long vga_auralcog 'aural fm cog write-only
}
word screen[noparse][[/noparse]X_TILES * Y_TILES] ' storage for screen tile map
long colors[noparse][[/noparse]64] ' color look up table
long palette[noparse][[/noparse]4] ' used to shadows colors
' nes gamepad vars
long nes_buttons
'//////////////////////////////////////////////////////////////////////////////
' OBJECT DECLARATION SECTION //////////////////////////////////////////////////
'//////////////////////////////////////////////////////////////////////////////
OBJ
'tv : "vga_drv_010.spin" ' instantiate a tv object
vga : "vga.spin"
gr : "graphics_drv_010.spin" ' instantiate a graphics object
gpad : "gamepad_drv_001.spin" ' gamepad driver
'//////////////////////////////////////////////////////////////////////////////
' PUBLIC FUNCTIONS ////////////////////////////////////////////////////////////
'//////////////////////////////////////////////////////////////////////////////
PUB start | i, dx, dy, x, y, y_inv ,t, temp_color, rotation_rate
'start vga
longmove(@vga_status, @vgaparams, paramcount)
vga_screen := @screen
vga_colors := @colors
vga.start(@vga_status)
'init colors, each tile has same 4 colors
palette[noparse][[/noparse]0] := COL_Black
palette[noparse][[/noparse]1] := COL_Violet
palette[noparse][[/noparse]2] := COL_Violet
palette[noparse][[/noparse]3] := COL_White
repeat i from 0 to 63
colors[noparse][[/noparse]i] := (palette[noparse][[/noparse]3] << 24) | (palette[noparse][[/noparse]2] << 16) | (palette[noparse][[/noparse]1] << 8) | (palette[noparse][[/noparse]0] << 0)
'init tile screen
repeat dx from 0 to vga_hc - 1
repeat dy from 0 to vga_vc - 1
screen[noparse][[/noparse]dy * vga_hc + dx] := onscreen_buffer >> 6 + dy + dx * vga_vc + ((dy & $3F) << 10)
{
UNUSED CODE DELETED FOR CLARITY
}
' END RENDERING SECTION ///////////////////////////////////////////////////
' END MAIN GAME LOOP REPEAT BLOCK ///////////////////////////////////////////
'//////////////////////////////////////////////////////////////////////////////
' DATA SECTION ////////////////////////////////////////////////////////////////
'//////////////////////////////////////////////////////////////////////////////
DAT
' VGA PARAMS FOR DRIVER
vgaparams long 0 'status: off/visible/invisible read-only (21 contiguous longs)
long 1 'enable: off/on write-only
long %010_111 'pins: byte(2),topbit(3) write-only
long %0011 'mode: interlace,hpol,vpol write-only
long 0 'video base @word write-only
long 0 'color base @long write-only
long X_TILES 'horizontal cells write-only
long Y_TILES 'vertical cells write-only
long 1 'horizontal cell expansion write-only
long 1 'vertical cell expansion write-only
long 0 'horizontal offset write-only
long 0 'vertical offset write-only
long 320 'horizontal display pixels write-only
long 21 'horizontal front-porch pixels write-only
long 40 'horizontal sync pixels write-only
long 41 'horizontal back-porch pixels write-only
long 240 'vertical display lines write-only
long 1 'vertical front-porch lines write-only
long 1 'vertical sync lines write-only
long 19 'vertical back-porch lines write-only
long 15_000_000 'pixel rate (Hz) write-only

Comments
Looking at the original trench demo, I cannot for the life of me see where the address of the video memory is passed to the vga driver, yet it somehow knows exactly where to look and same thing with the colors array.
What am I missing? I know its going to be something simple. It always is.
PS - Yes, I tried putting the screen and colors into the vgaparams list. Of course, the pointers are in variables and variables are verboten in a constants listing.
·
I got it... It was something simple of course.
In the DAT section the screen and colors pointers were zero because those are assigned in runtime and the dat is constant. The vga variables list also has vga_screen and vga_colors, but those are type declarations so no value.
At the beginning of pub start, longmove is used to move the DAT data into the vga variables THEN the screen and colors pointers are assigned to the vga_screen and vga_colors. Of course it hit me after I gave up and went to do something completely different.
I now have the trench demo working in VGA! The colors need adjusting though, not nearly the same on a VGA monitor.
Cheers,
S
Did a bit of a search ... found it here ...
www.parallax.com/dl/sw/HYDRA_Demos_Source_Teaser.zip
loads of stuff in this zip file - you will find it under the 'hydra trench archive'
Quattro
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Necessity is the mother of invention'
Post Edited (QuattroRS4) : 7/4/2007 4:29:13 AM GMT