Preprocessor.asm 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #define IRQ_UNDER_ROM // <- here we define a preprocesssor symbol. This can also be done
  2. #define STANDALONE
  3. //-----------------------------------------------------
  4. // Upstart program if we are in stand alone mode
  5. //-----------------------------------------------------
  6. #if STANDALONE // <- The source inside the #if is discarded if STANDALONE is not defined
  7. BasicUpstart2(start)
  8. start: sei
  9. #if !IRQ_UNDER_ROM // <- If's can be nested. Notice the ! operator. Other operators are ==, !=, ||, && and ()
  10. lda #<irq1
  11. sta $0314
  12. lda #>irq1
  13. sta $0315
  14. #else
  15. lda #$35
  16. sta $01
  17. lda #<irq1
  18. sta $fffe
  19. lda #>irq1
  20. sta $ffff
  21. #endif
  22. lda #$1b
  23. sta $d011
  24. lda #$32
  25. sta $d012
  26. lda #$81
  27. sta $d01a
  28. lda #$7f
  29. sta $dc0d
  30. sta $dd0d
  31. lda $dc0d
  32. lda $dd0d
  33. lda #$ff
  34. sta $d019
  35. cli
  36. inc $d020
  37. jmp *
  38. #endif
  39. //-----------------------------------------------------
  40. // Procedures for start and end of interupt
  41. //-----------------------------------------------------
  42. #if !IRQ_UNDER_ROM
  43. .pseudocommand irqStart { // <- Since preprocessor commands are executed before anything else, you can redefined macros, functions, imports etc dependant on your settings
  44. // (This can't be done by normal .if directives)
  45. lda #$ff
  46. sta $d019
  47. }
  48. .pseudocommand irqEnd line : addr {
  49. .if (line.getType()!=AT_NONE) {lda line; sta $d012; }
  50. .if (addr.getType()!=AT_NONE) {lda #<addr.getValue(); sta $0314; lda #>addr.getValue(); sta $0315; }
  51. jmp $ea81
  52. }
  53. #else
  54. .pseudocommand irqStart {
  55. pha
  56. txa
  57. pha
  58. tya
  59. pha
  60. lda #$ff
  61. sta $d019
  62. }
  63. .pseudocommand irqEnd line : addr {
  64. .if (line.getType()!=AT_NONE) {lda line; sta $d012; }
  65. .if (addr.getType()!=AT_NONE) {lda #<addr.getValue(); sta $fffe; lda #>addr.getValue(); sta $ffff; }
  66. pla
  67. tay
  68. pla
  69. tax
  70. pla
  71. rti
  72. }
  73. #endif
  74. //-----------------------------------------------------
  75. // The Irqs
  76. //-----------------------------------------------------
  77. #if !IRQ_UNDER_ROM
  78. .const delay = 3
  79. #else
  80. .const delay = 7
  81. #endif
  82. *=$5000
  83. irq1: irqStart
  84. ldy #delay
  85. dey
  86. bne *-1
  87. lda #LIGHT_BLUE
  88. sta $d020
  89. irqEnd #$32+200 : #irq2
  90. irq2: irqStart
  91. ldy #delay
  92. dey
  93. bne *-1
  94. lda #BLACK
  95. sta $d020
  96. irqEnd #$32 : #irq1