home *** CD-ROM | disk | FTP | other *** search
/ PSION CD 2 / PsionCDVol2.iso / Programs / 185 / CAT.SIS / Cat (.txt) < prev    next >
Encoding:
EPOC OPL Source  |  1998-08-12  |  12.2 KB  |  471 lines

  1.  
  2.  
  3. APP Cat, 268437309    REM Reserved uid. Do not use for other apps
  4.     CAPTION "Cat", 1
  5.     ICON "CatIcon.mbm"
  6. ENDA
  7.  
  8. REM Cat.opl Released as public domain January 1998
  9. REM Feel free to use any routines in this file.
  10.  
  11. REM VARIABLE NAMING CONVENTION.
  12. REM Constants are prefixed with K
  13. REM Global variables are prefixed with G
  14. REM Recived procedure parameters are prefixed with P
  15. REM All other variables are local
  16.  
  17. REM Cat.mbm contains 28 bitmaps. Each one is loaded in turn to
  18. REM create an animation.
  19.  
  20. INCLUDE "CONST.OPH"
  21.  
  22. CONST KMenuKeyPressed% = 148
  23. CONST KCloseApp% = -1
  24.  
  25. CONST Kx = 25            REM Top left position of cat window
  26. CONST Ky = 80
  27.  
  28. CONST KCatSpeed = 2    REM Lower value for faster cat. Do not set to zero. Default 2
  29.  
  30. DECLARE EXTERNAL
  31. EXTERNAL GetFileNameAndExtension$:(PFileName$)
  32. EXTERNAL GetNumberOfBitmapsInMbm&:(MbmName$)
  33. EXTERNAL GetBitmapWidth&:(PMbmName$, PBitmapNumber%)
  34. EXTERNAL GetBitmapHeight&:(PMbmName$, PBitmapNumber%)
  35. EXTERNAL HideDefaultWindow:
  36. EXTERNAL CreateCatWindow%:(Px%, Py%, PWidth&, PHeight&)
  37. EXTERNAL ShowBitmap:(FileName$, BitmapIndex%, WindowId%, X%, Y%)
  38. EXTERNAL CheckForEvent:
  39. EXTERNAL ClearKeyboardBuffer:
  40. EXTERNAL ShowMenu:
  41. EXTERNAL GetAppPath$:
  42. EXTERNAL ReportFileMissingToUser:(PFileName$, PAdvise1$, PAdvise2$, PAdvise3$)
  43. EXTERNAL ReportErrorToUser:(DialogTitle$, PErrorCode&)
  44. EXTERNAL About:
  45. EXTERNAL ExitProgram:
  46.  
  47.  
  48. PROC Main:
  49.     LOCAL MbmName$(255)
  50.     
  51.     LOCAL CatWindow%
  52.     
  53.     LOCAL BitmapIndex%
  54.     LOCAL NumberOfBitmapsInFile&
  55.     LOCAL BitmapWidth&
  56.     LOCAL BitmapHeight&
  57.     
  58.     MbmName$ = GetAppPath$: + "Cat.mbm"
  59.     
  60.     rem--------------------------------------
  61.     REM This section gets details about cat.mbm
  62.     rem--------------------------------------
  63.     
  64.     IF NOT EXIST(MbmName$)
  65.         ReportFileMissingToUser:(GetFileNameAndExtension$:(MbmName$), "Place Cat.app and Cat.mbm", "in the same folder", "")
  66.         ExitProgram:
  67.     ENDIF
  68.     
  69.     BitmapIndex% = 1
  70.     
  71.     NumberOfBitmapsInFile& = GetNumberOfBitmapsInMbm&:(MbmName$)
  72.     
  73.     IF NumberOfBitmapsInFile& < 0
  74.         ReportErrorToUser:("Error opening cat.mbm", NumberOfBitmapsInFile&)
  75.         ExitProgram:
  76.     ENDIF
  77.     
  78.     BitmapWidth& = GetBitmapWidth&:(MbmName$, BitmapIndex%)
  79.     
  80.     BitmapHeight& = GetBitmapHeight&:(MbmName$, BitmapIndex%)
  81.     
  82.     rem--------------------------------------
  83.     REM This section sets up the screen
  84.     rem--------------------------------------
  85.     
  86.     HideDefaultWindow:
  87.     
  88.     CatWindow% = CreateCatWindow%:(Kx, Ky, BitmapWidth&, BitmapHeight&)
  89.     
  90.     WHILE 1
  91.         
  92.         rem--------------------------------------
  93.         REM Start with first bitmap in file
  94.         rem--------------------------------------
  95.         
  96.         BitmapIndex% = 1
  97.         
  98.         WHILE BitmapIndex% < NumberOfBitmapsInFile&
  99.  
  100.             rem--------------------------------------
  101.             REM This procedure checks for system 
  102.             REM messages and key presses
  103.             rem--------------------------------------
  104.             
  105.             CheckForEvent:
  106.             
  107.             rem--------------------------------------
  108.             REM This section displays the next bitmap
  109.             rem--------------------------------------
  110.             
  111.             ShowBitmap:(GetAppPath$: + "Cat.mbm", BitmapIndex%, CatWindow%, 0, 0)
  112.  
  113.             BitmapIndex% = BitmapIndex% + 1
  114.             
  115.             rem--------------------------------------
  116.             REM Increase or decrease PAUSE to adjust speed
  117.             rem--------------------------------------
  118.             
  119.             PAUSE KCatSpeed
  120.             
  121.         ENDWH
  122.     ENDWH
  123. ENDP
  124.  
  125. rem--------------------------------------
  126. REM This function returns a filename and extension
  127. REM from a full file path specification
  128. REM Called from Main:
  129. rem--------------------------------------
  130. PROC GetFileNameAndExtension$:(PFileName$)
  131.     LOCAL Off%(6)
  132.     LOCAL FileName$(33)
  133.     LOCAL Extension$(4)
  134.     
  135.     FileName$ = MID$(PARSE$(PFileName$, PFileName$, Off%()), Off%(4), Off%(5) - Off%(4))
  136.     Extension$ = MID$(PARSE$(PFileName$, PFileName$, Off%()), Off%(5), 4)
  137.     
  138.     RETURN FileName$ + Extension$
  139. ENDP
  140.  
  141.  
  142. rem--------------------------------------
  143. REM returns the number of bitmaps in an mbm PMbmName$
  144. REM or < 0 = error number
  145. REM Called from Main:
  146. rem--------------------------------------
  147. PROC GetNumberOfBitmapsInMbm&:(PMbmName$)
  148.     LOCAL FileHandle%
  149.     LOCAL CheckForError&
  150.     LOCAL OffsetToInfoTable&
  151.     LOCAL OffsetOfInfoTable&
  152.     LOCAL NumberOfBitmaps&
  153.     
  154.     CheckForError& = IOOPEN(FileHandle%, PMbmName$, $0600)
  155.     
  156.     rem--------------------------------------
  157.     REM Error opening file
  158.     rem--------------------------------------
  159.     IF CheckForError&
  160.         IOCLOSE(FileHandle%)
  161.         RETURN CheckForError&
  162.     ENDIF
  163.     
  164.     OffsetToInfoTable& = 16
  165.     
  166.     IOSEEK(FileHandle%, 1, OffsetToInfoTable&)
  167.     IOREAD(FileHandle%, ADDR(OffsetOfInfoTable&), 4)
  168.     IOSEEK(FileHandle%, 1, OffsetOfInfoTable&)
  169.     IOREAD(FileHandle%, ADDR(NumberOfBitmaps&), 4)
  170.     IOCLOSE(FileHandle%)
  171.     
  172.     RETURN NumberOfBitmaps&
  173. ENDP
  174.  
  175.  
  176. rem--------------------------------------
  177. REM Returns the width of bitmap number
  178. REM PBitmapNumber% in an mbm file PMbmName$
  179. REM Called from Main:
  180. rem--------------------------------------
  181. PROC GetBitmapWidth&:(PMbmName$, PBitmapNumber%)
  182.     LOCAL CheckForError&
  183.     LOCAL FileHandle%
  184.  
  185.     LOCAL OffsetOfPointerToInfoTable&
  186.     LOCAL OffsetOfInfoTable&
  187.     LOCAL OffsetOfPointerToBitmapRecord&
  188.     LOCAL OffsetOfBitmapRecord&
  189.     
  190.     LOCAL NumberOfBitmaps&
  191.     LOCAL BitmapWidth&
  192.     
  193.     CheckForError& = IOOPEN(FileHandle%, PMbmName$, $0600)
  194.     
  195.     rem--------------------------------------
  196.     REM Error opening file
  197.     rem--------------------------------------
  198.     IF CheckForError&
  199.         IOCLOSE(FileHandle%)
  200.         RETURN CheckForError&
  201.     ENDIF
  202.     
  203.     rem--------------------------------------
  204.     REM This section checks that PBitmapNumber%
  205.     REM is not greater than the number of bitmaps
  206.     REM in the file
  207.     rem--------------------------------------
  208.     
  209.     OffsetOfPointerToInfoTable& = 16
  210.     
  211.     IOSEEK(FileHandle%, 1, OffsetOfPointerToInfoTable&)
  212.     IOREAD(FileHandle%, ADDR(OffsetOfInfoTable&), 4)
  213.     IOSEEK(FileHandle%, 1, OffsetOfInfoTable&)
  214.     IOREAD(FileHandle%, ADDR(NumberOfBitmaps&), 4)
  215.     
  216.     rem--------------------------------------
  217.     REM Return code for general failure
  218.     REM if bitmaps less than PBitmapNumber%
  219.     rem--------------------------------------
  220.     IF NumberOfBitmaps& < PBitmapNumber%
  221.         RETURN -1
  222.     ENDIF
  223.     
  224.     rem--------------------------------------
  225.     REM This section returns the width
  226.     REM of bitmap number PBitmapNumber%
  227.     rem--------------------------------------
  228.     
  229.     OffsetOfPointerToBitmapRecord& = OffsetOfInfoTable& + (PBitmapNumber% * 4)
  230.     IOSEEK(FileHandle%, 1, OffsetOfPointerToBitmapRecord&)
  231.     IOREAD(FileHandle%, ADDR(OffsetOfBitmapRecord&), 4)
  232.     OffsetOfBitmapRecord& = OffsetOfBitmapRecord& + 8
  233.     IOSEEK(FileHandle%, 1, OffsetOfBitmapRecord&)
  234.     IOREAD(FileHandle%, ADDR(BitmapWidth&), 4)
  235.     IOCLOSE(FileHandle%)
  236.     
  237.     RETURN BitmapWidth&
  238. ENDP
  239.  
  240.  
  241. rem--------------------------------------
  242. REM Returns the height of bitmap number
  243. REM PBitmapNumber% in an mbm file PMbmName$
  244. REM Called from Main:
  245. rem--------------------------------------
  246. PROC GetBitmapHeight&:(PMbmName$, PBitmapNumber%)
  247.     LOCAL CheckForError&
  248.     LOCAL FileHandle%
  249.     
  250.     LOCAL OffsetOfPointerToInfoTable&
  251.     LOCAL OffsetOfInfoTable&
  252.     LOCAL OffsetOfPointerToBitmapRecord&
  253.     LOCAL OffsetOfBitmapRecord&
  254.     
  255.     LOCAL NumberOfBitmaps&
  256.     LOCAL BitmapHeight&
  257.     
  258.     CheckForError& = IOOPEN(FileHandle%, PMbmName$, $0600)
  259.     
  260.     rem--------------------------------------
  261.     REM Error opening file
  262.     rem--------------------------------------
  263.     IF CheckForError&
  264.         IOCLOSE(FileHandle%)
  265.         RETURN CheckForError&
  266.     ENDIF
  267.     
  268.     rem--------------------------------------
  269.     REM This section checks that PBitmapNumber%
  270.     REM is not greater than the number of bitmaps
  271.     REM in the file
  272.     rem--------------------------------------
  273.     
  274.     OffsetOfPointerToInfoTable& = 16
  275.     
  276.     IOSEEK(FileHandle%, 1, OffsetOfPointerToInfoTable&)
  277.     IOREAD(FileHandle%, ADDR(OffsetOfInfoTable&), 4)
  278.     IOSEEK(FileHandle%, 1, OffsetOfInfoTable&)
  279.     IOREAD(FileHandle%, ADDR(NumberOfBitmaps&), 4)
  280.     
  281.     rem--------------------------------------
  282.     REM Return code for general failure
  283.     REM if bitmaps less than PBitmapNumber%
  284.     rem--------------------------------------
  285.     IF NumberOfBitmaps& < PBitmapNumber%
  286.         RETURN -1
  287.     ENDIF
  288.     
  289.     rem--------------------------------------
  290.     REM This section returns the height
  291.     REM of bitmap number PBitmapNumber%
  292.     rem--------------------------------------
  293.     
  294.     OffsetOfPointerToBitmapRecord& = OffsetOfInfoTable& + (PBitmapNumber% * 4)
  295.     IOSEEK(FileHandle%, 1, OffsetOfPointerToBitmapRecord&)
  296.     IOREAD(FileHandle%, ADDR(OffsetOfBitmapRecord&), 4)
  297.     OffsetOfBitmapRecord& = OffsetOfBitmapRecord& + 12
  298.     IOSEEK(FileHandle%, 1, OffsetOfBitmapRecord&)
  299.     IOREAD(FileHandle%, ADDR(BitmapHeight&), 4)
  300.     IOCLOSE(FileHandle%)
  301.     
  302.     RETURN BitmapHeight&
  303. ENDP
  304.  
  305.  
  306. rem--------------------------------------
  307. REM Called from Main:
  308. rem--------------------------------------
  309. PROC HideDefaultWindow:
  310.     gUSE 1
  311.     gSETWIN 0, 0, 0, 0
  312.     rem gVISIBLE OFF
  313. ENDP
  314.  
  315.  
  316. rem--------------------------------------
  317. REM Called from Main:
  318. rem--------------------------------------
  319. PROC CreateCatWindow%:(Px%, Py%, PWidth&, PHeight&)
  320.     LOCAL CatWindow%
  321.     CatWindow% = gCREATE(Px%, Py%, PWidth&, PHeight&, KgCreateVisible%, KgCreate4ColourMode%)
  322.     RETURN CatWindow%
  323. ENDP
  324.  
  325.  
  326. rem--------------------------------------
  327. REM loads an MBM PFileName$ into window PWindowId%
  328. REM Bitmap number PBitmapIndex% at PX%, PY%
  329. REM Replacing any bitmap already there
  330. REM Called from Main:
  331. rem--------------------------------------
  332. PROC ShowBitmap:(PFileName$, PBitmapIndex%, PWindowId%, PX%, PY%)
  333.     LOCAL BitmapId%
  334.     LOCAL BitmapWidth%
  335.     LOCAL BitmapHeight%
  336.     
  337.     BitmapId% = gLOADBIT(PFileName$, KgLoadBitReadOnly%, PBitmapIndex%)
  338.     
  339.     BitmapWidth% = gWIDTH
  340.     BitmapHeight% = gHEIGHT
  341.     
  342.     gUSE PWindowId%
  343.     
  344.     gAT PX%, PY%
  345.     gCOPY BitmapId%, 0, 0, BitmapWidth%, BitmapHeight%, KtModeReplace%
  346.     
  347.     gCLOSE BitmapId%
  348. ENDP
  349.  
  350.  
  351. rem--------------------------------------
  352. REM This procedure checks whether a 'Close file'
  353. REM message has been received from the system
  354. REM or whether a key has been pressed
  355. REM Called from Main:
  356. rem--------------------------------------
  357. PROC CheckForEvent:
  358.     LOCAL ev&(16)
  359.     LOCAL Status%
  360.     
  361.     ClearKeyboardBuffer:
  362.     
  363.     GETEVENTA32 Status%, ev&()
  364.     IF ev&(1) = KEvCommand&
  365.         ExitProgram:
  366.     ELSEIF (ev&(3) = 69) AND (ev&(4) = KKmodControl%)
  367.         ExitProgram:
  368.     ELSEIF (ev&(3) = 69) AND (ev&(4) = KKmodControl% + KKmodCaps%)
  369.         ExitProgram:
  370.     ELSEIF (ev&(3) = 65) AND (ev&(4) = KKmodControl%)
  371.         About:
  372.     ELSEIF (ev&(3) = 65) AND (ev&(4) = KKmodControl% + KKmodCaps%)
  373.         About:
  374.     ELSEIF ev&(3) = KMenuKeyPressed%
  375.         ShowMenu:
  376.     ENDIF
  377. ENDP
  378.  
  379.  
  380. rem--------------------------------------
  381. REM Need to call this procedure for
  382. REM GETEVENTA32 to work. Don't know why !
  383. REM Called from CheckForEvent%:
  384. rem--------------------------------------
  385. PROC ClearKeyboardBuffer:
  386.     WHILE KEY
  387.     ENDWH
  388. ENDP
  389.  
  390.  
  391. rem--------------------------------------
  392. REM Called from CheckForEvent:
  393. rem--------------------------------------
  394. PROC ShowMenu:
  395.     LOCAL MenuItem%
  396.     mINIT
  397.     mCARD "Cat","About Cat",%a,"Close",%e
  398.     MenuItem% = MENU
  399.     IF MenuItem% = %a
  400.         About:
  401.     ELSEIF MenuItem% = %e
  402.         ExitProgram:
  403.     ENDIF
  404. ENDP
  405.  
  406.  
  407. rem--------------------------------------
  408. REM GetAppPath$: returns the path of
  409. REM the running application or opo
  410. REM Called from Main:
  411. rem--------------------------------------
  412. PROC GetAppPath$:
  413.     LOCAL off%(6)
  414.     RETURN LEFT$(PARSE$("",CMD$(1),off%()),off%(4) - 1)
  415. ENDP
  416.  
  417.  
  418. rem--------------------------------------
  419. REM Called from Main:
  420. rem--------------------------------------
  421. PROC ReportFileMissingToUser:(PFileName$, PAdvise1$, PAdvise2$, PAdvise3$)
  422.     dINIT PFileName$ + " not found"
  423.     dTEXT "",PAdvise1$
  424.     dTEXT "",PAdvise2$
  425.     dBUTTONS "Ok",13
  426.     DIALOG
  427. ENDP
  428.  
  429.  
  430. rem--------------------------------------
  431. REM Called from Main:
  432. rem--------------------------------------
  433. PROC ReportErrorToUser:(DialogTitle$, PErrorCode&)
  434.     dINIT DialogTitle$
  435.     dTEXT "","The following error has occurred"
  436.     dTEXT ""," "
  437.     dTEXT "",ERR$(PErrorCode&)
  438.     dTEXT ""," "
  439.     dBUTTONS "Ok",13
  440.     DIALOG
  441. ENDP
  442.  
  443.  
  444. rem--------------------------------------
  445. REM Called from ShowMenu:
  446. rem--------------------------------------
  447. PROC About:
  448.     dINIT "            About Cat V1.0"
  449.     dTEXT "","     ┬⌐ Richard Wakelin 1998"
  450.     dTEXT "","      Released as freeware"
  451.     dTEXT "","                 Email"
  452.     dTEXT ""," rbenno@cix.compulink.co.uk."
  453.     dTEXT "","106305,466@compuserve.com"
  454.     dTEXT "","                  Web"
  455.     dTEXT "","http://ourworld/compuserve.com"
  456.     dTEXT "","       /homepages/RWakelin"
  457.     rem dBUTTONS "Ok",13
  458.     DIALOG
  459. ENDP
  460.  
  461.  
  462. rem--------------------------------------
  463. REM Called from CheckForEvent%: and ShowMenu:
  464. rem--------------------------------------
  465. PROC ExitProgram:
  466.     REM Place any clean up code here
  467.     STOP
  468. ENDP
  469.  
  470.  
  471.