Help from experienced machine code programmers

Use this section to showcase your programming examples. Or to ask members for programming suggestions
Post Reply
User avatar
Martin
Global Admin
Posts: 220
Joined: Mon Jan 02, 2023 5:18 pm

Help from experienced machine code programmers

Post by Martin »

Looking for some advice from our machine code programmers...
  • As you may have read I'm reviewing the TRAVEL PACK (here)
  • I've used Jaap's REVTRAN to reverse translate the OB3's back to OPL's.
  • In the process I found a routine that calls ROM functions from the Top Level Menu. I want to say system services but I'm not sure that is correct.
I once read in the technical reference manual I think that calling these services from OPL for example the CALCulator can be problematic as the 'RETURN' can crash the machine.

This example below TIMERTN: works though the top level menu looking for the 'time' utility then calls it and once the user has updated the time it returns successfully to the calling OPL routine.

The routine in question
Can anyone shed light on what exactly is going on!
NOTE I've added the code next to the REM's to help me 'watch' the variables,

Code: Select all

timertn:
REM CM/XP procedure
REM Old globals: OFFSET%
LOCAL L1%,L2%,L3%,L4$(4),L5%(2)

                     :REM lines added to aid testing
LOCAL OFFSET%        :REM Include this global variable
OFFSET%=0            :REM Try 0 and 1 to see difference

L2%=PEEKW(8194)
CURSOR OFF
IF OFFSET%=1
 L5%(1)=16292         :REM what's at addresses
 L5%(2)=14592         :REM 16292 and 14592
 USR(ADDR(L5%()),1)
 RETURN
ENDIF
DO
 L1%=PEEKB(L2%)
 IF L1%=0
  RETURN 1
 ENDIF
 IF L1%=4
  L4$=""
  L3%=1
  DO
   L4$=L4$+CHR$(PEEKB(L2%+L3%))
   L3%=L3%+1
   PRINT L4$,PEEKB(L2%+L3%)  :REM Added to
   GET                       :REM Watch variable
  UNTIL L3%=5
  IF L4$="TIME" OR L4$="DATE" OR L4$="ZEIT"
   USR(PEEKW(L2%+L1%+1),0)
   RETURN
  ENDIF
 ENDIF
 L2%=L2%+L1%+3
UNTIL 0
EXAMPLE of output from running TIMERTN

Code: Select all

LZ Main Menu
Hlog   Find    Save
Diary  Calc    Time
Notes  World   Alarm

[Prog][Run]TIMERTN
H 76
HL 79
HLO 71
HLOG 0
F 73
FI 78
FIN 68
FIND 201
S 65
SA 86
SAV 69
SAVE 201
C 65
CA 76
CAL 67
CALC 201
T 73
TI 77
TIM 69
TIME 201
If I [DEL]ete the [Time] function from the menu it 'jumps' into the [Prog] menu..
If I reinstate the [Time] finction in position 1 it runs and jumps straight into the [Time] function.
It is definitely scanning the top level menu and looking for "TIME" (English) "DATE" (French) OR "ZEIT" (German)

Any help will be appreciated..
Sincerely Martin
User avatar
Martin
Global Admin
Posts: 220
Joined: Mon Jan 02, 2023 5:18 pm

Help from experienced machine code programmers

Post by Martin »

More investigation

I'm still trying to get to the bottom of how the program above works.

I'm checking the republished Technical Reference Manual I found..

(1) the warning about calling the CALCulator from OPL... I tried it by changing 'TIME' to 'CALC' in the program. Sure anough it entered the Calculator which worked fine.. then when ON/CLEARing out of it the Organiser crashed with a [TRAP] error.. Only solution was battery out - cold reset.
.
TechRef_CalcWarning_P115.png
.
(2) a note about entry points to top-level applications and a pointer to the program above 'look up the entry points in the menucell' wherever that is!
.
TechRef_Calling_P115.png
.
(3) if someone could direct me to information about how I call these 'system services' from OPL then there are a couple I would like to experiment with...
.
TechRef_NotePad_P116.png
TechRef_Sorting_P109.png
.
Again sincerely Martin
You do not have the required permissions to view the files attached to this post.
User avatar
Martin
Global Admin
Posts: 220
Joined: Mon Jan 02, 2023 5:18 pm

