'RJA: Trying to figure out why this works as ASM, but not as Spin2 '****************************** '* VGA 640 x 480 x 8bpp-lut * '****************************** CON 'RJA: new for real P2 - you can use different xdiv and xmul to set clock frequency: /10*125 -> 250 MHz _XTALFREQ = 20_000_000 ' crystal frequency _XDIV = 10 ' crystal divider to give 1MHz _XMUL = 125 ' crystal / div * mul _XDIVP = 1 ' crystal / div * mul /divp to give _CLKFREQ (1,2,4..30) _XOSC = %10 'OSC ' %00=OFF, %01=OSC, %10=15pF, %11=30pF _XSEL = %11 'XI+PLL ' %00=rcfast(20+MHz), %01=rcslow(~20KHz), %10=XI(5ms), %11=XI+PLL(10ms) _XPPPP = ((_XDIVP>>1) + 15) & $F ' 1->15, 2->0, 4->1, 6->2...30->14 _CLOCKFREQ = _XTALFREQ / _XDIV * _XMUL / _XDIVP ' internal clock frequency _SETFREQ = 1<<24 + (_XDIV-1)<<18 + (_XMUL-1)<<8 + _XPPPP<<4 + _XOSC<<2 ' %0000_000e_dddddd_mmmmmmmmmm_pppp_cc_00 ' setup oscillator _ENAFREQ = _SETFREQ + _XSEL ' %0000_000e_dddddd_mmmmmmmmmm_pppp_cc_ss ' enable oscillator CON intensity = 80 '0..128 fclk = _CLOCKFREQ 'RJA: Adjusted for real P2 '80_000_000.0 fpix = 25_000_000.0 fset = (fpix / fclk * 2.0) * float($4000_0000) vsync = 4 'vsync pin 'RJA: changed for real P2 PUB start(status)|usbcog usbcog := coginit(0,@origin, 0) + 1 repeat DAT org 0 origin ' ' ' Setup ' '+-------[ Set Xtal ]----------------------------------------------------------+ ' RJA: New for real P2 hubset #0 ' set 20MHz+ mode hubset ##_SETFREQ ' setup oscillator waitx ##20_000_000/100 ' ~10ms hubset ##_ENAFREQ ' enable oscillator '+-----------------------------------------------------------------------------+ rdfast #0,##@BitmapFile-$400+$436'##$1000-$400 'load .bmp palette into lut rep @.end,#$100 rflong y shl y,#8 wrlut y,x add x,#1 .end rdfast ##640*480/64,##@BitmapFile+$436'##$1000 'set rdfast to wrap on bitmap setxfrq ##round(fset) 'set transfer frequency to 25MHz 'the next 4 lines may be commented out to bypass level scaling setcy ##intensity << 24 'r set colorspace for rgb setci ##intensity << 16 'g setcq ##intensity << 08 'b setcmod #%01_0_000_0 'enable colorspace conversion 'RJA dacmodes changed for real P2 wrpin dacmode_s,#0 'enable dac modes in pins 0..3 wrpin dacmode_c,#1 wrpin dacmode_c,#2 wrpin dacmode_c,#3 setnib dira,#$f,#0 'RJA: New for real P2 ' ' ' Field loop ' field mov x,#33 'top blanks call #blank mov x,#480 'set visible lines line call #hsync 'do horizontal sync xcont m_rf,#0 'visible line djnz x,#line 'another line? mov x,#10 'bottom blanks call #blank drvnot #vsync 'sync on mov x,#2 'sync blanks call #blank drvnot #vsync 'sync off jmp #field 'loop ' ' ' Subroutines ' blank call #hsync 'blank lines xcont m_vi,#0 _ret_ djnz x,#blank hsync xcont m_bs,#0 'horizontal sync xcont m_sn,#1 _ret_ xcont m_bv,#0 ' ' ' Initialized data 'RJA: New dacmodes for real P2 dacmode_s long %0000_0000_000_1011000000000_01_00000_0 'hsync is 123-ohm, 3.3V dacmode_c long %0000_0000_000_1011100000000_01_00000_0 'R/G/B are 75-ohm, 2.0V m_bs long $CF000000+16 'before sync m_sn long $CF000000+96 'sync m_bv long $CF000000+48 'before visible m_vi long $CF000000+640 'visible m_rf long $7F000000+640 'visible rlong 8bpp lut x res 1 y res 1 ' ' ' Bitmap ' ' orgh $1000 - $436 'justify pixels at $1000, pallete at $1000-$400 orgh BitmapFile file "bitmap2.bmp"'combined1.bmp" 'bitmap2.bmp '640 x 480, 8pbb-lut