Last active
July 20, 2024 03:26
-
-
Save CarlTBarnes/87e1b615288409b86b7f7af4488e8dbd to your computer and use it in GitHub Desktop.
Scratch source I use when I want to write a quick test of some code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PROGRAM !Scratch program by Carl Barnes - Version 8/1/2020 - Download https://git.io/JtPKE | |
INCLUDE('TplEqu.CLW') | |
INCLUDE('KeyCodes.CLW') | |
MAP | |
main PROCEDURE() | |
DB PROCEDURE(STRING DebugMessage) | |
DBClear PROCEDURE() !Clear DebugView Buffer | |
Hex8 PROCEDURE(LONG LongInt),STRING | |
MODULE('RTL') | |
!LenFastClip PROCEDURE(CONST *STRING Text2Measure),LONG,NAME('Cla$FASTCLIP'),DLL(dll_mode) Fails in Release mode, bad idea | |
ClaFieldNameRTL PROCEDURE(LONG pFEQ),CSTRING,RAW,NAME('Cla$FIELDNAME'),DLL(dll_mode) | |
ClaEventNameRTL PROCEDURE(LONG EventPlusA000h),*CSTRING,RAW,NAME('WslDebug$MsgName'),DLL(dll_mode) | |
C5LogSetName PROCEDURE(CONST *CSTRING),NAME('WslDebug$SetLogFile'),DLL(dll_mode) | |
C5LogPrint PROCEDURE(STRING),NAME('WslDebug$Print'),DLL(dll_mode) | |
C5LogPrintEvent PROCEDURE(),NAME('WslDebug$PrintEvent'),DLL(dll_mode) !E.g. Event: EVENT:Accepted ?WSLDEBUGPRINT_BTN (10) | |
END | |
MODULE('api') | |
OutputDebugString(*CSTRING cMsg),PASCAL,DLL(1),RAW,NAME('OutputDebugStringA') | |
DebugBreak(),PASCAL,DLL(1) !If running under Debug forces the debugger to popup... eaiser to use ASSERT() | |
GetLastError(),LONG,PASCAL,DLL(1) | |
END | |
END | |
CODE | |
MAIN() | |
RETURN | |
!---------------------------- | |
Main PROCEDURE | |
Window WINDOW('Scratch '),AT(,,400,200),CENTER,GRAY,IMM,SYSTEM,STATUS,FONT('Segoe UI',9),RESIZE | |
BUTTON('Button1'),AT(155,180),USE(?Button1) | |
BUTTON('Button2'),AT(206,180),USE(?Button2) | |
END | |
CODE | |
OPEN(WINDOW) | |
0{PROP:text}=clip(0{PROP:text}) &' - Library ' & system{PROP:LibVersion,2} &'.'& system{PROP:LibVersion,3} | |
ACCEPT | |
CASE EVENT() | |
OF EVENT:OpenWindow | |
OF EVENT:CloseWindow | |
OF EVENT:PreAlertKey | |
OF EVENT:AlertKey | |
OF EVENT:Timer | |
END | |
CASE ACCEPTED() | |
! OF ?Button1 | |
! OF ?Button2 | |
END | |
CASE FIELD() | |
! OF ?Button1 | |
! OF ?Button2 | |
END | |
END | |
CLOSE(WINDOW) | |
!=============================== | |
Hex8 PROCEDURE(LONG Lng)!,STRING | |
LngAdj LONG,AUTO,STATIC | |
L BYTE,DIM(4),OVER(LngAdj) | |
Hex STRING('0123456789ABCDEF'),STATIC | |
HX STRING(9),AUTO,STATIC | |
CODE | |
LngAdj = BAND(BSHIFT(Lng, -4),0F0F0F0Fh) + 01010101h | |
HX[1]=HEX[L[4]] ; HX[3]=HEX[L[3]] ; HX[5]=HEX[L[2]] ; HX[7]=HEX[L[1]] | |
LngAdj=BAND(Lng,0F0F0F0Fh) + 01010101h | |
HX[2]=HEX[L[4]] ; HX[4]=HEX[L[3]] ; HX[6]=HEX[L[2]] ; HX[8]=HEX[L[1]] ; HX[9]='h' | |
RETURN HX | |
!=============================== | |
DB PROCEDURE(STRING xMessage) | |
Prfx EQUATE('Scratch: ') | |
sz CSTRING(SIZE(Prfx)+SIZE(xMessage)+1),AUTO | |
CODE | |
sz = Prfx & CLIP(xMessage) | |
OutputDebugString( sz ) | |
!------------------ | |
DBClear PROCEDURE() | |
DbgClear CSTRING('DBGVIEWCLEAR') !Message to Clear the buffer. Must UPPER and first i.e. without a Prefix | |
CODE | |
OutputDebugString(DbgClear) !Cannot have Prefix, must be first .. so call API directly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PROGRAM !Scratch_LIST program by Carl Barnes - Version 9/2/2022 - Download https://git.io/JtPKE | |
!Sometimes you want to right a quick bit of code to test a LIST control. | |
!This Scratch program fills a ScratchQ with a Directory from Windows Temp folder so you have some data to test with. | |
INCLUDE('TplEqu.CLW') | |
INCLUDE('KeyCodes.CLW') | |
MAP | |
Main PROCEDURE() | |
DB PROCEDURE(STRING DebugMessage) | |
DBClear PROCEDURE() !Clear DebugView Buffer | |
Hex8 PROCEDURE(LONG LongInt),STRING | |
MODULE('RTL') | |
!LenFastClip PROCEDURE(CONST *STRING Text2Measure),LONG,NAME('Cla$FASTCLIP'),DLL(dll_mode) Fails in Release mode, bad idea | |
ClaFieldNameRTL PROCEDURE(LONG pFEQ),CSTRING,RAW,NAME('Cla$FIELDNAME'),DLL(dll_mode) | |
ClaEventNameRTL PROCEDURE(LONG EventPlusA000h),*CSTRING,RAW,NAME('WslDebug$MsgName'),DLL(dll_mode) | |
C5LogSetName PROCEDURE(CONST *CSTRING),NAME('WslDebug$SetLogFile'),DLL(dll_mode) | |
C5LogPrint PROCEDURE(STRING),NAME('WslDebug$Print'),DLL(dll_mode) | |
C5LogPrintEvent PROCEDURE(),NAME('WslDebug$PrintEvent'),DLL(dll_mode) !E.g. Event: EVENT:Accepted ?WSLDEBUGPRINT_BTN (10) | |
END | |
MODULE('api') | |
GetTempPath(LONG nBufferLength,*CSTRING lpTempPath),LONG,PROC,PASCAL,RAW,DLL(1),NAME('GetTempPathA') | |
OutputDebugString(*CSTRING cMsg),PASCAL,RAW,DLL(1),NAME('OutputDebugStringA') | |
DebugBreak(),PASCAL,DLL(1) !If running under Debug forces the debugger to popup... eaiser to use ASSERT() | |
GetLastError(),LONG,PASCAL,DLL(1) | |
END | |
END | |
WinTempPathBS CSTRING(256) | |
CODE | |
IF ~GetTempPath(SIZE(WinTempPathBS),WinTempPathBS) THEN Message('GetTempPath() Error '& GetLastError(),'Scratch_LIST'). | |
MAIN() | |
RETURN | |
!---------------------------- | |
Main PROCEDURE | |
ScratchQ QUEUE,PRE(ScrQ) | |
Name STRING(260) !ScrQ:Name | |
ShortName STRING(13) !ScrQ:ShortName | |
Date LONG !ScrQ:Date | |
Time LONG !ScrQ:Time | |
Size LONG !ScrQ:Size | |
Attrib BYTE !ScrQ:Attrib | |
END | |
!#FIELDS(ScrQ:Name, ScrQ:ShortName, ScrQ:Date, ScrQ:Time, ScrQ:Size, ScrQ:Attrib) | |
QNdx LONG,AUTO | |
Window WINDOW('Scratch_LIST '),AT(,,400,200),CENTER,GRAY,IMM,SYSTEM,STATUS,FONT('Segoe UI',9),RESIZE | |
BUTTON('Button1'),AT(316,3),USE(?Button1) | |
BUTTON('Button2'),AT(358,3),USE(?Button2) | |
ENTRY(@s255),AT(2,4,300),USE(WinTempPathBS),SKIP,COLOR(COLOR:BTNFACE),READONLY | |
LIST,AT(2,21),FULL,USE(?List:ScratchQ),VSCROLL,FROM(ScratchQ), | | |
FORMAT('180L(2)|M~Name~L(2)@s255@' &| | |
'54L(2)|M~ShortName~L(2)@s13@' &| | |
'[' &| | |
'46R(2)|M~Date~C(0)@d8@' &| | |
'34R(2)|M~Time~C(0)@t7@' &| | |
']~Last Modified~' &| | |
'48R(2)|M~Size~C(0)@n-14@' &| | |
'20R(2)|M~Attrib~C(0)@n3@') | |
END | |
CODE | |
OPEN(WINDOW) | |
0{PROP:text}=clip(0{PROP:text}) &' - Library ' & system{PROP:LibVersion,2} &'.'& system{PROP:LibVersion,3} | |
DISPLAY | |
DO Fill_ScratchQ_Rtn | |
ACCEPT | |
CASE EVENT() | |
OF EVENT:OpenWindow | |
OF EVENT:CloseWindow | |
OF EVENT:PreAlertKey | |
OF EVENT:AlertKey | |
OF EVENT:Timer | |
END | |
CASE ACCEPTED() | |
! OF ?Button1 | |
! OF ?Button2 | |
OF ?LIST:ScratchQ | |
GET(ScratchQ,CHOICE(?LIST:ScratchQ)) | |
END | |
CASE FIELD() | |
! OF ?Button1 | |
! OF ?Button2 | |
OF ?LIST:ScratchQ | |
GET(ScratchQ,CHOICE(?LIST:ScratchQ)) | |
CASE EVENT() | |
OF EVENT:NewSelection | |
CASE KEYCODE() | |
OF MouseLeft2 !Double Click | |
Message(CLIP(ScrQ:Name) &'|'& CLIP(ScrQ:ShortName) & | | |
'||Last Mod: '& FORMAT(ScrQ:Date,@d8) &' '& FORMAT(ScrQ:Time,@t7) &'|Size: '& ScrQ:Size, | | |
'List Row '& POINTER(ScratchQ)) | |
OF MouseRight | |
SETKEYCODE(0) | |
CASE POPUP('Copy File Name|Copy Short Name') | |
OF 1 ; SETCLIPBOARD(ScrQ:Name) | |
OF 2 ; SETCLIPBOARD(ScrQ:ShortName) | |
END | |
END !KeyCodes | |
END !New Selection on List | |
END !Field | |
END | |
CLOSE(WINDOW) | |
Fill_ScratchQ_Rtn ROUTINE | |
DATA | |
DirQ QUEUE(FILE:Queue),PRE(DirQ) | |
END ! DirQ:Name DirQ:ShortName(8.3?) DirQ:Date DirQ:Time DirQ:Size DirQ:Attrib | |
CODE | |
FREE(ScratchQ) | |
DIRECTORY(DirQ,WinTempPathBS&'*.*',ff_:NORMAL+ff_:DIRECTORY) | |
LOOP QNdx=1 TO RECORDS(DirQ) | |
GET(DirQ,QNdx) | |
!IF DirQ:Name='.' OR DirQ:Name='..' THEN CYCLE. | |
IF BAND(DirQ:Attrib,ff_:DIRECTORY) THEN DirQ:ShortName='<DIR>'. | |
CLEAR(ScratchQ) | |
ScratchQ :=: DirQ | |
ADD(ScratchQ) | |
END | |
EXIT | |
!=============================== | |
Hex8 PROCEDURE(LONG Lng)!,STRING | |
LngAdj LONG,AUTO,STATIC | |
L BYTE,DIM(4),OVER(LngAdj) | |
Hex STRING('0123456789ABCDEF'),STATIC | |
HX STRING(9),AUTO,STATIC | |
CODE | |
LngAdj = BAND(BSHIFT(Lng, -4),0F0F0F0Fh) + 01010101h | |
HX[1]=HEX[L[4]] ; HX[3]=HEX[L[3]] ; HX[5]=HEX[L[2]] ; HX[7]=HEX[L[1]] | |
LngAdj=BAND(Lng,0F0F0F0Fh) + 01010101h | |
HX[2]=HEX[L[4]] ; HX[4]=HEX[L[3]] ; HX[6]=HEX[L[2]] ; HX[8]=HEX[L[1]] ; HX[9]='h' | |
RETURN HX | |
!=============================== | |
DB PROCEDURE(STRING xMessage) | |
Prfx EQUATE('Scratch: ') | |
sz CSTRING(SIZE(Prfx)+SIZE(xMessage)+1),AUTO | |
CODE | |
sz = Prfx & CLIP(xMessage) | |
OutputDebugString( sz ) | |
!------------------ | |
DBClear PROCEDURE() | |
DbgClear CSTRING('DBGVIEWCLEAR') !Message to Clear the buffer. Must UPPER and first i.e. without a Prefix | |
CODE | |
OutputDebugString(DbgClear) !Cannot have Prefix, must be first .. so call API directly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PROGRAM !Scratch Lite program by Carl Barnes - Version 9/1/2022 - Download https://git.io/JtPKE | |
INCLUDE('TplEqu.CLW') | |
INCLUDE('KeyCodes.CLW') | |
MAP | |
Main PROCEDURE() | |
DB PROCEDURE(STRING DebugMessage) | |
MODULE('api') | |
OutputDebugString(*CSTRING cMsg),PASCAL,DLL(1),RAW,NAME('OutputDebugStringA') | |
END | |
END | |
CODE | |
MAIN() | |
RETURN | |
!---------------------------- | |
Main PROCEDURE | |
Window WINDOW('Scratch '),AT(,,400,200),CENTER,GRAY,IMM,SYSTEM,STATUS,FONT('Segoe UI',9),RESIZE | |
BUTTON('Button1'),AT(155,180),USE(?Button1) | |
BUTTON('Button2'),AT(206,180),USE(?Button2) | |
END | |
CODE | |
OPEN(WINDOW) | |
0{PROP:text}=clip(0{PROP:text}) &' - Library ' & system{PROP:LibVersion,2} &'.'& system{PROP:LibVersion,3} | |
ACCEPT | |
CASE EVENT() | |
OF EVENT:OpenWindow | |
OF EVENT:CloseWindow | |
OF EVENT:PreAlertKey | |
OF EVENT:AlertKey | |
OF EVENT:Timer | |
END | |
CASE ACCEPTED() | |
! OF ?Button1 | |
! OF ?Button2 | |
END | |
CASE FIELD() | |
! OF ?Button1 | |
! OF ?Button2 | |
END | |
END | |
CLOSE(WINDOW) | |
!=============================== | |
DB PROCEDURE(STRING xMessage) | |
Prfx EQUATE('Scratch: ') | |
sz CSTRING(SIZE(Prfx)+SIZE(xMessage)+1),AUTO | |
CODE | |
sz = Prfx & CLIP(xMessage) | |
OutputDebugString( sz ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment