home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 92 / asm / source / fargo / testfunc.asm < prev    next >
Encoding:
Assembly Source File  |  2001-07-01  |  2.2 KB  |  114 lines

  1.     include    "tios.h"
  2.     xdef    _main
  3.     xdef    _tibasic
  4.  
  5. ;*****************************************************
  6.  
  7. _main:
  8.     ; make a tiny stack frame for functions that
  9.     ; take one word as a parameter
  10.     sub.l    #2,sp
  11.  
  12.     ; Trigger an "Internal error" if we can't find
  13.     ; the "x" parameter in our local folder
  14.     pea    param_name(pc)
  15.     move.w    tios::DefTempHandle,-(sp)
  16.     jsr    tios::FindSymEntry
  17.     add.l    #6,sp
  18.     move.l    a0,d0
  19.     bne    no_error
  20.     tios::ER_throw 1020
  21. no_error:
  22.     move.w    10(a0),d0
  23.  
  24.     ; Trigger a "Data type" error if the "x"
  25.     ; parameter is not a string
  26.     tios::DEREF d0,a0
  27. check_data_type:
  28.     move.w    (a0),d0
  29.     lea    2(a0,d0.w),a0
  30.     cmp.b    #$2D,-(a0)
  31.     beq    good_data_type
  32.     tios::ER_throw 210
  33. good_data_type:
  34.     sub.l    #1,a0
  35. find_string_loop:
  36.     tst.b    -(a0)
  37.     bne    find_string_loop
  38.     add.l    #1,a0
  39.     move.l    a0,test_args
  40.     move.l    a0,test_args+4
  41.  
  42.     ; Now we will push the return value onto
  43.     ; the estack. The return value of this
  44.     ; function is "%s=%s", where "%s" is
  45.     ; replaced with the string that was
  46.     ; passed to the function as a parameter.
  47.  
  48.     ; Mark the beginning of the string
  49.     move.w    #0,(sp)
  50.     jsr    tios::push_quantum
  51.  
  52.     ; Use the callback printf function to
  53.     ; do printf("%s=%s", string) and push
  54.     ; each outputted char onto the estack
  55.     pea    test_args
  56.     pea    test_format(pc)
  57.     clr.l    -(sp)
  58.     pea    push_char(pc)
  59.     jsr    tios::vcbprintf
  60.     lea    16(sp),sp
  61.  
  62.     ; Mark the end of the string
  63.     move.w    #0,(sp)
  64.     jsr    tios::push_quantum
  65.     ; $2D = string tag
  66.     move.w    #$2D,(sp)
  67.     jsr    tios::push_quantum
  68.  
  69.     ; Indicate that there is a return value
  70.     move.b    #2,tios::main_lcd+$126E
  71.  
  72.     ; remove our stack frame
  73.     add.l    #2,sp
  74.  
  75.     ; return to caller
  76.     rts
  77.  
  78. ;*****************************************************
  79.  
  80. push_char:
  81.     move.w    4(sp),d0
  82.     move.w    d0,-(sp)
  83.     jsr    tios::push_quantum
  84.     add.l    #2,sp
  85.     rts
  86.  
  87. ;*****************************************************
  88.  
  89. test_format    dc.b    "%s=%s",0
  90.  
  91. param_name    dc.b    "x",0
  92.  
  93. ;*****************************************************
  94.     bss
  95.  
  96. test_args:
  97.     dc.l    0
  98.     dc.l    0
  99.  
  100. ;*****************************************************
  101.     section    _tibasic
  102.  
  103.     dc.b    $E9
  104.     dc.b    $0F,$E4        ; EndFunc
  105.     dc.b    $00,$E8        ; :
  106.     dc.b    $17,$E4        ; Func
  107.     dc.b    $E5,$08        ; (x)
  108.     dc.b    $00,$00,$40,$DC
  109.  
  110. _tibasic
  111. ;*****************************************************
  112.  
  113.     end
  114.