Posted By

Zufolek on 10/01/09


Tagged

Atari 2600


Versions (?)

Some Stuff for Batari Basic


 / Published in: Other
 

For batari Basic, which is found at http://bataribasic.com

To use functions in bB, a=ExampleFunction(arg1,arg2) To use functions in asm, make register a = arg1, y = arg2, and do jsr to function, and it returns value in register a.

  1. asm
  2.  
  3. ;function Abs(n) returns absolute value of n
  4. Abs
  5. bpl AbsDone
  6. sta temp1
  7. lda #0
  8. sec
  9. sbc temp1
  10. AbsDone
  11. rts
  12.  
  13.  
  14.  
  15. ;function Dist(x1,x2) returns distance from x1 to x2
  16. Dist
  17. sty temp1
  18. sec
  19. sbc temp1
  20. jsr Abs
  21. rts
  22.  
  23.  
  24. ;function RndLow(n) returns integer less than n
  25. ;with lower results more frequent
  26.  
  27. RndLow
  28. STA temp1
  29. LDX #255
  30. .RndLowLoop
  31. INX
  32. CPX temp1
  33. BCC RndLowOk
  34. LDA #0
  35. RTS
  36. RndLowOk
  37. jsr randomize
  38. STA temp3
  39. BIT temp3
  40. BMI .RndLowLoop
  41. txa
  42. RTS
  43.  
  44.  
  45. ;function RandRange(low,high) returns a random number
  46. ;between low and high, this needs to be optimized
  47. RandRange
  48. STA temp1
  49. STY temp2
  50. jsr randomize
  51. STA temp3
  52. CMP #0
  53. BEQ .RandDone
  54. .RandLoop
  55. jsr randomize
  56. STA temp3
  57. CMP temp2
  58. bcs .RandLoop
  59. CMP temp1
  60. bcc .RandLoop
  61. .RandDone
  62. RTS
  63.  
  64.  
  65.  
  66. ;subroutine AddScore adds to score the value in variable 's'
  67. ;assumes variable 't' is a frame counter
  68. ;call before every drawscreen
  69. .AddScore
  70. ldx s
  71. beq ScoreDone
  72. lda t
  73. and #3
  74. bne ScoreDone
  75. dex
  76. bne ScoreCont
  77. lda #4
  78. jmp SetScCol
  79. ScoreCont
  80. lda t
  81. asl
  82. asl
  83. asl
  84. asl
  85. clc
  86. adc #14
  87. SetScCol
  88. sta scorecolor
  89. SED
  90. CLC
  91. LDA score+2
  92. ADC #$01
  93. STA score+2
  94. LDA score+1
  95. ADC #$00
  96. STA score+1
  97. LDA score
  98. ADC #$00
  99. STA score
  100. CLD
  101. stx s
  102. ScoreDone
  103. rts
  104.  
  105. end

Report this snippet  

You need to login to post a comment.