Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New and improved SICK project
#1
This file is:

Code: (Select All)
The Symbolic Instruction Code Kit, which contains a QB64 program named SIC64.BAS
and several smaller utility programs. The source code is public domain and can be
found on several sites, including, filegate.net and keepandshare.com

This program uses a recursive descent parser to interpret a psuedo-basic language
written in a line oriented fashion and can be used for small programming chores.

The archive also contains some further imbedded .zip files which contain several
QB64 sample programs, and some .SIC programs which are used by the SIC engine.
Thank you,
 Erik Jon Oredson
You may contact me at my email: 
 eoredson@gmail.com

Version list:

Code: (Select All)
Version v64.0a r5.8a:
  Fixes total bytes in ListFiles.
  Adds bytes copied in StatusLine when loading file.
  Adds Dot.Display when reading/writing files in Sub ScrnEdit.
  Adds Timer to Sub Edit.Status.Line in Sub Scrnedit.
  Removes _unsigned from all file handle variables.
  Fixes Control-R search/replace display in Sub Scrnedit.
  Fixes Function DisplayWinError$ with ErrorBuffer$ as ASCIIZ.
Version v64.0a r5.9a:
  Fixes Analyze.bas, Indent.bas, Renumber.bas
  Renames Syntax2.doc to Syntax.doc
  Stores/restores read-only bit in output file in Sub Scrnedit.
  Replaces all Common Shared with Dim Shared in sic.inc
Version v64.0a r5.9a (09/30/2022):
  Adds quotes in filename for load/save.
  Adds Linux compatible in scrnedit.
  Adds load filename in Scrnedit to program array.
Version v64.0a r5.9a (10/30/2022)
  Adds (Z)extended display to Directories/Filenames in Menu3.
  Adds $Z drive serial number macro to SetPrompts.
  Renamed sic.inc to sic16.inc to avoid old filename collision.
Version v64.0a r6.0a:
  Adds multiple file numbers to closefile.
  Adds debug commands to program run array.
  Adds screen saver timer trap and settings.
  Make sure all Inkey$ modified to InkeyX$ to trap Keypress for screen saver.
Version v64.0a r6.1a:
  Adds dialog.inc file for reading filename.
  Edits call GetOpenFilename for reading filename in Call ScrnEdit.
Version v64.0a r6.2a:
  Adds range of files to close in CloseFile.
  Adds MakeBeep to File# breaks.
  Fixes Rem $Debug: spacing.
  Adds file trap to lock/unlock.
  Adds file record trap to debug.
    Affects Sub Get/Put and Sub Lock/Unlock.
Version v64.0a r6.3a:
  Adds TO keyword to lock/unlock.
  Fixes spacing in Sub ReadProgram.
Version v64.0a r6.4a:
  Fixes print after keyboardline input.
  Adds more dialog box function calls.
  Removes Cls in dialog box call.
Version v64.0a r6.5a:
  Modifies titlebar icon.
  Adds multiple $Debug statements when separated by colons.
Version v64.0a r6.6a:
  Removes call to GetConfigFilename$ in Sub ReadConfig and Sub WriteConfig.
  Removes CreateFile And CreateFileA in library function declarations.
  Writes Sub CreateFileA to test file, create file, and append file.
Version v64.0a r6.7a:
  Fixes problem when started from netpath/cdrom.
  Adds C:\ and \\server\share\ to main input loop.
  Adds CD/MD/RD directory access commands.
  Fixes problem using directory path in ReadConfig.
Version v64.0a r6.8a:
  Adds CD... to main menu.
  Fixes multipaths to CD/MD/RD.
  Also detects removing drive in RD.
  Adds realtime clock to KeyboardLine2$
Version v64.0a r7.1a:
  Fixes display line length in input in KeyboardLine2$
    When entered Tab/Insert/Enter char.
    Adds KeyboardTimer to toggle realtime display prompt.
    Adds KeyboardTimer in config file.
  Adds Width command to main menu.
    Also adds screen width 40 to ScrnEdit/Dirs/Files/Drives.
    Now sets TabStop constant to 8.
