?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /*-------------------------------------------------------------------------
  2.    _gptrgetc.c - get value for a generic pointer (used with --xram-movc)
  3.  
  4.    Copyright (c) 1999, Sandeep Dutta . sandeep.dutta@usa.net
  5.  
  6.    This library is free software; you can redistribute it and/or modify it
  7.    under the terms of the GNU General Public License as published by the
  8.    Free Software Foundation; either version 2, or (at your option) any
  9.    later version.
  10.  
  11.    This library is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with this library; see the file COPYING. If not, write to the
  18.    Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
  19.    MA 02110-1301, USA.
  20.  
  21.    As a special exception, if you link this library with other files,
  22.    some of which are compiled with SDCC, to produce an executable,
  23.    this library does not by itself cause the resulting executable to
  24.    be covered by the GNU General Public License. This exception does
  25.    not however invalidate any other reasons why the executable file
  26.    might be covered by the GNU General Public License.
  27. -------------------------------------------------------------------------*/
  28.  
  29.  
  30. /* the  return value is expected to be in acc, and not in the standard
  31.  * location dpl. Therefore we choose return type void here: */
  32.  
  33. #if 1
  34.  
  35. void
  36. _gptrgetc (char *gptr) __naked
  37. {
  38. /* This is the new version with pointers up to 16 bits.
  39.    B cannot be trashed */
  40.  
  41.     gptr; /* hush the compiler */
  42.  
  43.     __asm
  44.     ;   save values passed
  45.     ;
  46.     ;   depending on the pointer type acc. to SDCCsymt.h
  47.     ;
  48.         jb              _B_7,codeptr$        ; >0x80 code               ; 3
  49.         jnb             _B_6,xdataptr$       ; <0x40 far                ; 3
  50.  
  51.         mov     dph,r0 ; save r0 independant of regbank ; 2
  52.         mov     r0,dpl ; use only low order address             ; 2
  53.  
  54.         jb              _B_5,pdataptr$       ; >0x60 pdata              ; 3
  55.     ;
  56.     ;   Pointer to data space
  57.     ;
  58.         mov     a,@r0                                                                   ; 1
  59.         mov     r0,dph ; restore r0                                             ; 2
  60.         mov     dph,#0 ; restore dph                                    ; 2
  61.         ret                                                                                             ; 1
  62.     ;
  63.     ;   pointer to external stack or pdata
  64.     ;
  65.  pdataptr$:
  66.         movx    a,@r0                                                                   ; 1
  67.         mov     r0,dph ; restore r0                                             ; 2
  68.         mov     dph,#0 ; restore dph                                    ; 2
  69.         ret                                                                                             ; 1
  70. ;
  71. ;   pointer to xternal data
  72. ;   pointer to code area
  73. ;
  74.  codeptr$:
  75.  xdataptr$:
  76.         clr     a                                                                               ; 1
  77.         movc    a,@a+dptr                                                               ; 1
  78.         ret                                                                                             ; 1
  79.                                                                                                         ;===
  80.                                                                                                         ;28 bytes
  81.      __endasm;
  82. }
  83.  
  84. #else
  85.  
  86. void
  87. _gptrgetc (char *gptr) __naked
  88. {
  89.     gptr; /* hush the compiler */
  90.  
  91.     __asm
  92.     ;   save values passed
  93.         xch    a,r0
  94.         push   acc
  95.     ;
  96.     ;   depending on the pointer type acc. to SDCCsymt.h
  97.     ;
  98.         mov     a,b
  99.         jz      00001; 0 near
  100.         dec     a
  101.         jz      00003; 1 far
  102.         dec     a
  103.         jz      00003; 2 code
  104.         dec     a
  105.         jz      00004$  ; 3 pdata
  106.         dec     a       ; 4 skip generic pointer
  107.         dec     a
  108.         jz      00001; 5 idata
  109.     ;
  110.     ;   any other value for type
  111.     ;   return xFF
  112.         mov     a,#0xff
  113.         ret
  114.     ;
  115.     ;   Pointer to data space
  116.     ;
  117.  00001$:
  118.         mov     r0,dpl     ; use only low order address
  119.         mov     a,@r0
  120.         ret
  121. ;
  122. ;   pointer to xternal data
  123. ;   pointer to code area
  124. ;
  125.  00003$:
  126.         ; clr     a  is already 0
  127.         movc    a,@a+dptr
  128.         ret
  129. ;
  130. ;   pointer to xternal stack
  131. ;
  132.  00004$:
  133.         mov     r0,dpl
  134.         movx    a,@r0
  135. ;
  136. ;   restore and return
  137. ;
  138.         mov     r0,a
  139.         pop     acc
  140.         xch     a,r0
  141.         ret
  142.      __endasm;
  143.  
  144. }
  145. #endif
  146.