/tools/cc65-2.13.2/libsrc/lynx/crt0.s

http://github.com/gilligan/snesdev · Assembly · 178 lines · 92 code · 48 blank · 38 comment · 0 complexity · e3ab4d3cc1fa0af117f8e2ebe9b7ca9e MD5 · raw file

  1. ; ***
  2. ; CC65 Lynx Library
  3. ;
  4. ; Originally by Bastian Schick
  5. ; http://www.geocities.com/SiliconValley/Byte/4242/lynx/
  6. ;
  7. ; Ported to cc65 (http://www.cc65.org) by
  8. ; Shawn Jefferson, June 2004
  9. ;
  10. ; ***
  11. ;
  12. ; Startup code for cc65 (Lynx version). Based on Atari 8-bit startup
  13. ; code structure. The C stack is located at the end of the RAM memory
  14. ; segment and grows downward. Bastian Schick's executable header is put
  15. ; on the front of the fully linked binary (see EXEHDR segment.)
  16. ;
  17. .include "lynx.inc"
  18. .export _exit
  19. .export __STARTUP__ : absolute = 1 ; Mark as startup
  20. .import callirq, initlib, donelib
  21. .import zerobss
  22. .import callmain
  23. .import _main
  24. .import __BSS_LOAD__
  25. .import __INTERRUPTOR_COUNT__
  26. .import __RAM_START__, __RAM_SIZE__
  27. .include "zeropage.inc"
  28. .include "extzp.inc"
  29. ; ------------------------------------------------------------------------
  30. ; EXE header (BLL header)
  31. .segment "EXEHDR"
  32. .word $0880
  33. .dbyt __RAM_START__
  34. .dbyt __BSS_LOAD__ - __RAM_START__ + 10
  35. .byte $42,$53
  36. .byte $39,$33
  37. ; ------------------------------------------------------------------------
  38. ; Mikey and Suzy init data, reg offsets and data
  39. .rodata
  40. SuzyInitReg: .byte $28,$2a,$04,$06,$92,$83,$90
  41. SuzyInitData: .byte $7f,$7f,$00,$00,$24,$f3,$01
  42. MikeyInitReg: .byte $00,$01,$08,$09,$20,$28,$30,$38,$44,$50,$8a,$8b,$8c,$92,$93
  43. MikeyInitData: .byte $9e,$18,$68,$1f,$00,$00,$00,$00,$00,$ff,$1a,$1b,$04,$0d,$29
  44. ; ------------------------------------------------------------------------
  45. ; Actual code
  46. .segment "STARTUP"
  47. ; set up system
  48. sei
  49. cld
  50. ldx #$FF
  51. txs
  52. ; init bank switching
  53. lda #$C
  54. sta MAPCTL ; $FFF9
  55. ; disable all timer interrupts
  56. lda #$80
  57. trb TIM0CTLA
  58. trb TIM1CTLA
  59. trb TIM2CTLA
  60. trb TIM3CTLA
  61. trb TIM5CTLA
  62. trb TIM6CTLA
  63. trb TIM7CTLA
  64. ; disable TX/RX IRQ, set to 8E1
  65. lda #%11101
  66. sta SERCTL
  67. ; clear all pending interrupts
  68. lda INTSET
  69. sta INTRST
  70. ; setup the stack
  71. lda #<(__RAM_START__ + __RAM_SIZE__)
  72. sta sp
  73. lda #>(__RAM_START__ + __RAM_SIZE__)
  74. sta sp+1
  75. ; Init Mickey
  76. ldx #.sizeof(MikeyInitReg)-1
  77. mloop: ldy MikeyInitReg,x
  78. lda MikeyInitData,x
  79. sta $fd00,y
  80. dex
  81. bpl mloop
  82. ; these are RAM-shadows of read only regs
  83. ldx #$1b
  84. stx __iodat
  85. dex ; $1A
  86. stx __iodir
  87. ldx #$d
  88. stx __viddma
  89. ; Init Suzy
  90. ldx #.sizeof(SuzyInitReg)-1
  91. sloop: ldy SuzyInitReg,x
  92. lda SuzyInitData,x
  93. sta $fc00,y
  94. dex
  95. bpl sloop
  96. lda #$24
  97. sta __sprsys
  98. ; Clear the BSS data
  99. jsr zerobss
  100. ; If we have IRQ functions, set the IRQ vector
  101. ; as Lynx is a console there is not much point in releasing the IRQ
  102. lda #<__INTERRUPTOR_COUNT__
  103. beq NoIRQ1
  104. lda #<IRQStub
  105. ldx #>IRQStub
  106. sei
  107. sta INTVECTL
  108. stx INTVECTH
  109. cli
  110. ; Call module constructors
  111. NoIRQ1: jsr initlib
  112. ; Push arguments and call main
  113. jsr callmain
  114. ; Call module destructors. This is also the _exit entry.
  115. _exit: jsr donelib ; Run module destructors
  116. ; Endless loop
  117. noret: bra noret
  118. .segment "CODE"
  119. IRQStub:
  120. phy
  121. phx
  122. pha
  123. cld
  124. jsr callirq
  125. lda INTSET
  126. sta INTRST
  127. pla
  128. plx
  129. ply
  130. rti