So Ill kick off with with a continuation from a previous thread, "Command line parameters". I see a lot of programmers starting out with programming for Qdos/S*Basic, myself included, getting tangled in the RI stack, fetching and returning parameters, moving stuff around, padding strings, keeping it all nice and tidy. A lot of that is often error prone, inefficient, and unnecessary. (And a lot of that comes, I believe, from some of the early tutorial books, which the publishers wanted to get out in a rush, without their authors having had the time to familiarise themselves with their subject.)
What I want to say will be shorter, and hopefully more understandable if I just present it as code:
Code: Select all
* Sample code to demonstrate simplified parameter handling
* Ideal for simple integer maths or string handling where one or more
* strings dont change length (eg for reading only)
*
* Compatible with QDOS, Minerva and SMSQ/E
* Works with Qlib but not Turbo(?)
*
* a$ = 'abcXYZ': TOGGLE_CASE a$: PRINT a$
*
* a$ = 'abcXYZ': TOGGLE_CASE a$ & 'x': REMark ???
section code
filetype 0
include dev8_keys_qlv
include dev8_keys_sbasic
include dev8_keys_err
lea.l key,a1
move.w sb.inipr,a2
jmp (a2)
key
dc.w 2 one long proc name
dc.w ut_tc-*
dc.b 11,'TOGGLE_CASE'
dc.w 0,0,0 endprocs, no fns
ut_tc
lea.l 8(a3),a1 point past first par
cmp.l a1,a5 exactly one par?
bne.s err_bp no..
cmpi.w #nt.varst,nt_usetp(a6,a3.l) pure string?
bne.s err_bp nope
move.l nt_value(a6,a3.l),a1 value pointer
adda.l sb_datab(a6),a1 a1 -> string
move.w (a6,a1.l),d0 d0.w = len
addq.l #2,a1
bra.s tc_lend
tc_lp
eor.b #%100000,(a6,a1.l) A..z only
addq.l #1,a1
tc_lend
dbra d0,tc_lp
moveq #0,d0
rts back to basic
err_bp
moveq #err.ipar,d0
rts
*
end
Obviously this code doesnt do anything sensible, but a keyword like DOUBLE% int% based on this method might be useful. The alternative is getting the string on the stack (involving copying the whole string), processing it and then returning it as a function or via the parameter (both involving copying again).
The purpose of this thread is to explore workings and differences between Basics, so in the following Im asking for a "peer-review" of the following assumptions (best described in code, again.):
Code: Select all
* Sample code to demonstrate simplified parameter handling
* Ideal for simple integer maths or string handling where one or more
* strings dont change length (eg for reading only)
*
* Compatible with SMSQ/E and QLib only
*
* a$ = 'abcXYZ': TOGGLE_CASE a$: PRINT a$
*
* a$ = 'abcXYZ': TOGGLE_CASE a$ & 'x': REMark ???
section code
filetype 0
include dev8_keys_qlv
include dev8_keys_sbasic
include dev8_keys_err
lea.l key,a1
move.w sb.inipr,a2
jmp (a2)
key
dc.w 2 one long proc name
dc.w ut_tc-*
dc.b 11,'TOGGLE_CASE'
dc.w 0,0,0 endprocs, no fns
ut_tc
lea.l 8(a3),a1 point past first par
cmp.l a1,a5 exactly one par?
bne.s err_bp no..
cmpi.w #nt.varst,nt_usetp(a6,a3.l) pure string?
bne.s err_bp nope
move.l nt_value(a6,a3.l),a1 a1 -> string
move.w (a1)+,d0 d0.w = len
bra.s tc_lend
tc_lp
eor.b #%100000,(a1)+ A..z only
tc_lend
dbra d0,tc_lp
moveq #0,d0
rts back to basic
err_bp
moveq #err.ipar,d0
rts
*
end
Ive tested these in the systems mentioned, looking for corruption or memory leaks, but all seems fine. I may just have been lucky.
If theres an interest, Ill update this info if and when..
Per