Andrew Collier | 31 Jan 20:36
Picon
Gravatar

Who remembers about the floating point calculator?

Hi,

AS you may know, if you CALL a machine code routine with some  
parameters, they are pushed onto the ROM's floating point calculator  
stack. I'm trying to use this, but having some difficulty getting the  
numbers back out again. Can anyone spot what's going wrong?

Consider a routine taking two parameters, which I'll designate FROM  
and TO; each are addresses in BASIC format (i.e. between 16384 and  
540671) - I want to separate these into a (page+1) and offset of each  
address, and collect the resulting 16-bit values using JGETINT.

If I call the following routine with CALL (address), 32768, 81920 then  
the values which are returned in HL from the calls to JGETINT are, in  
order:
0x0000		; fine, 81920 mod 16384 == 0
0x0005		; fine, 82910 div 16384 == 5
0x00c0		; wrong - expect 32768 mode 16384 == 0
0x0000		; wrong - expect 32768 mode 16384 == 2

Are there any entry conditions to 0x28 or JGETINT which I need to obey  
and have forgotten about? Have I got the FPC sequence wrong?

Thanks in advance for any useful observations,
Andrew

ENTRY:
     cp 2
     jp nz, parameter_error

     rst 0x28 ; call floating point calculator, stack = FR,TO

     db 0x25 ; DUP       ; FR,TO,TO
     db 0xe2 ; STK16K    ; FR,TO,TO,16K
     db 0x08 ; MOD       ; FR,TO,TO\16K
     db 0x06 ; SWOP      ; FR,TO\16K,TO
     db 0xe2 ; STK16K    ; FR,TO\16K,TO,16K
     db 0x09 ; IDIV      ; FR,TO\16K,TO/16K

     db 0x1c ; SWOP13    ; TO/16K,TO\16K,FR

     db 0x25 ; DUP       ; TO/16K,TO\16K,FR,FR
     db 0xe2 ; STK16K    ; TO/16K,TO\16K,FR,FR,16K
     db 0x08 ; MOD       ; TO/16K,TO\16K,FR,FR\16K
     db 0x06 ; SWOP      ; TO/16K,TO\16K,FR\16K,FR
     db 0xe2 ; STK16K    ; TO/16K,TO\16K,FR\16K,FR,16K
     db 0x09 ; IDIV      ; TO/16K,TO\16K,FR\16K,FR/16K

     db 0x06 ; SWOP      ; TO/16K,TO\16K,FR/16K,FR\16K

     db 0x33 ; EXIT

     call JGETINT
     ld (FROM_os),hl

     call JGETINT
     ld a,h
     or a
     jr nz, invalid_argument_error
     ld a,l
     dec a
     cp 32
     jr nc, invalid_argument_error
     ld (FROM_page),a

     call JGETINT
     ld (TO_os),hl

     call JGETINT
     ld a,h
     or a
     jr nz, invalid_argument_error
     ld a,l
     dec a
     cp 32
     jr nc, invalid_argument_error
     ld (TO_page),a

--

-- 
  ---       Andrew Collier         ----
   ---- http://www.intensity.org.uk/ ---
                                       --


Gmane