Author Topic: submitting new asm routines for C or python compiler.  (Read 2117 times)

0 Members and 1 Guest are viewing this topic.

Offline Aaendi

  • Newbie
  • *
  • Posts: 25
submitting new asm routines for C or python compiler.
« on: August 11, 2010, 03:32:55 AM »
If I want to submit an asm routine for a higher level compiler (there is both a C and a python compiler for the Snes right?) how do I go about doing it?

Offline mic_

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 632
Re: submitting new asm routines for C or python compiler.
« Reply #1 on: August 11, 2010, 03:38:39 AM »
(there is both a C and a python compiler for the Snes right?)
No. The SDK is based around a C compiler. The code optimizer included with the SDK is written in Python, but it doesn't allow you to program the SNES using Python.


If I want to submit an asm routine for a higher level compiler how do I go about doing it?
See my reply at the nesdev forum.
And if you want examples you could check out the SNES Myth menu source code. For example this file and this file.

Offline Aaendi

  • Newbie
  • *
  • Posts: 25
Re: submitting new asm routines for C or python compiler.
« Reply #2 on: August 11, 2010, 10:29:50 AM »
Here is a code that renders 1 line of 8 affine-mapped pixels and stores the line of pixels in planar format in tcc_r9 and tcc_r9h.  Don't know if it works yet, I'll try testing it Tomarrow if I have time.

Code: [Select]
;; affine(pixel_start_x, pixel_start_y, pixel_inc_x, pixel_inc_y)


affine:

php
rep #$30
phy
phx
phb

sep #$20
lda 16,s      ;; bank
pha
plb
rep #$20

lda 18,s
sta tcc_r0    ;; x pixel increment
lda 22,s
sta tcc_r0h   ;; y pixel increment

lda 14,s
sta tcc_r1h
clc
adc tcc_r0h
sta tcc_r2h
clc
adc tcc_r0h
sta tcc_r3h
clc
adc tcc_r0h
sta tcc_r4h
clc
adc tcc_r0h
sta tcc_r5h
clc
adc tcc_r0h
sta tcc_r6h
clc
adc tcc_r0h
sta tcc_r7h
clc
adc tcc_r0h
sta tcc_r8h

lda 10,s
sta tcc_r1+1
clc
adc tcc_r0
sta tcc_r2+1
clc
adc tcc_r0
sta tcc_r3+1
clc
adc tcc_r0
sta tcc_r4+1
clc
adc tcc_r0
sta tcc_r5+1
clc
adc tcc_r0
sta tcc_r6+1
clc
adc tcc_r0
sta tcc_r7+1
clc
adc tcc_r0
sta tcc_r8+1

sep #$20
lda (tcc_r1h)
ror
rol tcc_r9
ror
rol tcc_r9+1
ror
rol tcc_r9h
ror
rol tcc_r9h+1
lda (tcc_r2h)
ror
rol tcc_r9
ror
rol tcc_r9+1
ror
rol tcc_r9h
ror
rol tcc_r9h+1
lda (tcc_r3h)
ror
rol tcc_r9
ror
rol tcc_r9+1
ror
rol tcc_r9h
ror
rol tcc_r9h+1
lda (tcc_r4h)
ror
rol tcc_r9
ror
rol tcc_r9+1
ror
rol tcc_r9h
ror
rol tcc_r9h+1
lda (tcc_r5h)
ror
rol tcc_r9
ror
rol tcc_r9+1
ror
rol tcc_r9h
ror
rol tcc_r9h+1
lda (tcc_r6h)
ror
rol tcc_r9
ror
rol tcc_r9+1
ror
rol tcc_r9h
ror
rol tcc_r9h+1
lda (tcc_r7h)
ror
rol tcc_r9
ror
rol tcc_r9+1
ror
rol tcc_r9h
ror
rol tcc_r9h+1
lda (tcc_r8h)
ror
rol tcc_r9
ror
rol tcc_r9+1
ror
rol tcc_r9h
ror
rol tcc_r9h+1

plb
plx
ply
plp
rtl

« Last Edit: August 11, 2010, 11:36:52 PM by Aaendi »

Offline vorn10

  • Newbie
  • *
  • Posts: 1
  • NEO newbie
Re: submitting new asm routines for C or python compiler.
« Reply #3 on: February 28, 2019, 01:58:57 AM »
If I want to submit an asm routine for a higher level compiler (there is both a C and a python compiler for the Snes right?) how do I go about doing it?

C and Assembly can be used together to provide extra flexibility. You can create static libraries in Assembly that you call from C, and vice-versa, you can call C functions from within Assembly. Check out the code samples below that demonstrate that process.

It's actually slightly incorrect to say we are 'calling C from Assembly' or vice-versa because once the code is compiled, it is the same machine language. Whether you compile the object files from Assembly or from C they turn out the same. Once they are object files they can be called from anywhere, but they have to be defined as externals and linked. You could create static libraries as object files from other languages too. It doesn't just have to be Assembly and C.