Managed a work-a-round

Post by Martin »

How does it go again... If at first you don't succeed etc. etc..

I haven't managed to use the NT$ENTR entry point outlinned above but have managed to adapt the TIMERTN routine to do the menu search work-a-round as outlinned in the snippets (here)..

Sincerely
Martin

PS if anyone does know how to use the 'recommended' entry points I'm still interested to learn.
MartinP
Posts: 46
Joined: Wed Jan 04, 2023 7:51 pm

Re: Help from experienced machine code programmers

Post by MartinP »

Here's an example of using the entry point:

Code: Select all

SYSCALL:
REM system service call example for LZ
LOCAL A%(3)
PRINT "** NOTEPAD **"
GET
A%(1)=$C601         :REM LDAB #1  load B with 1, Function 1: call notepad as if top menu option chosen
A%(2)=$3F9F         :REM SWI 9F   software interrupt, call system service $9F NT$ENTR
A%(3)=$3901         :REM RTS, NOP Return from subroutine, no operation
USR(ADDR(A%()),0)   :REM run the machine code stored in A%
CLS
PRINT "BACK TO OPL"
GET
Seems you have to press ON/CLEAR twice to get out of Notepad, not sure why.

And to answer one of your questions: The menu cell is the menu data stored at address $2002 (8194 in decimal). It's the table that TIMERTN is reading.

MartinP
User avatar
Martin
Global Admin
Posts: 220
Joined: Mon Jan 02, 2023 5:18 pm

machine code - Got it thanks

Post by Martin »

Fantastic as always Martin... It is certainly less code than than examining the menu cell above...

Yes it also takes two [ON/CLEAR]'s to return when using the method above.. If you watch carefully the first press turns the cursor off then the next returns... It does it with them all Diary, XFiles, Utils - first the cursor then return.

Also the method above puts 'Notepad' in the buffer.

For the utility I'm considering I'd like to provide 'in program' access to other top level menu items... Can you help with the hex values for them?

Notes (got thanks)
Diary
xFiles
xFiles Sort (or by passing a file name to XF$SORT)
Utils
Utils Dir
Utils Info
and possibly
Save &
Find

You'll also see that I've posted a question about peeking a pack to see if it is a Rampack... I want the file handler to have access to Rampaks but not flash or Datapaks.

Again thanks for your help
Sincerely Martin
MartinP
Posts: 46
Joined: Wed Jan 04, 2023 7:51 pm

Re: Help from experienced machine code programmers

Post by MartinP »

Have a look here, it should provide some answers:
https://www.jaapsch.net/psion/mcoslz.htm#toplevel
I think most of what you need is on Jaap’s site, but it’s all spread about on a number of different pages, so it’s somewhat of a puzzle to piece it together.
Martin P.
User avatar
Martin
Global Admin
Posts: 220
Joined: Mon Jan 02, 2023 5:18 pm

Calling System Services

Post by Martin »

Well done Martin... That was just what the doctor ordered

Code: Select all

A%(1)=$C601         :REM LDAB #1  load B with 1, Function 1: call notepad as if top menu option chosen
A%(2)=$3F9F         :REM SWI 9F   software interrupt, call system service $9F NT$ENTR
A%(3)=$3901         :REM RTS, NOP Return from subroutine, no operation
USR(ADDR(A%()),0)   :REM run the machine code stored in A%

XFILES
A%(1)=$C601	:REM 1=xFiles, 4=Find, 5=Save
A%(2)=$3FA8
A%(3)=$3901
USR(ADDR(A%(),0)

UTILS
A%(1)=$C601	:rem 1=Utils, 3=Info, 9=Dir
A%(2)=$3FA1
A%(3)=$3901
USR(ADDR(A%(),0)

Diary
A%(1)=$C601	:rem 1=Week, 3=Month
A%(2)=$3FA7
A%(3)=$3901
USR(ADDR(A%(),0)
Sincerely thankful
Martin
Post Reply