Version v64.0a r7.2a:
    Fixes MediaExists in Sub FreeSpace and TotalSpace.
    Improves drive list in Volume in Sub Menu.
    Adds [Z]Destroy drive to Volume to Sub Menu.
    Fixes ListBreakTime in Sub DebugCommand.
    Fixes error trap in Debug and Whatis.
    Adds multiple spec to files and dirs list.
Version v64.0a r7.3a:
  Now traps control characters in Sprint.
  Moves _ControlChr off to top of main program.
  Adds Const.inc and Color.inc include files.
  Adds Library.inc to include library declarations.

Version v64.0a r7.4a:
  Adds ctrl-l to insert file and ctrl-k to append file in sub scrnedit.
  Fixes insert to sub scrnedit.

Version v64.0a r7.5a:
  Replaces LoadIcon with Icon2BMP.
  Replaces Name AS with MoveFile.
  Replaces Kill with DeleteFile.
  Replaces MkDir with CreateDirectory.
  Adds $VersionInfo to Library.inc
  Adds screen values to Width function.
  Adjusts SicHelp.bas for screen display and statusline.
  Adds SearchFiles, ScrnEdit2, and ValidFileChar.
    Also adds PercentDisplay, Dot.Display2, and Back.Space.
  Adds Set Toggle <value>, Set Alarms <value>, Set Memmenu <value>.
  Modifies some file variables hfind and finddata.
  Now gets print using in Format$ to call XprintExpression.
  Nasty error:
    Fixes deleting source file upon exit instead of temp file.
    Also removes temp file in Renumber correctly.
Version v64.0a r7.6a:
  Replaces all _limit and Inkey$ with custom Inkeyx$
  Removes ascii 29 backspace in Dot.Display in ScrnEdit2.
    Replaces with call to BackSpace.
  Adds More and Type command to display contents of a file.
    Works with binary file i/o and traps Control-Break.
  Modifies ScrnEdit and ScrnEdit2 with Linux binary read/write buffer.
    Avoids binary overrun skipping last line at eof.
    Adds AvoidLINUX setting to skip Linux read/write.
  Wrote Sub InitConfig to reset and overwrite Sick?.cfg file.
  Adds Toggle Menu function to toggle default settings.
  Adds Prompt command to start SetPrompts menu.
  Edits and adds Sub Dot.Display in Scrnedit and Scrnedit2.
  Removes unused Dot.Display2 and Back.Space functions.
  Adds <clock>/<date>/<time>/Date$/Time$ to ListHelpFile macros.

Version v64.0a r7.7a:
  Edits Whatis error trap flag.
  Adds Color Red to DisplayError.
  Adds static Displayed to StartMenu.
  Adds Sub MorePromptType for Sub TypeFile.
  Now sets single reported in _Sndlen to 2 decimals.
  Enables support for Midi files.
    Adds Sub VerifyPlay function to check sound filename extension.
  Increments node command line to A to F.

Version v64.0a r7.8a:
  Adds Play Pause and Play Resume to toggle playmode.
  New SearchFiles functions:
    Adds Sub VerifyFile to check system file.
    Adds Sub VerifyFile2 to check library file.
    Adds Sub VerifyFile3 to check source file.
    Adds Sub VerifyFile4 to check document file.
    Adds Sub VerifyFile5 to check compressed file.
      And Ctrl-P pause/resume soundfile.
      And Ctrl-Q set soundfile plsu 10 seconds.
      And Ctrl-R set soundfile minus 10 seconds.
  Moves author info from statements array to authorstatus array.
  Adds some Triple variable assignment operators, such as:
      !!=, &&=, ||=, ++=, --=, **=, //=, \\=, ^^=, <<=, >>=

Attached files:
  SIC87I.ZIP for VBdos
  SICK64F9.ZIP for QB64

Now 32,044 lines.

[Image: sic64.png]


Attached Files
.zip   SICHELP.ZIP (Size: 63.07 KB / Downloads: 18)
.zip   SIC87I.ZIP (Size: 845.75 KB / Downloads: 11)
.zip   SICK64F9.ZIP (Size: 506.18 KB / Downloads: 28)
Reply
#2
Once again thank you for your work. Especially packaging "scrnedit" as a subprogram. The standalone program is good enough but I have to remember to save my work often, which means getting out of it and back into it again but I'm not used to it. I'm going to spread word a little bit about both your programs because it's not easy to create a text editor, and less easy to build an interpreter that could be taken seriously.
Reply
#3
Thumbs Up 
Updated QB64PE 32-bit to the latest v3.2 to produce SICK64, on Windows10. I had a problem compiling the "analyze.bas". Maybe you used BASIC PDS v7.1 to come up with it, because it complains about "DIR$()" function. There is one in QB64PE but it behaves differently:

