xboxscene.org forums

Author Topic: Canonic Assembler  (Read 730 times)

openxdkman

  • Archived User
  • Hero Member
  • *
  • Posts: 550
Canonic Assembler
« on: April 13, 2007, 10:06:00 AM »

Here is a program that calls printf and draws a sinus function (fpu used).
There are plenty of useless global variables and constants just to show you syntax.

CODE

010,10+10
//0N,L+G :10 labels, 10 local registers + 10 global registers
//First char of first line must be '0' in canonic code

//Global macros (max 32500 chars in global macros string at any time)

// Global macros used as registers names:
// Each new pre-processing starts with global macro string "...="
// Next vars will start automatically at value L (see "0N,L+G")
// First global register can receive source line at run time for debug
// Second and third global register can be used as references as well
$$g_line,g_compare1,g_compare2
$$g_table[16]
$$g_last_global

// Global macros used as constants:
$$PI=!3.14159f
$$TABLE_SIZE=32

// Global macros used as unified api function IDs
$$plot=0,hline,vline,dline,rline
$$printf,print
$$malloc,free,calloc,realloc,ext_ram_left
$$comp,copy,clear,scanb,scanw,scanl
$$read_input,write_output,seek_input,seek_output,tell_input,tell_output
$$dbgprintline,dbgcheckram,dbgcompequ,dbgcomplt
$$getch
$$mdct,iwin,awin,convsamp

$$finit=61440
$$f2xm1,fabs,fchs,fpatan,fprem,fptan,frndint
$$fscale,fxtract,fsqrt,fxch,fyl2x,fyl2xp1
$$fld1,fldl2t,fldl2e,fldpi,fldlg2,fldln2,fldz
$$fsin,fcos,fsincos

// Global macros used as structures members offsets:
$$my_struct_first_member=!0
$$my_struct_dwords_table[TABLE_SIZE]
$$my_struct_size
$$my_2nd_struct_first_member=%0
$$my_2nd_struct_shorts_table[TABLE_SIZE]
$$my_2nd_struct_size

//Labels (max 32500 chars in labels macros string at any time)
@@main=0
//Compels incoming label 'main' to have value zero (code entry point)
//(allows you to put 'main' function code at bottom of file)

//Constant strings
@msg
S'Hello world %ld %04lx %s'
S'0a
S'0d
S'0
@name
S''
S'0

//let's ask for debug information (0=none, 1=report g_line)
~~1

////////
//main//
////////

@main
    $
    $ret,i,p1,p2,p3,x,y,c,fi

    Pp1
    L!7d7
    Sp1
    L!babe
    Sp2
    "name
    Sp3
    "msg
    #printf

    #finit

    L!0
    Si
@loop
        Li
        +!200
        Sx
    
        .
        Li
        sfi
        
        #fldpi
        *fi
        /!64.0
        #fsin
        *!-10.0
        +!384.0
        Sy
                
        L!0
        Sc

        Px
        #plot
    
        Li
        +!1
        Si
                Tloop

    L!0
    Sret
    Rret

//turns off debugging mode (faster execution for code after this line)
~~0

//keyboard scancodes for getch
//0x01 escape
//0x1c enter
//0x39 space
//0xc8 up
//0xd0 down
//0xcb left
//0xcd right
Logged