Enjoy!7alken wrote: Sat Apr 26, 2025 1:36 pm hi Norm, wow, what a cool book this one, up to PE ... never saw it till now, probably needs more audience
Petr
Cheers,
Norm.
Enjoy!7alken wrote: Sat Apr 26, 2025 1:36 pm hi Norm, wow, what a cool book this one, up to PE ... never saw it till now, probably needs more audience
Petr
Code: Select all
;reflection_asm - a reflection library for SuperBASIC
;U N D E R C O N S T R U C T I O N
;
;ASSEMBLER: Computer One Assembler (because I want to use the symbolic
;debugging of Computer One Monitor and C1 Monitor recommends this Ed.)
;
;TODO: Write my SuperBASIC function "ref_getLnHi" as a S(uper)BASIC
; machine code extension for S(uper)BASIC
;Start: 2025-04-24 Thu (Cottage) - Last update 2025-04-26 Fri (Home)
;
;NOTE: Maximum line length of C1 editor seems to be 80 chars (or so)! but with the continuation char in first column this editor line will be joined with the previous.
;
;First test if blank lines (without semicolons) are allowed in C1 Ed/As
bp_init equ $110 ;Vector BP.INIT to define MC PROC/FNs
start
lea define,a1 ;Load Effective Adress of SB PROC/FNs
move.w bp_init,a2 ;We must call SB vector BP.INIT
jmp (a2) ;DO IT!
define
dc.w 0,0 ;No procedures
dc.w 2 ;One function (but name is long so 2)
dc.w ref_getLnLo-*
dc.b 12,'REF_GETLNLO%'
dc.w 0 ;END of FuNctions
ref_getLnLo
moveq #0,d0 ;Currently this function does nothing
rts ; and returns no error (0 I hope)
And make sure you clean up the math stack once you start using it (you need to remove all of the space off (a1,a6) you might have used with the CA_GTxxxx vectors, then put the return value there and adjust bv_rip(a6)). QDOS will do that cleanup for you in procedures, but not functions (That is why it is useful for your first machine code extensions to start with procedures, then elevate to functions, once you get the hang of it).Martin_Head wrote: Sun Apr 27, 2025 8:43 am Yes, put the return value on the maths stack, and set D4 to one of-
1 String
2 float
3 word integer
Code: Select all
;reflection_asm - a reflection library for SuperBASIC
;U N D E R C O N S T R U C T I O N
;
;ASSEMBLER: Computer One Assembler (because I want to use the symbolic
;debugging of Computer One Monitor and C1 Monitor recommends this Ed.)
;
;TODO: Write my SuperBASIC function "ref_getLnHi" as a S(uper)BASIC
; machine code extension for S(uper)BASIC
;Start: 2025-04-24 Thu (Cottage) - Last update 2025-04-26 Fri (Home)
;
;NOTE: Maximum line length of C1 editor seems to be 80 chars (or so)! but with the continuation char in first column this editor line will be joined with the previous.
;
;First test if blank lines (without semicolons) are allowed in C1 Ed/As
;Note: We use RI stack (also called arithmetic stack or maths stack)
BP_INIT equ $110 ;Vector BP.INIT to define MC PROC/FNs
BV_CHRIX equ $11a ;Vector BV.CHRIX
BV_PFBAS equ $10 ;Start of program
BV_PFB equ $14 ;End of program
BV_RIP equ $58 ;BASIC storage for RI stack
QSTR equ 1 ;Qdos STRing
QFLT EQU 2 ;Qdos FLoaT
QINT EQU 3 ;Qdos INteger (WORD, i.e. short in C!)
start
lea define,a1 ;Load Effective Adress of SB PROC/FNs
move.w BP_INIT,a2 ;We must call SB vector BP.INIT
jmp (a2) ;DO IT!
define
dc.w 0,0 ;No procedures
dc.w 2 ;One function (but name is long so 2)
dc.w ref_getLnLo-*
dc.b 12,'REF_GETLNLO%'
dc.w 0 ;END of FuNctions
ref_getLnLo ;0(a6,a1.l) points to RI stack
move.l BV_PFBAS(a6),a2 ;Get pointer to start of program
move.w 4(a6,a2.l),d4 ;Get line number of first line
move.w BV_CHRIX,a0 ;We need space on RI stack
move.l #2,d0 ;2 bytes required for line number
move.l a1,BV_RIP(a6) ;Stack may move at BV.CHRIX so save it
jsr (a0)
move.l BV_RIP(a6),a1 ;Restore RI stack pointer
move.w d4,0(a6,a1.l) ;Push line no. (short int) ...
addq.l #2,a1 ;... on RI stack AND (don't forget!):
moveq #QINT,d4 ;... set return type (integer [short])
moveq #0,d0 ;No error
rts ;Return to SuperBASIC
Code: Select all
Move.l bv_rip(a6),a1
Subq.l #2,a1
Move.l a1,bv_rip(a6)
Move.w d4,0(a6,a1.l)
Moveq #QINT,d4
...