https://qb64phoenix.com/qb64wiki/index.php/DIR$

I guess you're prepared for it, otherwise this is going to be a PITA. Look what had to be done for Linux only to get anything that looks like Windows File Explorer in an user's QB64 program.

Another issue: the "sichelp.bas" is created successfully but when the user runs it and chooses option #6 it says it cannot find "syntax.doc". I noticed in the package the file was split into two parts because it was getting too big. This is only a functional bug which doesn't prevent EXE creation.

I composed a program on "SIC64" but forgot to put in line numbers. Loaded it in, ran it and did nothing. Maybe just after the user orders program run, make a quick syntax check such as using "VAL()" to make sure there's an integer line number at the beginning of a line? Some people might be put off by the stony silence or convinced the interpreter doesn't work. Although this stuff is for geeks anyway...

Maybe it's just my 10-year-old computer (Intel "Sandy Bridge" or near) but the interpreter reports incorrect CPU usage on its titlebar while waiting for keyboard input. I opened Windows Task Manager to discover it was only about 5% while the titlebar said 20% or more. It's something else that could dishearten a person who dives into things although could be middle-aged like we are around here. Another thing that could be considered confusing is this interpreter has a status bar, but the CPU usage and available RAM is displayed somewhere else in its program window.

I wish I had even more time to do useful things with this interpreter.
Reply
#4
(09-24-2022, 08:06 PM)mnrvovrfc Wrote: Updated QB64PE 32-bit to the latest v3.2 to produce SICK64, on Windows10. I had a problem compiling the "analyze.bas". Maybe you used BASIC PDS v7.1 to come up with it, because it complains about "DIR$()" function. There is one in QB64PE but it behaves differently:

https://qb64phoenix.com/qb64wiki/index.php/DIR$

I guess you're prepared for it, otherwise this is going to be a PITA. Look what had to be done for Linux only to get anything that looks like Windows File Explorer in an user's QB64 program.

Another issue: the "sichelp.bas" is created successfully but when the user runs it and chooses option #6 it says it cannot find "syntax.doc". I noticed in the package the file was split into two parts because it was getting too big. This is only a functional bug which doesn't prevent EXE creation.

I composed a program on "SIC64" but forgot to put in line numbers. Loaded it in, ran it and did nothing. Maybe just after the user orders program run, make a quick syntax check such as using "VAL()" to make sure there's an integer line number at the beginning of a line? Some people might be put off by the stony silence or convinced the interpreter doesn't work. Although this stuff is for geeks anyway...

Maybe it's just my 10-year-old computer (Intel "Sandy Bridge" or near) but the interpreter reports incorrect CPU usage on its titlebar while waiting for keyboard input. I opened Windows Task Manager to discover it was only about 5% while the titlebar said 20% or more. It's something else that could dishearten a person who dives into things although could be middle-aged like we are around here. Another thing that could be considered confusing is this interpreter has a status bar, but the CPU usage and available RAM is displayed somewhere else in its program window.

I wish I had even more time to do useful things with this interpreter.

No PITA, just in Sick64d9.zip is the following:

Remove or comment out Dir$ from Analyze.bas
  Reason: In QB45 it worked into BC7 with Dir$ which was deprecated before QB64..

Rename Syntax2.doc to Syntax.doc..

Now states to enter line number if no command matches.

CPU usage is grabbed from Mem.h and there nothing I can do to fix this!

Erik.
Reply
#5
(09-27-2022, 06:21 AM)eoredson Wrote: CPU usage is grabbed from Mem.h and there nothing I can do to fix this!

@eoredson
You don't have to use MEM.h at all, if you don't want to. All of these can be used perfectly well in QB64. If you need help converting them over I'd be more than happy to assist.
Tread on those who tread on you

