Home > CBM > BASIC > Keywords > Usr 180 Subpages: (divide), (equal), (less), (minus), (more), (multiply), (plus), (power), Abs, And, Append, Asc, Atn, Auto, Backup, Bank, Begin, Bend, Bload, Boot, Box, Bsave, Bump, Catalog, Char, Chr, Circle, Close, Clr, Cmd, Collect, Collision, Color, Concat, Cont, Copy, Cos, Data, Dclear, Dclose, Dec, Def, Delete, Dim, Directory, Dispose, Dload, Do, Dopen, Draw, Ds, Ds string, Dsave, Dverify, El, Else, End, Envelope, Er, Err, Exit, Exp, Fast, Fetch, Filter, Fn, For, Fre, Get, Get num, Getkey, Go, Gosub, Goto, Graphic, Gshape, Header, Help, Hex, If, Input, Input num, Instr, Int, Joy, Key, Left, Len, Let, List, Load, Locate, Log, Loop, Mid, Monitor, Movspr, New, Next, Not, Off, On, Open, Or, Paint, Peek, Pen, Pi, Play, Pointer, Poke, Pos, Pot, Print, Print num, Pudef, Quit, Rclr, Rdot, Read, Record, Rem, Rename, Renumber, Restore, Resume, Return, Rgr, Right, Rlum, Rnd, Rreg, Rspcolor, Rsppos, Rsprite, Run, Rwindow, Save, Scale, Scnclr, Scratch, Sgn, Sin, Sleep, Slow, Sound, Spc, Sprcolor, Sprdef, Sprite, Sprsav, Sqr, Sshape, St, Stash, Step, Stop, Str, Swap, Sys, Tab, Tan, Tempo, Then, Ti, Ti string, To, Trap, Troff, Tron, Until, Using, Val, Verify, Vol, Wait, While, Width, Window, Xor |
| Keyword | Abbreviation | Token (hex) | Version(s) | Classification | | USR | U{Shift+S} | B7 | 1.0+ | Function |
USR ( value ) | Parameters | Type | Legal Value(s) | Default Value | Note(s) | | value | Numeric | depends of function definition | | |
| Returns | Type | Value(s) | Note(s) | | result | Floating-point | depends on function definition | |
Call a machine-language program to evaluate a custom user-function.
The USR function is the functional equivalant to the SYS command/statement. Another way to think of it, is as the machine-language equivalant of the BASIC (DEF)FN. In contrast to SYS, you pass a numeric value to be processed, not a memory address (the memory address of the machine-language program is a secret variable). In contrast to (DEF)FN, the definition is written is assembly/machine language, instead of BASIC. Also different from (DEF)FN is that you can have only one custom USR function (unless you keep POKE'ing different values, see below). Because it calls a machine-language program, this function is very non-portable. If no machine-langauge program has been "set up", then calling USR will generate ILLEGAL QUANTITY ERROR. To "set up" USR, poke the start address of a machine-language program (which should store its result in BASIC's floating-point accumulator) into the magic addresses shown below: | Machine | Address | | Low Byte | High Byte | | PET | ??? | ??? | | CBM-II | 3 | 4 | | VIC-20 | 1 | 2 | | Commodore 64 | 785 | 786 | | Commodore 16 | 1281 | 1282 | | Plus/4 | 1281 | 1282 | | Commodore 128 | 4633 | 4644 |
You will get TYPE MISMATCH ERROR with a string value. Because this is extemely machine-dependent, there are no examples.
© H2Obsession, 2014 |