Shop OBEX P1 Docs P2 Docs Learn Events
Improved GEAR Emulator - Page 2 — Parallax Forums

Improved GEAR Emulator



  • yetiyeti Posts: 818
    edited 2018-11-04 06:22
    Can someone please drop some hints here how to build Gear using Mono on Linux (Debian/Devuan).
    Or add the hints to Gear's readme at GitHub?
  • You don't need to compile it. You can just run the binary (mono's binaries are arch independent)
    [red@apophenia:~/Downloads/gear]$ unzip  ../
    Archive:  ../
      inflating: Changes and corrections-ASB.txt
      inflating: Gear.exe
      inflating: licence.txt
      inflating: PinNoise.xml
      inflating: Plugins notes.txt
      inflating: readme.txt
      inflating: SerialIO.xml
      inflating: Stimulus.xml
      inflating: Television.xml
      inflating: test.stm
      inflating: vgamonitor.xml
    [red@apophenia:~/Downloads/gear]$ file Gear.exe
    Gear.exe: PE32 executable (GUI) Intel 80386 [b]Mono/.Net assembly[/b], for MS Windows
    [red@apophenia:~/Downloads/gear]$ mono Gear.exe
    Gtk not found (missing LD_LIBRARY_PATH to, using built-in colorscheme

    1075 x 663 - 24K
    s.png 23.7K
  • (Unless you're actually wanting to compile it of course - if that's the case let us know and we'll see if we can work it out together)
  • So, you know I had to right? ;-)
    [nix-shell:~/s]$ git clone  # Downloads the latest from github
    [nix-shell:~/s]$ cd gear-emu/
    [nix-shell:~/s/gear-emu]$ xbuild /p:Configuration=Release  # The magic (yet deprecated) incantation.
    >>>> xbuild tool is deprecated and will be removed in future updates, use msbuild instead <<<<
    XBuild Engine Version 14.0
    Mono, Version
    Copyright (C) 2005-2013 Various Mono authors
    Build started 11/4/2018 9:43:41 PM.
    Project "/home/red/s/gear-emu/gear.sln" (default target(s)):
            Target ValidateSolutionConfiguration:
                                    Microsoft (R) Visual C# Compiler version (ec1cde8b)
                                    Copyright (C) Microsoft Corporation. All rights reserved.
                            Target _CopyDeployFilesToOutputDirectoryPreserveNewest:
                                    Creating directory '/home/red/s/gear-emu/Gear/bin/Release/Resources'
    Build succeeded.
             0 Warning(s)
             0 Error(s)
    Time Elapsed 00:00:06.0526560
    [nix-shell:~/s/gear-emu]$ mono Gear/bin/Release/Gear.exe

    ^^ success!@
  • __red__ wrote: »
    So, you know I had to right? ;-)

    Saw that coming :P Glad you got it working :) nicely done
  • yetiyeti Posts: 818
    edited 2018-11-05 06:52
    I tried this (some days ago) and my builds on Debian9/amd64 failed with:
    (((lots of similar lines omitted)))
            CSC: error CS0518: The predefined type `System.IntPtr' is not defined or imported
            CSC: error CS0518: The predefined type `System.UIntPtr' is not defined or imported
            CSC: error CS0518: The predefined type `System.RuntimeFieldHandle' is not defined or imported
            CSC: error CS0518: The predefined type `System.RuntimeTypeHandle' is not defined or imported
            CSC: error CS0518: The predefined type `System.Exception' is not defined or imported
             0 Warning(s)
             31 Error(s)
    Time Elapsed 00:00:02.3771650
    There may be some "libraries" missing but not knowing much more about DotNet than just its name I'm lost there.
    $ LANG= aptitude search '~i ^mono*' | cat # piping yields terminal width independent output format
    i A mono-4.0-gac - Mono GAC tool (for CLI 4.0)
    i A mono-csharp-shell - interactive C# shell
    i  mono-devel - Mono development tools
    i A mono-gac - Mono GAC tool
    i A mono-mcs - Mono C# 2.0 / 3.0 / 4.0 / 5.0  compiler for CLI 2.0 / 4.0 / 4.5
    i A mono-runtime - Mono runtime - default version
    i A mono-runtime-common - Mono runtime - common files
    i A mono-runtime-sgen - Mono runtime - SGen
    i A mono-xbuild - MSBuild-compatible build system for Mono
    I simply assumed, installing `mono-devel` would depend on all necessary stuff. :-(

    Some minutes later while looking at the head of the log...
    XBuild Engine Version 14.0
    Mono, Version
    Copyright (C) 2005-2013 Various Mono authors
    Maybe there's a fresher Mono in backports?
    $ LANG= apt-cache policy mono-devel 
      Version table:
     *** 500
            500 stretch/main amd64 Packages
            100 /var/lib/dpkg/status
    So "stable-backports" has no fresher stuff.

    Trying weird stuff like
    $ xbuild /p:Configuration=Release /p:TargetFrameworkVersion="v4.5"
    results in a `Gear.exe` binary that starts but crashes wile loading a `*.binary`.
    That was my status quo 2 days ago.

    I really just poke around aimlessly in the Mono universe.
    Please laugh later...
  • yeti wrote: »
    results in a `Gear.exe` binary that starts but crashes wile loading a `*.binary`.

    Admittedly I have not attempted to load a .binary yet. Let me see what I can do...
  • __red__ wrote: »
    Admittedly I have not attempted to load a .binary yet. Let me see what I can do...
    So you can reproduce this crash?
  • Yes - it crashes for me here too. The older version attached to the first post however does work.
    [red@apophenia:~/projects/sp]$ mono /nix/store/mnb5wfkawlmskabfzykgxavd6f34k0sw-gear-emu-2015-07-14/bin/Gear.exe
    Gtk not found (missing LD_LIBRARY_PATH to, using built-in colorscheme
    System.NullReferenceException: Object reference not set to an instance of an object
      at Gear.GUI.SpinView.Repaint (System.Boolean force) [0x000c2] in <8b5bab8ab7a24c02aa57663778500dfc>:0
      at Gear.GUI.SpinView.OnSize (System.Object sender, System.EventArgs e) [0x0004c] in <8b5bab8ab7a24c02aa57663778500dfc>:0
      at (wrapper delegate-invoke) <Module>.invoke_void_object_EventArgs(object,System.EventArgs)
      at System.Windows.Forms.Control.OnSizeChanged (System.EventArgs e) [0x00026] in <8254e6010dae4d09ac0767af6dcc75af>:0
      at System.Windows.Forms.Control.UpdateBounds (System.Int32 x, System.Int32 y, System.Int32 width, System.Int32 height, System.Int32
    clientWidth, System.Int32 clientHeight) [0x000da] in <8254e6010dae4d09ac0767af6dcc75af>:0
      at System.Windows.Forms.Control.UpdateBounds (System.Int32 x, System.Int32 y, System.Int32 width, System.Int32 height) [0x0004a] in
      at System.Windows.Forms.Control.SetBoundsCoreInternal (System.Int32 x, System.Int32 y, System.Int32 width, System.Int32 height, Syst
    em.Windows.Forms.BoundsSpecified specified) [0x00110] in <8254e6010dae4d09ac0767af6dcc75af>:0
      at System.Windows.Forms.Control.SetBoundsCore (System.Int32 x, System.Int32 y, System.Int32 width, System.Int32 height, System.Windo
    ws.Forms.BoundsSpecified specified) [0x00000] in <8254e6010dae4d09ac0767af6dcc75af>:0
      at System.Windows.Forms.Control.SetBoundsInternal (System.Int32 x, System.Int32 y, System.Int32 width, System.Int32 height, System.W
    indows.Forms.BoundsSpecified specified) [0x00058] in <8254e6010dae4d09ac0767af6dcc75af>:0
      at (wrapper remoting-invoke-with-check) System.Windows.Forms.Control.SetBoundsInternal(int,int,int,int,System.Windows.Forms.BoundsSp
      at System.Windows.Forms.Layout.DefaultLayout.LayoutDockedChildren (System.Windows.Forms.Control parent, System.Windows.Forms.Control
    [] controls) [0x001c6] in <8254e6010dae4d09ac0767af6dcc75af>:0
      at System.Windows.Forms.Layout.DefaultLayout.Layout (System.Object container, System.Windows.Forms.LayoutEventArgs args) [0x00013] i
    n <8254e6010dae4d09ac0767af6dcc75af>:0
      at System.Windows.Forms.Control.OnLayout (System.Windows.Forms.LayoutEventArgs levent) [0x0006d] in <8254e6010dae4d09ac0767af6dcc75a
      at System.Windows.Forms.ScrollableControl.OnLayout (System.Windows.Forms.LayoutEventArgs levent) [0x00013] in <8254e6010dae4d09ac076
      at System.Windows.Forms.ContainerControl.OnLayout (System.Windows.Forms.LayoutEventArgs e) [0x00000] in <8254e6010dae4d09ac0767af6dc
      at System.Windows.Forms.Control.PerformLayout (System.Windows.Forms.Control affectedControl, System.String affectedProperty) [0x0005
    a] in <8254e6010dae4d09ac0767af6dcc75af>:0
      at System.Windows.Forms.Control.PerformLayout () [0x00000] in <8254e6010dae4d09ac0767af6dcc75af>:0
      at Gear.GUI.SpinView.InitializeComponent () [0x003ee] in <8b5bab8ab7a24c02aa57663778500dfc>:0
      at Gear.GUI.SpinView..ctor (Gear.EmulationCore.PropellerCPU chip) [0x00030] in <8b5bab8ab7a24c02aa57663778500dfc>:0
      at (wrapper remoting-invoke-with-check) Gear.GUI.SpinView..ctor(Gear.EmulationCore.PropellerCPU)
      at Gear.GUI.Emulator..ctor (System.String source) [0x0006a] in <8b5bab8ab7a24c02aa57663778500dfc>:0
      at (wrapper remoting-invoke-with-check) Gear.GUI.Emulator..ctor(string)
      at Gear.GUI.GearDesktop.OpenBinaryButton_Click (System.Object sender, System.EventArgs e) [0x00057] in <8b5bab8ab7a24c02aa5766377850
      at System.Windows.Forms.ToolStripItem.OnClick (System.EventArgs e) [0x00019] in <8254e6010dae4d09ac0767af6dcc75af>:0
      at System.Windows.Forms.ToolStripButton.OnClick (System.EventArgs e) [0x00017] in <8254e6010dae4d09ac0767af6dcc75af>:0
      at System.Windows.Forms.ToolStripItem.HandleClick (System.Int32 mouse_clicks, System.EventArgs e) [0x00029] in <8254e6010dae4d09ac07
      at System.Windows.Forms.ToolStripItem.FireEvent (System.EventArgs e, System.Windows.Forms.ToolStripItemEventType met) [0x00054] in <
      at (wrapper remoting-invoke-with-check) System.Windows.Forms.ToolStripItem.FireEvent(System.EventArgs,System.Windows.Forms.ToolStrip
      at System.Windows.Forms.ToolStrip.OnMouseUp (System.Windows.Forms.MouseEventArgs mea) [0x00048] in <8254e6010dae4d09ac0767af6dcc75af
      at System.Windows.Forms.Control.WmLButtonUp (System.Windows.Forms.Message& m) [0x00078] in <8254e6010dae4d09ac0767af6dcc75af>:0
      at System.Windows.Forms.Control.WndProc (System.Windows.Forms.Message& m) [0x001b4] in <8254e6010dae4d09ac0767af6dcc75af>:0
      at System.Windows.Forms.ScrollableControl.WndProc (System.Windows.Forms.Message& m) [0x00000] in <8254e6010dae4d09ac0767af6dcc75af>:
      at System.Windows.Forms.ToolStrip.WndProc (System.Windows.Forms.Message& m) [0x00000] in <8254e6010dae4d09ac0767af6dcc75af>:0
      at System.Windows.Forms.Control+ControlWindowTarget.OnMessage (System.Windows.Forms.Message& m) [0x00000] in <8254e6010dae4d09ac0767
      at System.Windows.Forms.Control+ControlNativeWindow.WndProc (System.Windows.Forms.Message& m) [0x0000b] in <8254e6010dae4d09ac0767af
      at System.Windows.Forms.NativeWindow.WndProc (System.IntPtr hWnd, System.Windows.Forms.Msg msg, System.IntPtr wParam, System.IntPtr
    lParam) [0x00085] in <8254e6010dae4d09ac0767af6dcc75af>:0

    I know nothing about C# with leaves us with three options.
    i. Find a C#/.net guru.
    ii. bisect/blame the codebase until we find the offending change.
    iii. Stick to the released version above.
  • iv. Add to SpinSim whatever makes us happier...
  • Bisected:
    BOOM d889e1a04e8ee4302cf3cecc56964f56c8cf136a Fri Aug 29 20:06:25 2014 -0400
    ERR  1378cd810f8f06b19845966bc3b5b98b810fae83 Thu Aug 28 18:20:18 2014 -0400
    ERR  57836aaa719cbe386bcc2674aaae603937649285 Wed Aug 27 18:11:20 2014 -0400
    ERR  32b3011e39f878b749906edd57e60a9324592009 Wed Aug 27 00:43:28 2014 -0400
    ERR  9c82e6e15622fd3d1f3245193e8f4b182a5e73df Mon Aug 25 18:58:24 2014 -0400
    ERR  459f057f12bc968a6642e2c7223f70fa3e72d402 Wed Aug 13 03:32:00 2014 -0400
    ERR  100c0f1cfbe7eca95971c99077ff28f677c48a22 Tue Aug 12 20:08:51 2014 -0400
    ERR  947fa1ba08abd29ab4c97910fa8e57083c430cf0 Tue Aug 12 08:00:41 2014 -0400
    GOOD eef5fee5f8dcc6176a09d75c2203fa266a833e52 Fri Aug 8 18:16:09 2014 -0400

    It looks like some serious refactoring was done between 947fa1ba and 1378cd81. ERR, in the context above means that mono was unable to compile it.

    At the end of said refactoring, it crashes after loading a binary.

    Nix has packages for versions of mono:

    I can write a quick script to compile the current master under each of these versions and test it (in case the GUI api has changed underneath it).

  • __red____red__ Posts: 470
    edited 2018-11-05 15:26
    /nix/store/g4kjlw9c4rmhdi0x1p25zfywv7yij50c-mono-   2 Warnings (still crashes)
    /nix/store/pns5993p7zc6j5vdjdmn27xj6cimdk2h-mono-   1 Warnings (still crashes)
    /nix/store/ic5qiz4xrlwmiiia7618zw1ysqqmhjf2-mono-    1 Warnings (still crashes)
    /nix/store/i1a62m9nkvxvamfqbraahcw9kbw3dbad-mono-    0 Warnings (still crashes)
    /nix/store/1m935f07rqj2b7k8xaxm2zkgac4rrflr-mono-    0 Warnings (still crashes)
    /nix/store/xhshcsj9452rq4m8549hdkjl4ipsvc56-mono-  0 Warnings (still crashes)
    /nix/store/k5ic0l9j1dv80n8s56lrxzw3ar7sh0m2-mono- 0 Warnings (still crashes)

    I guess this tells us that this isn't a mono versioning problem.
  • yetiyeti Posts: 818
    edited 2018-11-05 15:41
    Maybe we can ping @Gatuno?
  • Ok... one chance more... \o/
    Can't help: My MonoDevelop crashes faster than I can find the debugger in it.
  • GatunoGatuno Posts: 23
    edited 2018-11-06 14:44
    First of all I want to greet you for interest on use Gear Emulator.
    Keeping in mind that you are trying to compile in Linux with mono, I can tell you I never was successful on that. It compiled ON WINDOWS with mono.
    The main reason 4 years ago was the System.Windows.Forms class was not ported to linux, working only in Win*. That class is the main application framework of the app.
    Maybe the mono project had ported it?
  • @Gatuno, thanks for answering!

    Mono is like a foreign parallel dimension to me, but I see something packaged n Debian9 that "smells" like a "System.Windows.Forms" package.
    $ apt-cache search
    libmono-system-windows-forms-datavisualization4.0a-cil - Mono System.Windows.Forms.DataVisualization Library (for CLI 4.0)
    libmono-system-windows-forms4.0-cil - Mono System.Windows.Forms Library (for CLI 4.0)
  • GatunoGatuno Posts: 23
    edited 2018-11-06 16:25
    I think the second one is the required for runtime, but base package is other. I use:
    $apt-cache search mono-system-windows
    libmono-system-windows4.0-cil - Mono System.Windows library (for CLI 4.0)

    As I read on now it would be possible to compile.
    There is a interesting "Guide Porting Winforms Applications" -, with some assistant.

    I hope I have been helpful.

  • Gatuno - that actually helps a ton, thank you.

    I'll update once I have those dependancies resolved.
  • Hello,

    How do I view what is going on with the variables?

    Is there an op code to look for in the Memory/Spin map?
    Is there a specific place in memory the variables are placed?
    When compiled, are the variables given a sequential number as a name or a random one?

    Is there a way to get them to show so I can watch them change?
    group0        long      CLK_PIN << 24 | PH0_PIN << 16 | PH1_PIN << 8 | 0
    group1        long      CLK_PIN << 24 | PH2_PIN << 16 | PH3_PIN << 8 | 100
    group2        long      CLK_PIN << 24 | PH4_PIN << 16 | NO_PIN  << 8 | 200
                  org       0
    wavegen       rdlong    phase0,par
                  mov       clkpin,phase0
                  shr       clkpin,#24
                  mov       clkmask,#1
                  shl       clkmask,clkpin
                  mov       ph0pin,phase0
                  shr       ph0pin,#16
                  and       ph0pin,#$ff
                  mov       ph1pin,phase0
                  shr       ph1pin,#8
                  and       ph1pin,#$ff
                  and       phase0,#$ff
                  add       phase0,#sine
                  mov       phase1,phase0
                  add       phase1,#50

    Thank You
  • I read thru the "Changes and corrections-ASB.txt" and ran across this.
    +Show Cog RAM Special Purpose Registers values.
    Now the values of special registers in cog memory (between $1F0 - PAR and $1FF - VSCL)
    are displayed correctly in memory or PASM view.

    What is PASM view? Where is it? How do you switch it on?

    Thank You
  • Cog view I think.
  • Any answer to the fourth post up?
  • yetiyeti Posts: 818
    edited 2019-02-28 19:13
    bteddy wrote: »
    Any answer to the fourth post up?
    Will a naked DAT block compile?
    Will this naked DAT block compile?
    Where is a loop in there?
    Am I too undercaffeinated (totally possible!) to see it?
  • ?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!


    I have stated multiple time I am a beginner with the propeller, microcontrollers in general.
    To me the questions are totally different.
    If something I am asking is redundant, I don't know that.

    There will always be newbies.
    This is why the forum is here (supposedly), to share and have it archived for future access, right!?

    I read the manual, searched this and other forums, then I asked the questions.
    Sorry, but I can not visualize it the way it is described in the manual.
  • yetiyeti Posts: 818
    edited 2019-03-01 02:21
    How did you get your code into GEAR?
    For me, this fragment does not even compile.
  • Propeller tool.
    Enter code.
    Click Object_info.
    Click Save Binary File.

    Open Gear.
    Click Open Binary.
  • bteddy wrote: »
    Propeller tool.
    Enter code.
    Click Object_info.
    Click Save Binary File.

    Open Gear.
    Click Open Binary.
    With THIS code?
  • This is the complete listing.
    '' Copyright (c) 2008 Philip C. Pilgrim
    '' (See end of file for terms of use.)
    ''-----------[ Description ]----------------------------------------------------
    '' This Propeller object provides up to eight leading-edge-aligned PWM channels
    '' with resolution determined by a defined constant. The maximum PWM frequency
    '' is the lesser of:
    ''    clkfreq / (13.5 * resolution) and 20.648881 / resolution MHz
    '' The minimum PWM frequency is :
    ''    clkfreq / (40000 * resolution)
    '' PWM output is generated using the Propeller's video generator in VGA mode. The
    '' eight or fewer channels can be any subset of the pins in one of four
    '' contiguous blocks: A0-A7, A8-A15, A16-A23, or A24-A31.
    ''-----------[ History ]--------------------------------------------------------
    '' Version 1.1: 17 Jul 08: Fixed a couple bugs related to base pins > 0.
    '' Version 1.2: 20 Jan 10: Fixed a bug relating to duty modes of 256 (i.e. full on).
    ''-----------[ Program ]--------------------------------------------------------
      resolution    = 256           'The number of steps in the pulse widths. Must be an integer multiple of 4.
      nlongs        = resolution / 4
      long  fcb[5]
      long  pwmdata[nlongs + 1]
      long  pinmask
      long  previndex[8]
      byte  cogno, basepin
    '-----------[ Public Methods ]-------------------------------------------------
    PUB start(base, mask, freq)
    ' This method is used to setup the PWM driver and start its cog. If a driver had
    ' already been started, it will be stopped first. The arguments are as follows:
    '     base: The base pin of the PWM output block. Must be 0, 8, 16, or 24.
    '     mask: The enable mask for the eight pins in the block:
    '               bit 0 = basepin + 0
    '               bit 1 = basepin + 1
    '               ...
    '               bit 7 = basepin + 7
    '           Set a bit to 1 to enable the corresponding pin for PWM ouput.
    '     freq: The frequency in Hz for the PWM output.
    ' Returns true on success; false, if no cog is available or parameters exceed
    ' permissible limits.    
      if (cogno)
      freq *= resolution
      if (clkfreq =< 4000000 or freq > 20648881 or clkfreq  < freq * 135 / 10 or clkfreq / freq > 40000 or base <> base & %11000 or mask <> mask & $ff or resolution <> resolution & $7ffffffc)
        return false
      basepin := base      
      pinmask := mask << base
      longfill(@pwmdata, 0, nlongs)
      longfill(@previndex, 0, 8)
      fcb[0] := nlongs
      fcb[1] := freq
      fcb[2] := constant(1 << 29 | 1 << 28) | base << 6 | mask
      fcb[3] := pinmask
      fcb[4] := @pwmdata
      if (cogno := cognew(@pwm, @fcb) + 1)
        return true
        return false
    PUB stop
    ' This method is used to stop an already-started PWM driver. It returns true if
    ' a driver was running; false, otherwise.
      if (cogno)
        cogstop(cogno - 1)
        return true
        return false
    PUB duty(pinno, value) | vindex, pindex, i, mask, unmask
    ' This method defines a pin's duty cycle. It's arguments are:
    '     pinno: The pin number of the PWM output to modify.
    '     value: The new duty cycle (0 = 0% to resolution = 100%)
    ' Returns true on success; false, if pinno or value is invalid.
      if (1 << pinno & pinmask == 0 or value < 0 or value > resolution)
        return false
      pinno -= basepin
      mask := $01010101 << pinno
      unmask := !mask
      vindex := value >> 2
      pindex := previndex[pinno]
      if (vindex > pindex)
        repeat i from pindex to vindex - 1
          pwmdata[i] |= mask
      elseif (vindex < pindex)
        repeat i from pindex to vindex + 1
          pwmdata[i] &= unmask
      pwmdata[vindex] := pwmdata[vindex] & unmask | mask & ($ffffffff >> (31 - ((value & 3) << 3)) >> 1)
      previndex[pinno] := vindex
      return true
    ' PWM driver loaded into a separate cog. Cycles continuously through PWM data in hub RAM,
    ' using the video driver to output logic levels.
    '-----------[ Initialization ]-------------------------------------------------
                  org       0
    pwm           rdlong    clkfrq,#0               'Read the current clock frequency (Hz).
                  mov       ptr0,par                'Get beginning address of fcb in ptr0.
                  rdlong    longs,ptr0              'Get the number of longs in pwm array.
                  add       ptr0,#4
                  rdlong    pllfrqh,ptr0            'Read the desired output pll frequency (Hz).
                  add       ptr0,#4                 'Increment fcb index.
                  mov       pllfrql,pllfrqh         'Divide output pll freq by 16 to get input pll freq w/ no divider.
                  shr       pllfrqh,#4              '  64-bit result.
                  shl       pllfrql,#28
                  mov       plldiv,#0               'Initialize frequency divider for no division.
    :frqalp       cmp       pllfrqh,_4000000 wc     'Is input pll freq at least 4MHz?
            if_nc jmp       #gotpllinp              '  Yes: Use it.
                  shl       pllfrql,#1 wc           '  No:  Input pll freq *= 2.
                  rcl       pllfrqh,#1
                  add       plldiv,#1               '       Divider *= 2 also to keep output the same.
                  jmp       #:frqalp                '       Back for another try.
    gotpllinp     mov       ra,pllfrqh              'frqa := input pll freq * 2^32 / clkfrq
                  mov       rb,pllfrql
                  mov       rx,clkfrq
                  call      #divabx                 'rb := ra:rb / rx
                  mov       frqa,rb                 'Save frqa.
                  sub       plldiv,#7 wc,wz         'Can all the division be done in counter?
     if_nz_and_nc jmp       #:needvscl                            
                  neg       plldiv,plldiv           '  Yes: Compute the divider value.
                  jmp       #:gotdiv
    :needvscl     shl       vscl0,plldiv            '  No:  Shift VSCL value left by divider amount.
                  mov       plldiv,#0               '       Set CTRA for maximum divider.
    :gotdiv       mov       vscl,vscl0              'Write computed value to VSCL.
                  shl       plldiv,#23              'Position it for CTRA.
                  or        plldiv,ctra0            'OR in the rest.
                  mov       ctra,plldiv             'Write CTRA.
                  rdlong    vcfg,ptr0               'Get VCFG from fcb.
                  add       ptr0,#4
                  rdlong    dira,ptr0               'Get DIRA from fcb.
                  add       ptr0,#4
                  rdlong    ptr0,ptr0               'Get address of pwmdata array in ptr0.
    '-----------[ Main PWM Loop ]--------------------------------------------------
    pwmlp         mov       ptr,ptr0                ' 4   Point back to beginning of pwmdata.
                  mov       ctr,longs               ' 4   Initialize counter with no. of longs.
    :nyblp        rdlong    pwmbits,ptr             '22   Read four "pixels" form pwmdata.
                  add       ptr,#4                  ' 4   Point to next four.              
                  waitvid   pwmbits,#%11_10_01_00   ' 6   Wait and "display".
                  djnz      ctr,#:nyblp             ' 8   Back for next "pixel".
                  jmp       #pwmlp                  ' 4   Back for first "pixel".
                                                    '52 clocks worst case, or 1.538 MHz through loop w/ 80 MHz clock.
    '-----------[ Divide 64 / 32 = 32 ]--------------------------------------------
    divabx        mov       cctr,#32 wc
    :loop         rcl       rb,#1 wc
                  rcl       ra,#1 wc
            if_c  sub       ra,rx
           if_nc  cmpsub    ra,rx wc
                  djnz      cctr,#:loop
                  rcl       rb,#1 wc
    divabx_ret    ret
    '-----------[ Predefined variables and constants ]-----------------------------
    vscl0         long      1 << 12 | 4             'Initial VSCL w/ no division.
    ctra0         long      %00001 << 26            'Initial CTRA w/ no PLL.
    pwmbits       long      0                       '
    _4000000      long      4000000                 'Minimum PLL input frequency.
    '-----------[ Variables ]------------------------------------------------------
    ptr0          res       1
    ptr           res       1
    ctr           res       1
    ra            res       1
    rb            res       1
    rx            res       1
    cctr          res       1
    clkfrq        res       1
    pllfrqh       res       1
    pllfrql       res       1
    plldiv        res       1
    longs         res       1
    ''-----------[ TERMS OF USE ]---------------------------------------------------
    '' Permission is hereby granted, free of charge, to any person obtaining a copy of
    '' this software and associated documentation files (the "Software"), to deal in
    '' the Software without restriction, including without limitation the rights to use,
    '' copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
    '' Software, and to permit persons to whom the Software is furnished to do so,
    '' subject to the following conditions: 
    '' The above copyright notice and this permission notice shall be included in all
    '' copies or substantial portions of the Software. 
Sign In or Register to comment.