Reply
#6
Eh, what the heck. I decided to go ahead and do it for ya. Here is the MEM.H file converted to 100% BAS code.
Everything should work just the same since all the variable types match and the structs are the proper size.

Code: (Select All)
Type MEMORYSTATUSEX
    As _Unsigned Long dwLength, dwMemoryLoad
    As _Unsigned _Integer64 ullTotalPhys, ullAvailPhys, ullTotalPageFile, ullAvailPageFile, ullTotalVirtual, ullAvailVirtual, ullAvailExtendedVirtual
End Type

Type FILETIME
    As _Unsigned Long dwLowDateTime, dwHighDateTime
End Type

Declare CustomType Library
    Sub GlobalMemoryStatusEx (ByVal lpBuffer As _Offset)
    Function GetSystemTimes& (ByVal lpIdleTime As _Offset, Byval lpKernelTime As _Offset, Byval lpUserTime As _Offset)
End Declare

Function MemInUsePercent~& () 'I changed this one to a return of _Unsigned Long because dwMemoryLoad is an _Unsigned Long. I think Steve had missed that originally
    Dim As MEMORYSTATUSEX statex
    statex.dwLength = Len(statex)
    GlobalMemoryStatusEx _Offset(statex)
    MemInUsePercent = statex.dwMemoryLoad
End Function

Function TotalPhysicalMem~&& ()
    Dim As MEMORYSTATUSEX statex
    statex.dwLength = Len(statex)
    GlobalMemoryStatusEx _Offset(statex)
    TotalPhysicalMem = statex.ullTotalPhys
End Function

Function FreePhysicalMem~&& ()
    Dim As MEMORYSTATUSEX statex
    statex.dwLength = Len(statex)
    GlobalMemoryStatusEx _Offset(statex)
    FreePhysicalMem = statex.ullAvailPhys
End Function

Function TotalPagingFile~&& ()
    Dim As MEMORYSTATUSEX statex
    statex.dwLength = Len(statex)
    GlobalMemoryStatusEx _Offset(statex)
    TotalPagingFile = statex.ullTotalPageFile
End Function

Function FreePagingFile~&& ()
    Dim As MEMORYSTATUSEX statex
    statex.dwLength = Len(statex)
    GlobalMemoryStatusEx _Offset(statex)
    FreePagingFile = statex.ullAvailPageFile
End Function

Function TotalVirtualMem~&& ()
    Dim As MEMORYSTATUSEX statex
    statex.dwLength = Len(statex)
    GlobalMemoryStatusEx _Offset(statex)
    TotalVirtualMem = statex.ullTotalVirtual
End Function

Function FreeVirtualMem~&& ()
    Dim As MEMORYSTATUSEX statex
    statex.dwLength = Len(statex)
    GlobalMemoryStatusEx _Offset(statex)
    FreeVirtualMem = statex.ullAvailVirtual
End Function

Function FreeExtendedMem~&& ()
    Dim As MEMORYSTATUSEX statex
    statex.dwLength = Len(statex)
    GlobalMemoryStatusEx _Offset(statex)
    FreeExtendedMem = statex.ullAvailExtendedVirtual
End Function

Function CalculateCPULoad! (idleTicks As _Unsigned _Integer64, totalTicks As _Unsigned _Integer64) Static
    Static As _Unsigned _Integer64 previousTotalTicks, previousIdleTicks

    Dim As _Unsigned _Integer64 totalTicksSinceLastTime: totalTicksSinceLastTime = totalTicks - previousTotalTicks
    Dim As _Unsigned _Integer64 idleTicksSinceLastTime: idleTicksSinceLastTime = idleTicks - previousIdleTicks

    Dim As Single ret
    If totalTicksSinceLastTime > 0 Then ret = 1.0 - idleTicksSinceLastTime / totalTicksSinceLastTime Else ret = 0

    previousTotalTicks = totalTicks
    previousIdleTicks = idleTicks
    CalculateCPULoad = ret
End Function

Function FileTimeToInt64~&& (ft As FILETIME) Static
    FileTimeToInt64 = _ShL(ft.dwHighDateTime, 32) Or ft.dwLowDateTime
End Function

