Shaun_B

Commodore C64/SuperCPU programming API build 65c02

Sep 21st, 2021 (edited)
851
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .cpu _65c02
  2.   // Commodore 64 PRG executable file
  3. .file [name="kickc-c64-api.prg", type="prg", segments="Program"]
  4. .segmentdef Program [segments="Basic, Code, Data"]
  5. .segmentdef Basic [start=$0801]
  6. .segmentdef Code [start=$80d]
  7. .segmentdef Data [startAfter="Code"]
  8. .segment Basic
  9. :BasicUpstart(main)
  10.   .label getMachineType = $15
  11. .segment Code
  12. /**
  13.  * C64 API intended for use with the SuperCPU
  14.  * By Donkeysoft MMXXI
  15.  * At the moment, KickC and Kick Assembler only
  16.  * build 65c02 binaries; this may change in the
  17.  * future.
  18.  */
  19. main: {
  20.     .label waitState = $100
  21.     .label xLocation = 3
  22.     .label yLocation = 5
  23.     .label index = 2
  24.     jsr setMachineType
  25.     jsr disableBasicInterrupts
  26.     lda #<0
  27.     sta.z poke.value
  28.     sta.z poke.value+1
  29.     lda #<$d020
  30.     sta.z poke.location
  31.     lda #>$d020
  32.     sta.z poke.location+1
  33.     jsr poke
  34.     lda #<$f
  35.     sta.z poke.value
  36.     lda #>$f
  37.     sta.z poke.value+1
  38.     lda #<$d021
  39.     sta.z poke.location
  40.     lda #>$d021
  41.     sta.z poke.location+1
  42.     jsr poke
  43.     jsr clearScreen
  44.     jsr printAt
  45.     jsr colourAt
  46.     lda #$30
  47.     sta.z yLocation
  48.     lda #<$40
  49.     sta.z xLocation
  50.     lda #>$40
  51.     sta.z xLocation+1
  52.     lda #0
  53.     sta.z index
  54.   __b1:
  55.     lda.z index
  56.     cmp #8
  57.     bcs !__b2+
  58.     jmp __b2
  59.   !__b2:
  60.     jsr spriteExpandX
  61.     jsr spriteExpandY
  62.     jsr spriteUnexpandX
  63.     jsr spriteUnexpandY
  64.   __b4:
  65.     lda #<$2c
  66.     sta.z checkForScanLine.scanLine
  67.     lda #>$2c
  68.     sta.z checkForScanLine.scanLine+1
  69.     jsr checkForScanLine
  70.     cmp #1
  71.     bne __b5
  72.     lda #<1
  73.     sta.z poke.value
  74.     lda #>1
  75.     sta.z poke.value+1
  76.     lda #<$d020
  77.     sta.z poke.location
  78.     lda #>$d020
  79.     sta.z poke.location+1
  80.     jsr poke
  81.     jsr wait
  82.     lda #<0
  83.     sta.z poke.value
  84.     sta.z poke.value+1
  85.     lda #<$d020
  86.     sta.z poke.location
  87.     lda #>$d020
  88.     sta.z poke.location+1
  89.     jsr poke
  90.   __b5:
  91.     lda #<$58
  92.     sta.z checkForScanLine.scanLine
  93.     lda #>$58
  94.     sta.z checkForScanLine.scanLine+1
  95.     jsr checkForScanLine
  96.     cmp #1
  97.     bne __b6
  98.     lda #<3
  99.     sta.z poke.value
  100.     lda #>3
  101.     sta.z poke.value+1
  102.     lda #<$d020
  103.     sta.z poke.location
  104.     lda #>$d020
  105.     sta.z poke.location+1
  106.     jsr poke
  107.     jsr wait
  108.     lda #<0
  109.     sta.z poke.value
  110.     sta.z poke.value+1
  111.     lda #<$d020
  112.     sta.z poke.location
  113.     lda #>$d020
  114.     sta.z poke.location+1
  115.     jsr poke
  116.   __b6:
  117.     lda #<$f4
  118.     sta.z checkForScanLine.scanLine
  119.     lda #>$f4
  120.     sta.z checkForScanLine.scanLine+1
  121.     jsr checkForScanLine
  122.     cmp #1
  123.     bne __b7
  124.     lda #<5
  125.     sta.z poke.value
  126.     lda #>5
  127.     sta.z poke.value+1
  128.     lda #<$d020
  129.     sta.z poke.location
  130.     lda #>$d020
  131.     sta.z poke.location+1
  132.     jsr poke
  133.     jsr wait
  134.     lda #<0
  135.     sta.z poke.value
  136.     sta.z poke.value+1
  137.     lda #<$d020
  138.     sta.z poke.location
  139.     lda #>$d020
  140.     sta.z poke.location+1
  141.     jsr poke
  142.   __b7:
  143.     lda #<$110
  144.     sta.z checkForScanLine.scanLine
  145.     lda #>$110
  146.     sta.z checkForScanLine.scanLine+1
  147.     jsr checkForScanLine
  148.     cmp #1
  149.     beq !__b4+
  150.     jmp __b4
  151.   !__b4:
  152.     lda #<7
  153.     sta.z poke.value
  154.     lda #>7
  155.     sta.z poke.value+1
  156.     lda #<$d020
  157.     sta.z poke.location
  158.     lda #>$d020
  159.     sta.z poke.location+1
  160.     jsr poke
  161.     jsr wait
  162.     lda #<0
  163.     sta.z poke.value
  164.     sta.z poke.value+1
  165.     lda #<$d020
  166.     sta.z poke.location
  167.     lda #>$d020
  168.     sta.z poke.location+1
  169.     jsr poke
  170.     jmp __b4
  171.   __b2:
  172.     lda.z index
  173.     tax
  174.     jsr setSpriteColour
  175.     ldx.z index
  176.     jsr switchOnSprites
  177.     lda.z xLocation
  178.     sta.z spriteAt.x
  179.     lda.z xLocation+1
  180.     sta.z spriteAt.x+1
  181.     lda.z yLocation
  182.     sta.z spriteAt.y
  183.     lda.z index
  184.     sta.z spriteAt.spriteNumber
  185.     jsr spriteAt
  186.     lda #$18
  187.     clc
  188.     adc.z xLocation
  189.     sta.z xLocation
  190.     bcc !+
  191.     inc.z xLocation+1
  192.   !:
  193.     lda #$18
  194.     clc
  195.     adc.z yLocation
  196.     sta.z yLocation
  197.     inc.z index
  198.     jmp __b1
  199.   .segment Data
  200.     toPrint: .text "c64 rulez!"
  201.     .byte 0
  202. }
  203. .segment Code
  204. /**
  205.  * This is the initialisation will
  206.  * determine the machine type
  207.  * by setting the getMachineType global
  208.  * as follows:
  209.  *  37 is PAL
  210.  *  5 is NTSC (old)
  211.  *  6 is NTSC (new)
  212.  *  0 (or any other value) is unknown
  213.  *
  214.  * For safety, the initial value of 0xc000
  215.  * is stored into the accumulator and
  216.  * pushed onto the stack; it is then
  217.  * restored after the getMachineType
  218.  * global is set
  219.  *
  220.  * @author Robin Harbron
  221.  */
  222. setMachineType: {
  223.     lda $c000
  224.     pha
  225.     sei
  226.   __br1:
  227.     lda $d011
  228.     bmi __br1
  229.   __br2:
  230.     lda $d011
  231.     bpl __br2
  232.   __br3:
  233.     lda $d012
  234.     bit $d011
  235.     bpl __ex1
  236.     sta $c000
  237.     bmi __br3
  238.   __ex1:
  239.     cli
  240.     lda #<$c000
  241.     sta.z peek.location
  242.     lda #>$c000
  243.     sta.z peek.location+1
  244.     jsr peek
  245.     sta.z getMachineType
  246.     pla
  247.     sta $c000
  248.     rts
  249. }
  250. /**
  251.  * Disables BASIC interrupts
  252.  */
  253. disableBasicInterrupts: {
  254.     lda #<$dc0e
  255.     sta.z peek.location
  256.     lda #>$dc0e
  257.     sta.z peek.location+1
  258.     jsr peek
  259.     and #$fe
  260.     sta.z poke.value
  261.     lda #0
  262.     sta.z poke.value+1
  263.     lda #<$dc0e
  264.     sta.z poke.location
  265.     lda #>$dc0e
  266.     sta.z poke.location+1
  267.     jsr poke
  268.     rts
  269. }
  270. /**
  271.  * Takes in two 16-bit values, the first is
  272.  * the memory location and the second will be
  273.  * converted to an 8-bit value which is then
  274.  * poked to memory
  275.  */
  276. // poke(word zp(6) location, word zp(8) value)
  277. poke: {
  278.     .label value = 8
  279.     .label location = 6
  280.     lda #$ff
  281.     and.z value
  282.     ldy #0
  283.     sta (location),y
  284.     rts
  285. }
  286. /**
  287.  * Clears the screen according to
  288.  * the current screen memory location
  289.  * pointer at 0xd018
  290.  */
  291. clearScreen: {
  292.     .label screenLocation = $e
  293.     jsr getScreenMemoryLocation
  294.     jsr fillMemory
  295.     rts
  296. }
  297. /**
  298.  * Writes a string to the screen starting
  299.  * from column x and row y (zero indexed)
  300.  */
  301. printAt: {
  302.     .const x = 4
  303.     .const y = $c
  304.     .label screenAddress = $c
  305.     .label index = $16
  306.     lda #<$400+x+y*$28
  307.     sta.z screenAddress
  308.     lda #>$400+x+y*$28
  309.     sta.z screenAddress+1
  310.     lda #0
  311.     sta.z index
  312.   __b1:
  313.     ldy.z index
  314.     lda main.toPrint,y
  315.     cmp #0
  316.     bne __b2
  317.     rts
  318.   __b2:
  319.     lda.z screenAddress
  320.     sta.z poke.location
  321.     lda.z screenAddress+1
  322.     sta.z poke.location+1
  323.     ldy.z index
  324.     lda main.toPrint,y
  325.     sta.z poke.value
  326.     lda #0
  327.     sta.z poke.value+1
  328.     jsr poke
  329.     inc.z screenAddress
  330.     bne !+
  331.     inc.z screenAddress+1
  332.   !:
  333.     inc.z index
  334.     jmp __b1
  335. }
  336. /**
  337.  * Changes the character colour of a
  338.  * screen location starting from column
  339.  * x and row y (zero indexed)
  340.  */
  341. colourAt: {
  342.     .const x = 4
  343.     .const y = $c
  344.     .const colour = 1
  345.     .const numberOfCharacters = $a
  346.     .label colourRamAddress = $19
  347.     lda #<$d800+x+y*$28
  348.     sta.z colourRamAddress
  349.     lda #>$d800+x+y*$28
  350.     sta.z colourRamAddress+1
  351.     ldx #0
  352.   __b1:
  353.     cpx #numberOfCharacters
  354.     bcc __b2
  355.     rts
  356.   __b2:
  357.     lda.z colourRamAddress
  358.     sta.z poke.location
  359.     lda.z colourRamAddress+1
  360.     sta.z poke.location+1
  361.     lda #<colour
  362.     sta.z poke.value
  363.     lda #>colour
  364.     sta.z poke.value+1
  365.     jsr poke
  366.     inc.z colourRamAddress
  367.     bne !+
  368.     inc.z colourRamAddress+1
  369.   !:
  370.     inx
  371.     jmp __b1
  372. }
  373. /**
  374.  * Set sprite to double width (zero indexed)
  375.  */
  376. spriteExpandX: {
  377.     .const spriteNumber = 0
  378.     .label __2 = $16
  379.     lda #<$d01d
  380.     sta.z peek.location
  381.     lda #>$d01d
  382.     sta.z peek.location+1
  383.     jsr peek
  384.     sta.z __2
  385.     ldx #spriteNumber
  386.     jsr getBitNumber
  387.     ora.z __2
  388.     sta.z poke.value
  389.     lda #0
  390.     sta.z poke.value+1
  391.     lda #<$d01d
  392.     sta.z poke.location
  393.     lda #>$d01d
  394.     sta.z poke.location+1
  395.     jsr poke
  396.     rts
  397. }
  398. /**
  399.  * Set sprite to double height (zero indexed)
  400.  */
  401. spriteExpandY: {
  402.     .const spriteNumber = 1
  403.     .label __2 = $1c
  404.     lda #<$d017
  405.     sta.z peek.location
  406.     lda #>$d017
  407.     sta.z peek.location+1
  408.     jsr peek
  409.     sta.z __2
  410.     ldx #spriteNumber
  411.     jsr getBitNumber
  412.     ora.z __2
  413.     sta.z poke.value
  414.     lda #0
  415.     sta.z poke.value+1
  416.     lda #<$d017
  417.     sta.z poke.location
  418.     lda #>$d017
  419.     sta.z poke.location+1
  420.     jsr poke
  421.     rts
  422. }
  423. /**
  424.  * Unset sprite double width (zero indexed)
  425.  */
  426. spriteUnexpandX: {
  427.     .const spriteNumber = 2
  428.     .label __2 = $17
  429.     lda #<$d01d
  430.     sta.z peek.location
  431.     lda #>$d01d
  432.     sta.z peek.location+1
  433.     jsr peek
  434.     sta.z __2
  435.     ldx #spriteNumber
  436.     jsr getBitNumber
  437.     eor.z __2
  438.     sta.z poke.value
  439.     lda #0
  440.     sta.z poke.value+1
  441.     lda #<$d01d
  442.     sta.z poke.location
  443.     lda #>$d01d
  444.     sta.z poke.location+1
  445.     jsr poke
  446.     rts
  447. }
  448. /**
  449.  * Unset sprite double height (zero indexed)
  450.  */
  451. spriteUnexpandY: {
  452.     .const spriteNumber = 3
  453.     .label __2 = $18
  454.     lda #<$d017
  455.     sta.z peek.location
  456.     lda #>$d017
  457.     sta.z peek.location+1
  458.     jsr peek
  459.     sta.z __2
  460.     ldx #spriteNumber
  461.     jsr getBitNumber
  462.     eor.z __2
  463.     sta.z poke.value
  464.     lda #0
  465.     sta.z poke.value+1
  466.     lda #<$d017
  467.     sta.z poke.location
  468.     lda #>$d017
  469.     sta.z poke.location+1
  470.     jsr poke
  471.     rts
  472. }
  473. /**
  474.  * Will check for the current scan line
  475.  * position; returns -1 if the parameter
  476.  * sent is out of bounds (set to 312 assuming
  477.  * PAL - valid range is therefore 0 - 311
  478.  * assuming a zero index); 0 is returned if
  479.  * not at that scan line, and 1 if the
  480.  * parameter matches the current scan line
  481.  *
  482.  * @see setMachineType()
  483.  */
  484. // checkForScanLine(word zp(6) scanLine)
  485. checkForScanLine: {
  486.     .label currentScanLine = $19
  487.     .label scanLine = 6
  488.     lda.z scanLine+1
  489.     cmp #>$137
  490.     bne !+
  491.     lda.z scanLine
  492.     cmp #<$137
  493.   !:
  494.     bcc __b1
  495.     beq __b1
  496.     lda #$37
  497.     cmp.z getMachineType
  498.     beq __b7
  499.   __b1:
  500.     lda.z scanLine+1
  501.     cmp #>$105
  502.     bne !+
  503.     lda.z scanLine
  504.     cmp #<$105
  505.   !:
  506.     bcc __b2
  507.     beq __b2
  508.     lda #6
  509.     cmp.z getMachineType
  510.     beq __b7
  511.   __b2:
  512.     lda.z scanLine+1
  513.     cmp #>$104
  514.     bne !+
  515.     lda.z scanLine
  516.     cmp #<$104
  517.   !:
  518.     bcc __b3
  519.     beq __b3
  520.     lda #5
  521.     cmp.z getMachineType
  522.     beq __b7
  523.   __b3:
  524.     lda #<$d012
  525.     sta.z peek.location
  526.     lda #>$d012
  527.     sta.z peek.location+1
  528.     jsr peek
  529.     sta.z currentScanLine
  530.     lda #0
  531.     sta.z currentScanLine+1
  532.     lda #<$d011
  533.     sta.z peek.location
  534.     lda #>$d011
  535.     sta.z peek.location+1
  536.     jsr peek
  537.     tax
  538.     lda.z scanLine+1
  539.     cmp #>$100
  540.     bcc !+
  541.     bne __b4
  542.     lda.z scanLine
  543.     cmp #<$100
  544.     bcs __b4
  545.   !:
  546.     lda.z scanLine+1
  547.     cmp.z currentScanLine+1
  548.     bne __b4
  549.     lda.z scanLine
  550.     cmp.z currentScanLine
  551.     bne __b4
  552.     cpx #$80
  553.     bcc __b8
  554.   __b4:
  555.     cpx #$7f+1
  556.     bcc __b5
  557.     lda.z scanLine+1
  558.     bne __b6
  559.     lda #$ff
  560.     cmp.z scanLine
  561.     bcc __b6
  562.   __b5:
  563.     lda #0
  564.     rts
  565.   __b7:
  566.     lda #-1
  567.     rts
  568.   __b8:
  569.     lda #1
  570.     rts
  571.   __b6:
  572.     clc
  573.     lda.z currentScanLine
  574.     adc #<$100
  575.     sta.z currentScanLine
  576.     lda.z currentScanLine+1
  577.     adc #>$100
  578.     sta.z currentScanLine+1
  579.     lda.z scanLine+1
  580.     cmp.z currentScanLine+1
  581.     bne __b5
  582.     lda.z scanLine
  583.     cmp.z currentScanLine
  584.     bne __b5
  585.     jmp __b8
  586. }
  587. /**
  588.  * Simple wait function - will count down
  589.  * to zero; accepted parameters is 1 - 65535
  590.  */
  591. // wait(word zp(8) toWaitFor)
  592. wait: {
  593.     .label toWaitFor = 8
  594.     lda #<main.waitState
  595.     sta.z toWaitFor
  596.     lda #>main.waitState
  597.     sta.z toWaitFor+1
  598.   __b1:
  599.     lda.z toWaitFor+1
  600.     bne __b2
  601.     lda.z toWaitFor
  602.     bne __b2
  603.   !:
  604.     rts
  605.   __b2:
  606.     lda.z toWaitFor
  607.     bne !+
  608.     dec.z toWaitFor+1
  609.   !:
  610.     dec.z toWaitFor
  611.     jmp __b1
  612. }
  613. /**
  614.  * Sets the main sprite colour by
  615.  * sprite numbe (zero indexed) and
  616.  * colour (0 - 16) - will return
  617.  * without altering if the spriteNumber
  618.  * is 8 or over.
  619.  */
  620. // setSpriteColour(byte register(A) spriteNumber, byte register(X) colour)
  621. setSpriteColour: {
  622.     cmp #8
  623.     bcs __breturn
  624.     clc
  625.     adc #<$d027
  626.     sta.z poke.location
  627.     lda #>$d027
  628.     adc #0
  629.     sta.z poke.location+1
  630.     txa
  631.     sta.z poke.value
  632.     lda #0
  633.     sta.z poke.value+1
  634.     jsr poke
  635.   __breturn:
  636.     rts
  637. }
  638. /**
  639.  * Will switch on a single sprite of the
  640.  * eight available (zero indexed)
  641.  */
  642. // switchOnSprites(byte register(X) spriteNumber)
  643. switchOnSprites: {
  644.     .label __2 = $1b
  645.     cpx #8
  646.     bcs __breturn
  647.     lda #<$d015
  648.     sta.z peek.location
  649.     lda #>$d015
  650.     sta.z peek.location+1
  651.     jsr peek
  652.     sta.z __2
  653.     jsr getBitNumber
  654.     ora.z __2
  655.     sta.z poke.value
  656.     lda #0
  657.     sta.z poke.value+1
  658.     lda #<$d015
  659.     sta.z poke.location
  660.     lda #>$d015
  661.     sta.z poke.location+1
  662.     jsr poke
  663.   __breturn:
  664.     rts
  665. }
  666. /**
  667.  * Positions a sprite at x pixels across
  668.  * and y pixels down according to the
  669.  * zero-indexed sprite number; note that
  670.  * x can exceed 255
  671.  */
  672. // spriteAt(word zp($12) x, byte zp($1d) y, byte zp($14) spriteNumber)
  673. spriteAt: {
  674.     .label x = $12
  675.     .label y = $1d
  676.     .label spriteNumber = $14
  677.     .label spriteBit = $1c
  678.     .label spriteX = 6
  679.     .label spriteY = $a
  680.     ldx.z spriteNumber
  681.     jsr getBitNumber
  682.     sta.z spriteBit
  683.     lda #<$d010
  684.     sta.z peek.location
  685.     lda #>$d010
  686.     sta.z peek.location+1
  687.     jsr peek
  688.     tax
  689.     txa
  690.     and.z spriteBit
  691.     tay
  692.     lda #$ff
  693.     cmp.z x
  694.     bcc !+
  695.     lda.z x+1
  696.     beq __b4
  697.   !:
  698.     cpy #0
  699.     bne !__b1+
  700.     jmp __b1
  701.   !__b1:
  702.   __b4:
  703.     cpx #0
  704.     beq __b2
  705.     cpy #1
  706.     beq __b5
  707.     jmp __b2
  708.   __b5:
  709.     txa
  710.     sec
  711.     sbc.z spriteBit
  712.     sta.z poke.value
  713.     lda #0
  714.     sta.z poke.value+1
  715.     lda #<$d010
  716.     sta.z poke.location
  717.     lda #>$d010
  718.     sta.z poke.location+1
  719.     jsr poke
  720.   __b2:
  721.     lda.z spriteNumber
  722.     cmp #0
  723.     beq __b8
  724.     lda #<$d001
  725.     sta.z spriteY
  726.     lda #>$d001
  727.     sta.z spriteY+1
  728.     lda #<$d000
  729.     sta.z spriteX
  730.     lda #>$d000
  731.     sta.z spriteX+1
  732.     ldx #0
  733.   __b6:
  734.     cpx.z spriteNumber
  735.     bcc __b7
  736.     jmp __b3
  737.   __b8:
  738.     lda #<$d001
  739.     sta.z spriteY
  740.     lda #>$d001
  741.     sta.z spriteY+1
  742.     lda #<$d000
  743.     sta.z spriteX
  744.     lda #>$d000
  745.     sta.z spriteX+1
  746.   __b3:
  747.     lda.z x
  748.     sta.z poke.value
  749.     lda.z x+1
  750.     sta.z poke.value+1
  751.     jsr poke
  752.     lda.z spriteY
  753.     sta.z poke.location
  754.     lda.z spriteY+1
  755.     sta.z poke.location+1
  756.     lda.z y
  757.     sta.z poke.value
  758.     lda #0
  759.     sta.z poke.value+1
  760.     jsr poke
  761.     rts
  762.   __b7:
  763.     lda #2
  764.     clc
  765.     adc.z spriteX
  766.     sta.z spriteX
  767.     bcc !+
  768.     inc.z spriteX+1
  769.   !:
  770.     lda #2
  771.     clc
  772.     adc.z spriteY
  773.     sta.z spriteY
  774.     bcc !+
  775.     inc.z spriteY+1
  776.   !:
  777.     inx
  778.     jmp __b6
  779.   __b1:
  780.     txa
  781.     ora.z spriteBit
  782.     sta.z poke.value
  783.     lda #0
  784.     sta.z poke.value+1
  785.     lda #<$d010
  786.     sta.z poke.location
  787.     lda #>$d010
  788.     sta.z poke.location+1
  789.     jsr poke
  790.     jmp __b2
  791. }
  792. /**
  793.  * Returns a single byte from a specific
  794.  * memory location
  795.  */
  796. // peek(word zp($c) location)
  797. peek: {
  798.     .label location = $c
  799.     ldy #0
  800.     lda (location),y
  801.     rts
  802. }
  803. /**
  804.  * Returns the current screen location
  805.  * based on the high bits of 0xd018
  806.  */
  807. getScreenMemoryLocation: {
  808.     .label return = $e
  809.     .label screenPointer = $1d
  810.     .label memoryLocation = $e
  811.     lda #<$d018
  812.     sta.z peek.location
  813.     lda #>$d018
  814.     sta.z peek.location+1
  815.     jsr peek
  816.     lsr
  817.     lsr
  818.     lsr
  819.     lsr
  820.     sta.z screenPointer
  821.     lda #<0
  822.     sta.z memoryLocation
  823.     sta.z memoryLocation+1
  824.     tax
  825.   __b1:
  826.     cpx.z screenPointer
  827.     bcc __b2
  828.     rts
  829.   __b2:
  830.     clc
  831.     lda.z memoryLocation
  832.     adc #<$400
  833.     sta.z memoryLocation
  834.     lda.z memoryLocation+1
  835.     adc #>$400
  836.     sta.z memoryLocation+1
  837.     inx
  838.     jmp __b1
  839. }
  840. /**
  841.  * From a 16-bit start position, it will store
  842.  * the byte value in toFill by a set number
  843.  * of bytes
  844.  */
  845. // fillMemory(word zp($e) startPosition)
  846. fillMemory: {
  847.     .const toFill = $20
  848.     .const numberOfBytes = $3e8
  849.     .label index = $10
  850.     .label startPosition = $e
  851.     lda #<0
  852.     sta.z index
  853.     sta.z index+1
  854.   __b1:
  855.     lda.z index+1
  856.     cmp #>numberOfBytes
  857.     bcc __b2
  858.     bne !+
  859.     lda.z index
  860.     cmp #<numberOfBytes
  861.     bcc __b2
  862.   !:
  863.     rts
  864.   __b2:
  865.     lda.z startPosition
  866.     clc
  867.     adc.z index
  868.     sta.z poke.location
  869.     lda.z startPosition+1
  870.     adc.z index+1
  871.     sta.z poke.location+1
  872.     lda #<toFill
  873.     sta.z poke.value
  874.     lda #>toFill
  875.     sta.z poke.value+1
  876.     jsr poke
  877.     inc.z index
  878.     bne !+
  879.     inc.z index+1
  880.   !:
  881.     jmp __b1
  882. }
  883. /**
  884.  * Returns a value from 0 - 7 as its binary
  885.  * equivalent, for instance, sending 3 to
  886.  * this function will return 4; sending 7
  887.  * will return 128
  888.  */
  889. // getBitNumber(byte register(X) bit)
  890. getBitNumber: {
  891.     .const returnBit = 1
  892.     lda #returnBit
  893.     cpx #0
  894.     beq !e+
  895.   !:
  896.     asl
  897.     dex
  898.     bne !-
  899.   !e:
  900.     rts
  901. }
  902.  
RAW Paste Data