Table of Contents

SAS/C

Setup

; BEGIN SAS/C
ASSIGN SC: PATH:To/sasc
; END SAS/C

With Vamos

Vamos

smake won't work out of the box as smake needs LIBS:icon.library.

Gotchas

Data types

Getting the offset of a field in a struct

Handy if you don't want to hard code all the custom chip register values.

https://stackoverflow.com/a/39805594

snippet.c
#define offsetof(s,m) &((struct s *)0)->m

DIsable Ctrl-C handling

From http://amigadev.elowar.com/read/ADCD_2.1/Devices_Manual_guide/node0196.html:

snippet.c
#ifdef LATTICE
int CXBRK(void) { return(0); }     /* Disable SAS CTRL/C handling */
int chkabort(void) { return(0); }  /* really */
#endif
snippet.asm
; wow.s
 
  XDEF _wow ; SAS/C function link symbol convention
 
_wow: ; wow is int wow(char what)
  MOVE.L A5,-(SP) ; preserve A5
    MOVE.L A7,A5 ; put current stack onto A5 to use as reference to args
    MOVEQ #0,D0
    MOVE.B 11(A7),D0  ; move the char into D0
  MOVE.L (SP)+,A5
  RTS ; D0 is return value

In SAS/C:

snippet.c
// main,c
extern int wow(char what);
 
int main(void) {
  printf("%d\n", wow(30)) ; => 30
  return 0;
}

At the command line:

genam -l wow.s
sc link to main main.c wow.o

The more things you preserve on the stack during the parameter extraction, the farther up you'll have to look:

snippet.asm
_InitializeCopperlist:
  MOVEM.L A0/A5,-(SP)
    MOVE.L A7,A5
    MOVE.L 12(A5),A0
    MOVE.L #$FFFFFFFE,(A0)
  MOVEM.L (SP)+,A0/A5
  RTS

For more details on calling convention, search https://retro-commodore.eu/files/downloads/amigamanuals-xiik.net/Applications/SAS_C_Compiler_v6.5x___Manual_ENG/SASC6V2.txt for Communicating between Assembl.