Function GetCPULoad! ()
    Dim As FILETIME idleTime, kernelTime, userTime
    If GetSystemTimes(_Offset(idleTime), _Offset(kernelTime), _Offset(userTime)) Then GetCPULoad = CalculateCPULoad(FileTimeToInt64(idleTime), FileTimeToInt64(kernelTime) + FileTimeToInt64(userTime)) Else GetCPULoad = -1.0
End Function

EDIT: It should be good now. Had a function missing.
Tread on those who tread on you

Reply
#7
That looks like nice code, but,

when patched into the following snippet it produces an error:

  Statement cannot be placed between SUBS/FUNCTIONS

even if I move the include statement below main (above sub CPUtrap), then
when I start it the program window pauses for 2 seconds and vanishes.

Code: (Select All)
' declare all default variables
DefDbl A-Z
Rem $DYNAMIC
Rem $Include:'mem.bi'
Dim Shared t6 As Integer
Dim Shared t7 As Single

' start cpu timer trap
t6 = _FreeTimer
t7! = 1!
On Timer(t6, t7!) CPUtrap
Timer(t6) On
Do
  _Limit 50
  x$ = InKey$
  If Len(x$) Then Exit Do
Loop
Timer(t6) Off
End

Sub CPUtrap
  S$ = Str$(Int(GetCPULoad * 10000) / 100) ' 100.00
  If InStr(S$, ".") Then
      Q$ = Mid$(S$, InStr(S$, ".") + 1)
      S$ = Left$(S$, InStr(S$, ".") - 1)
      Q$ = Left$(Q$, 3)
      S$ = S$ + "." + Q$
  Else
      S$ = S$ + ".0"
  End If
  D$ = "CPU " + S$ + "%" ' 100.00
  Cls
  Print D$
End Sub


Attached Files
.bi   mem.bi (Size: 3.17 KB / Downloads: 54)
Reply
#8
(09-28-2022, 03:11 AM)eoredson Wrote: That looks like nice code, but,

when patched into the following snippet it produces an error:

  Statement cannot be placed between SUBS/FUNCTIONS
:
You have to divide @Spriggsy's contribution into two parts. The BI file is from the beginning and up to but excluding the line which starts like:
Code: (Select All)
Function MemInUsePercent~& ()
The BM file then is the file which begins at that line to the end. Place $INCLUDE: 'mem.bi' at the beginning of your source code, and another $INCLUDE at the end of your source code. The subprograms have to be at the end indeed, but the "DECLARE" statements need to be one of the first statements for initialization.
Reply
#9
I took your suggestion and moved the function declarations to the bottom of the code, but, the
program still exits the windows after a start..

Erik.

btw; what is "as" without any preceding variable?

WTF: does anybody out there test their code before posting it??

Now I have this snippet of code that does not work:

Code: (Select All)
' declare all default variables
DefDbl A-Z
Rem $DYNAMIC

Type MEMORYSTATUSEX
  As _Unsigned Long dwLength, dwMemoryLoad
  As _Unsigned _Integer64 ullTotalPhys, ullAvailPhys, ullTotalPageFile, ullAvailPageFile, ullTotalVirtual, ullAvailVirtual, ullAvailExtendedVirtual
End Type

Type FILETIME
  As _Unsigned Long dwLowDateTime, dwHighDateTime
End Type

Declare CustomType Library
  Sub GlobalMemoryStatusEx (ByVal lpBuffer As _Offset)
  Function GetSystemTimes& (ByVal lpIdleTime As _Offset, Byval lpKernelTime As _Offset, Byval lpUserTime As _Offset)
End Declare

Dim Shared t6 As Integer
Dim Shared t7 As Single

' start cpu timer trap
t6 = _FreeTimer
t7! = 1!
On Timer(t6, t7!) CPUtrap ' title with cpu
Timer(t6) On
Do
  _Limit 50
  x$ = InKey$
  If Len(x$) Then Exit Do
Loop
Timer(t6) Off
End

Sub CPUtrap
  S$ = Str$(Int(GetCPULoad * 10000) / 100) ' 100.00
  If InStr(S$, ".") Then
      Q$ = Mid$(S$, InStr(S$, ".") + 1)
      S$ = Left$(S$, InStr(S$, ".") - 1)
      Q$ = Left$(Q$, 3)
      S$ = S$ + "." + Q$
  Else
      S$ = S$ + ".0"
  End If
  D$ = "CPU " + S$ + "%" ' 100.00
  Cls
  Print D$
End Sub

Function MemInUsePercent~& ()
  Dim As MEMORYSTATUSEX statex
  statex.dwLength = Len(statex)
  GlobalMemoryStatusEx _Offset(statex)
  MemInUsePercent = statex.dwMemoryLoad
End Function

Function TotalPhysicalMem~&& ()
  Dim As MEMORYSTATUSEX statex
  statex.dwLength = Len(statex)
  GlobalMemoryStatusEx _Offset(statex)
  TotalPhysicalMem = statex.ullTotalPhys
End Function

Function FreePhysicalMem~&& ()
  Dim As MEMORYSTATUSEX statex
  statex.dwLength = Len(statex)
  GlobalMemoryStatusEx _Offset(statex)
  FreePhysicalMem = statex.ullAvailPhys
End Function

Function TotalPagingFile~&& ()
  Dim As MEMORYSTATUSEX statex
  statex.dwLength = Len(statex)
  GlobalMemoryStatusEx _Offset(statex)
  TotalPagingFile = statex.ullTotalPageFile
End Function

Function FreePagingFile~&& ()
  Dim As MEMORYSTATUSEX statex
  statex.dwLength = Len(statex)
  GlobalMemoryStatusEx _Offset(statex)
  FreePagingFile = statex.ullAvailPageFile
End Function

Function TotalVirtualMem~&& ()
  Dim As MEMORYSTATUSEX statex
  statex.dwLength = Len(statex)
  GlobalMemoryStatusEx _Offset(statex)
  TotalVirtualMem = statex.ullTotalVirtual
End Function

Function FreeVirtualMem~&& ()
  Dim As MEMORYSTATUSEX statex
  statex.dwLength = Len(statex)
  GlobalMemoryStatusEx _Offset(statex)
  FreeVirtualMem = statex.ullAvailVirtual
End Function

Function FreeExtendedMem~&& ()
  Dim As MEMORYSTATUSEX statex
  statex.dwLength = Len(statex)
  GlobalMemoryStatusEx _Offset(statex)
  FreeExtendedMem = statex.ullAvailExtendedVirtual
End Function

Function CalculateCPULoad! (idleTicks As _Unsigned _Integer64, totalTicks As _Unsigned _Integer64) Static
  Static As _Unsigned _Integer64 previousTotalTicks, previousIdleTicks

  Dim As _Unsigned _Integer64 totalTicksSinceLastTime: totalTicksSinceLastTime = totalTicks - previousTotalTicks
  Dim As _Unsigned _Integer64 idleTicksSinceLastTime: idleTicksSinceLastTime = idleTicks - previousIdleTicks

  Dim As Single ret
  If totalTicksSinceLastTime > 0 Then ret = 1.0 - idleTicksSinceLastTime / totalTicksSinceLastTime Else ret = 0

  previousTotalTicks = totalTicks
  previousIdleTicks = idleTicks
  CalculateCPULoad = ret
End Function

Function FileTimeToInt64~&& (ft As FILETIME) Static
  FileTimeToInt64 = _SHL(ft.dwHighDateTime, 32) Or ft.dwLowDateTime
End Function

Function GetCPULoad! ()
  Dim As FILETIME idleTime, kernelTime, userTime
  If GetSystemTimes(_Offset(idleTime), _Offset(kernelTime), _Offset(userTime)) Then GetCPULoad = CalculateCPULoad(FileTimeToInt64(idleTime), FileTimeToInt64(kernelTime) + FileTimeToInt64(userTime)) Else GetCPULoad = -1.0
End Function
Reply
#10
I ran your snippet and I have the CPU usage percentage showing up just fine in the window. You do not have to use my conversion. Concerning "AS", I'd recommend reading the Wiki page on DIM.

[Image: image.png]

P.S. Probably wouldn't hurt to maybe say which version of Windows you are on and which architecture. A little difficult to assist in figuring out where something is breaking if all we have is "WTF" and "doesn't work".
Tread on those who tread on you

Reply




Users browsing this thread: 4 Guest(s)