├── .gitignore ├── Asm4Kids ├── 10transfer.asm ├── 11incrementdecrement.asm ├── 12append.asm ├── 13link.asm ├── 14indexedadressing.asm ├── 15indexedadressingscreen.asm ├── 16indexedindirect.asm ├── 17indirectindexed.asm ├── 18loop.asm ├── 19indexingloop.asm ├── 1begin.asm ├── 20fillscreenloop.asm ├── 20fillscreenloop.bas ├── 21nestedloop.asm ├── 21nestedloop.bas ├── 22beqjmp.asm ├── 23inc.asm ├── 24incindexed.asm ├── 25adc.asm ├── 26adcby2s.asm ├── 27sbcby3s.asm ├── 28keyboard2screen.asm ├── 29betterkeyboard2screen.asm ├── 2ldatest.asm ├── 30redgreenbackground.asm ├── 31joystick.asm ├── 32joystickcolors.asm ├── 33lowreslines.asm ├── 34verticallines.asm ├── 35diagonallines.asm ├── 36animation.asm ├── 36animation.bas ├── 37joystickcursor.asm ├── 38joystickdraw.asm ├── 39spritezero.asm ├── 3printname.asm ├── 40planetdestroyer.asm ├── 41spriteassembler.bas ├── 42spritetester.asm ├── 43assemblysounds.asm ├── 44noisysprite.asm ├── 45joysticksprite.asm ├── 4ssta.asm ├── 5black.asm ├── 6on.asm ├── 7off.asm ├── 8putitonthescreen.asm ├── 9xyplot.asm └── Asm4Kids.cbmprj ├── C64128Asm ├── 0hitest.asm ├── 10stacknumbers.asm ├── 1hitest.bas ├── 2bindec.bas ├── 3decbin.bas ├── 4dechexdec.bas ├── 5store16bitinram.bas ├── 6addition.asm ├── 7printit.asm ├── 8addwithcheck.asm ├── 9txtbuf.asm └── C64128Asm.cbmprj ├── C64AsmLang ├── 10simplesubtraction.bas ├── 11doublebytesubtraction.bas ├── 12negation.bas ├── 13simplebcdaddition.bas ├── 14absoluteaddressing.bas ├── 15absoluteindexedaddressing.bas ├── 16indirectjumping.bas ├── 17indirectaddressing.bas ├── 18incrementingregister.bas ├── 19tenexlamationmarks.bas ├── 1machinecodedemo.bas ├── 20forwardbranching.bas ├── 21downcount.bas ├── 22incrementingmemory.bas ├── 23decrementingmemory.bas ├── 24subroutinedemo.bas ├── 25jumping.bas ├── 26multiplybyfour.bas ├── 27testbit0.bas ├── 28binaryoutputofsr.bas ├── 29simplemultiplication.bas ├── 2abovememsiz.bas ├── 30singlebytemult.bas ├── 31singlebytedivide.bas ├── 32conditionalassembly.bas ├── 33centrigradetofahrenheit.bas ├── 36aenterprise.bas ├── 36benterprise.bas ├── 36centerpriseflies.bas ├── 37usrdemo.bas ├── 38savefac1.bas ├── 39integertofp.bas ├── 3placeinfreeram.bas ├── 40fptointeger.bas ├── 41asciihextobinary.bas ├── 42binarytoasciihex.bas ├── 43outputasciistring.bas ├── 4rvsonusingpokes.bas ├── 5hexloader.bas ├── 6zeropageimmediate.bas ├── 7simpleadd.bas ├── 8singlebyteadd.bas ├── 9doublebyteadd.bas ├── C64AsmLang.cbmprj └── enterprise.spt ├── C64ColorGraphics ├── 1beginner │ ├── 1lighthouse.bas │ ├── 2ship.bas │ ├── 3sun.bas │ ├── 4toolkit.bas │ ├── 5tookitoptimized.bas │ ├── C64ColorGraphicsBeginner.cbmprj │ ├── boat.png │ ├── disk.d64 │ └── sun.spt └── 2advanced │ ├── 10spacecraftsprite.bas │ ├── 1helper.bas │ ├── 2checker.bas │ ├── 3.first.bas │ ├── 4shapes.bas │ ├── 5painting.bas │ ├── 6building.bas │ ├── 7translate.bas │ ├── 8scale.bas │ ├── 9rotate.bas │ ├── C64ColorGraphicsAdvanced.cbmprj │ ├── disk.d64 │ └── spacecraft.spt ├── C64StepByStep ├── book1 │ ├── 10conversion.bas │ ├── 11alphasorter.bas │ ├── 12colorchange.bas │ ├── 13cursorcontrol.bas │ ├── 14jiffyclock.bas │ ├── 15characterset.bas │ ├── 16keyboardgraphics.bas │ ├── 17rectangle.bas │ ├── 18screencolormap.bas │ ├── 19screencolormap.bas │ ├── 1squared.bas │ ├── 20bouncingball.bas │ ├── 21constellation.bas │ ├── 22telephonelist.bas │ ├── 23maze.bas │ ├── 24dataanimation.bas │ ├── 25taxrates.bas │ ├── 26singlesprite.bas │ ├── 27singlespritesimplified.bas │ ├── 28doublesprite.bas │ ├── 29siren.bas │ ├── 2display.bas │ ├── 30machinegun.bas │ ├── 31lasercannon.bas │ ├── 32bird.bas │ ├── 33engine.bas │ ├── 34datatune.bas │ ├── 35chordsimple.bas │ ├── 36sheetmusic.bas │ ├── 37random.bas │ ├── 38cointoss.bas │ ├── 39randomtest.bas │ ├── 3calculations.bas │ ├── 40randomgraphics.bas │ ├── 4conversions.bas │ ├── 5operator.bas │ ├── 6asciicolors.bas │ ├── 7printing.bas │ ├── 8neverending.bas │ ├── 9fornext.bas │ ├── c64stepbystep1.cbmprj │ └── singlesprite.spt └── book2 │ ├── 10andorcalculator.bas │ ├── 11highresbasic.bas │ ├── 12highresmachinecode.bas │ ├── 13parallellines.bas │ ├── 14triangle.bas │ ├── 15pinandstring.bas │ ├── 16linemachine.bas │ ├── 1stardistance.bas │ ├── 2carpetcoster.bas │ ├── 3bouncingball.bas │ ├── 4doublebouncingball.bas │ ├── 5firebase.bas │ ├── 6keyboardencoder.bas │ ├── 7functionkeydetect.bas │ ├── 8reactiontester.bas │ ├── 9andorsprites.bas │ ├── andorsprites.spt │ └── c64stepbystep2.cbmprj ├── LICENSE ├── README.md ├── asm4kids.jpg ├── book1n2.jpg ├── c64128asm.jpg ├── c64asmlang.jpg ├── cgraphicsa.jpg ├── cgraphicsb.jpg └── cheatsheet.md /.gitignore: -------------------------------------------------------------------------------- 1 | bak 2 | *.prg 3 | *.tmp 4 | *.dmp 5 | -------------------------------------------------------------------------------- /Asm4Kids/10transfer.asm: -------------------------------------------------------------------------------- 1 | ; 10 SYS (49152) 2 | 3 | *=$0801 4 | 5 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 6 | 7 | 8 | *=$c000 9 | jsr $e544 ; clear the screen 10 | ldx #$54 ; load 84 into the x register ('t') 11 | txa ; transfer x register to the accumulator 12 | jsr $e716 ; output to screen 13 | ldx #$41 ; load 65 into x register ('a') 14 | txa ; transfer x register to the accumulator 15 | sta 49200 ; store accumulator value in address 49200 16 | ldy 49200 ; load value of 49200 into y register (absolute addressing mode) 17 | tya ; transfer y to a 18 | jsr $e716 ; output to screen 19 | ldy #$58 ; load y with 88 ('x') 20 | tya ; transfer y to a 21 | jsr $e716 ; output to screen 22 | rts 23 | -------------------------------------------------------------------------------- /Asm4Kids/11incrementdecrement.asm: -------------------------------------------------------------------------------- 1 | ; 10 SYS (49152) 2 | 3 | *=$0801 4 | 5 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 6 | 7 | 8 | *=$c000 9 | jsr $e544 ; clear screen (58692) 10 | ldx #90 11 | ldy #65 12 | txa 13 | jsr $e716 ; output to screen 14 | tya 15 | jsr $e716 16 | dex ; subtract 1 from x register (decrement x) 17 | txa 18 | jsr $e716 19 | iny ; add 1 to y register (increment y) 20 | tya 21 | jsr $e716 22 | rts 23 | -------------------------------------------------------------------------------- /Asm4Kids/12append.asm: -------------------------------------------------------------------------------- 1 | ; append 2 | ; resets the pointers showing the beginning of the BASIC program 3 | ; to the end of the program in memory 4 | ; Needs the link program 5 | 6 | ; 10 SYS (49152) 7 | 8 | *=$0801 9 | 10 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 11 | 12 | 13 | *=$c000 14 | ldx $2d 15 | dex 16 | dex 17 | stx $2b 18 | ldx $2e 19 | stx $2c 20 | rts 21 | -------------------------------------------------------------------------------- /Asm4Kids/13link.asm: -------------------------------------------------------------------------------- 1 | ; link 2 | ; resets the pointers the the actual beginning of BASIC 3 | ; thereby linking two programs together 4 | 5 | ; 10 SYS (49200) 6 | 7 | *=$0801 8 | 9 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $32, $30, $30, $29, $00, $00, $00 10 | 11 | *=$c030 12 | lda #1 13 | sta $2b 14 | lda #8 15 | sta $2c 16 | rts 17 | -------------------------------------------------------------------------------- /Asm4Kids/14indexedadressing.asm: -------------------------------------------------------------------------------- 1 | ; indexed absolute adressing 2 | ; add the value of x or y register to the address in the operand 3 | ; address = adress + value of x or y register 4 | 5 | ; 10 SYS (49152) 6 | 7 | *=$0801 8 | 9 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 10 | 11 | 12 | *=$c000 13 | ldx #0 14 | txa 15 | sta $400,x ; stores at $400 16 | inx ; add 1 to x 17 | txa 18 | sta $400,x ; store at $401 19 | rts 20 | -------------------------------------------------------------------------------- /Asm4Kids/15indexedadressingscreen.asm: -------------------------------------------------------------------------------- 1 | ; uses indexed adressing with screen and color memory 2 | 3 | ; 10 SYS (49152) 4 | 5 | *=$0801 6 | 7 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 8 | 9 | *=$c000 10 | jsr $e544 ; clear screen 11 | lda #4 12 | sta $d021 ; background color (53281) 13 | sta $d020 ; border color (53280) 14 | lda #1 15 | ldx #0 16 | sta $d800,x ; base color address + x 17 | sta $400,x ; base screen address + x 18 | inx 19 | sta $d800,x 20 | sta $400,x 21 | inx 22 | sta $d800,x 23 | sta $400,x 24 | rts 25 | -------------------------------------------------------------------------------- /Asm4Kids/16indexedindirect.asm: -------------------------------------------------------------------------------- 1 | ; indexed indirect addressing 2 | ; a bit like a "bank shot" in pool 3 | ; address = pointer stored in zero page + x register value = location of address 4 | 5 | ; in zero page ($0-ff) a set of pointers are stored in 2-byte configurations 6 | ; low-byte is at the lower address, and the high-byte is at the higher address 7 | 8 | ; each pointer takes up two bytes (low and high) and that means that 9 | ; the indexing will have to be in steps of two 10 | 11 | 12 | ; 10 SYS (49152) 13 | 14 | *=$0801 15 | 16 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 17 | 18 | 19 | *=$c000 20 | jsr $e544 ; clear screen 21 | ldy #65 ; load y with ASCII 'a' 22 | sty $c100 ; store y in $c100 23 | lda #$00 ; low byte of target address 24 | sta $fb ; store in lb pointer address 25 | lda #$c1 ; high byte of pointer address 26 | sta $fc ; store in hb pointer address 27 | ldx #$0 28 | lda ($fb,x) ; indexed indirect lda 29 | jsr $e716 ; output to screen 30 | rts 31 | -------------------------------------------------------------------------------- /Asm4Kids/17indirectindexed.asm: -------------------------------------------------------------------------------- 1 | ; indirect indexed addressing (y register only) 2 | ; Uses a zero-page pointer, but uses y instead of x 3 | ; instead of pointing to a series of addresses in the zero page 4 | ; it points to a single address offset by the value of y 5 | ; Since it requires only two bytes of zero-page, it is much easier to 6 | ; use than indexed indirect 7 | 8 | ; address = pointer stored in zero page + x register value = location of address 9 | 10 | ; 10 SYS (49152) 11 | 12 | *=$0801 13 | 14 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 15 | 16 | 17 | *=$c000 18 | jsr $e544 19 | ldx #$d1 ; low byte target address 20 | stx $fb ; low byte pointer 21 | ldx #$c0 ; high byte target address 22 | stx $fc ; high byte pointer 23 | ldx #65 ; ASCII 'a' 24 | stx $c0d1 ; store in first target address 25 | inx 26 | stx $c0d3 27 | inx 28 | stx $c0d5 29 | ldy #$0 ; set y to $0 30 | lda ($fb),y ; indirect indexed adressing mode 31 | jsr $e716 32 | iny 33 | iny 34 | lda ($fb),y 35 | jsr $e716 36 | iny 37 | iny 38 | lda ($fb),y 39 | jsr $e716 40 | rts 41 | -------------------------------------------------------------------------------- /Asm4Kids/18loop.asm: -------------------------------------------------------------------------------- 1 | ; loop using cpx (compare x) and bne (branch is not equal) 2 | ; prints a-z 3 | 4 | ; 10 SYS (49152) 5 | 6 | *=$0801 7 | 8 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 9 | 10 | *=$c000 11 | jsr $e544 12 | ldx #65 ; initialize x with 65 - ASCII a 13 | loop txa ; transfer x to accumulator 14 | jsr $e716 ; print it to the screen 15 | inx ; increment x 16 | cpx #91 ; compare x with 91 17 | bne loop ; if x <> 91 then branch back to loop 18 | rts 19 | -------------------------------------------------------------------------------- /Asm4Kids/19indexingloop.asm: -------------------------------------------------------------------------------- 1 | ; example of indexed addressing and a loop 2 | 3 | ; 10 SYS (49152) 4 | 5 | *=$0801 6 | 7 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 8 | 9 | *=$c000 10 | jsr $e544 11 | ldx #0 12 | ldy #1 13 | start tya 14 | sta 55296,x 15 | txa 16 | sta 1024,x 17 | inx 18 | cpx #255 19 | bne start 20 | rts 21 | -------------------------------------------------------------------------------- /Asm4Kids/1begin.asm: -------------------------------------------------------------------------------- 1 | ; 10 SYS (49152) 2 | 3 | *=$0801 4 | 5 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 6 | 7 | jsr $e544 8 | rts 9 | -------------------------------------------------------------------------------- /Asm4Kids/20fillscreenloop.asm: -------------------------------------------------------------------------------- 1 | ; fill screen with colored characters - compare speed with basic variant 2 | ; 10 SYS (49152) 3 | 4 | *=$0801 5 | 6 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 7 | 8 | *=$c000 9 | jsr $e544 10 | ldx #0 11 | loop txa 12 | sta 55296,x ; base color address 13 | sta 55546,x 14 | sta 55796,x 15 | sta 56046,x 16 | sta 1024,x ; base screen address 17 | sta 1274,x 18 | sta 1524,x 19 | sta 1774,x 20 | inx 21 | cpx #250 ; compare x value with 250 22 | bne loop 23 | rts 24 | -------------------------------------------------------------------------------- /Asm4Kids/20fillscreenloop.bas: -------------------------------------------------------------------------------- 1 | 10 print chr$(147) 2 | 20 for x = 0 to 249 3 | 30 poke 55296 + x,x : poke 55546 + x,x 4 | 40 poke 55796 + x,x : poke 56046 + x,x 5 | 60 poke 1024 + x,x : poke 1274 + x,x 6 | 70 poke 1524 + x,x : poke 1774 + x,x 7 | 80 next -------------------------------------------------------------------------------- /Asm4Kids/21nestedloop.asm: -------------------------------------------------------------------------------- 1 | ; using a nested loop to overcome the 255 limitation in the x/y registers 2 | ; loop 127 * 10 times 3 | 4 | ; 10 SYS (49152) 5 | 6 | *=$0801 7 | 8 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 9 | 10 | *=$c000 11 | jsr $e544 12 | ldy #0 13 | loop1 ldx #33 14 | loop2 txa 15 | jsr $e716 16 | inx 17 | cpx #127 18 | bne loop2 19 | iny 20 | cpy #10 21 | bne loop1 22 | rts 23 | -------------------------------------------------------------------------------- /Asm4Kids/21nestedloop.bas: -------------------------------------------------------------------------------- 1 | 10 print chr$(147) 2 | 20 for y = 0 to 9 : rem loop 1 3 | 30 for x = 33 to 127 : rem loop 2 4 | 40 print chr$(x); 5 | 50 next x : rem branch to loop 2 6 | 60 next y : rem branch to loop 1 -------------------------------------------------------------------------------- /Asm4Kids/22beqjmp.asm: -------------------------------------------------------------------------------- 1 | ; print the alphabet to the screen until it reaches value 90 2 | ; jmp and beq allows us to place inx after 3 | ; the comparison and branch instructions 4 | 5 | ; 10 SYS (49152) 6 | 7 | *=$0801 8 | 9 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 10 | 11 | *=$c000 12 | ldx #65 13 | start txa 14 | jsr $e716 15 | cmp #90 16 | beq end 17 | inx 18 | jmp start 19 | end rts 20 | -------------------------------------------------------------------------------- /Asm4Kids/23inc.asm: -------------------------------------------------------------------------------- 1 | ; inc increments the value of the target address by one in the absolute mode 2 | 3 | ; 10 SYS (49152) 4 | 5 | *=$0801 6 | 7 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 8 | 9 | *=$c000 10 | lda #64 11 | sta $c100 12 | start inc $c100 13 | lda $c100 14 | jsr $e716 15 | cmp #90 16 | bne start 17 | rts 18 | -------------------------------------------------------------------------------- /Asm4Kids/24incindexed.asm: -------------------------------------------------------------------------------- 1 | ; inc in indexed mode 2 | ; fills the screen with an a and a lot of emptiness or junk 3 | ; depending on what's in the addresses 4 | 5 | ; 10 SYS (49152) 6 | 7 | *=$0801 8 | 9 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 10 | 11 | *=$c000 12 | ldx #0 13 | lda #64 14 | sta $c100 15 | start inc $c100,x 16 | lda $c100,x 17 | jsr $e716 18 | inx 19 | cpx #90 20 | bne start 21 | rts 22 | -------------------------------------------------------------------------------- /Asm4Kids/25adc.asm: -------------------------------------------------------------------------------- 1 | ; indexed adc 2 | ; print az by adding 25 to the accumulator which already contains 65 3 | 4 | ; 10 SYS (49152) 5 | 6 | *=$0801 7 | 8 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 9 | 10 | *=$c000 11 | lda #65 12 | jsr $e716 13 | adc #25 ; adc = add with carry, accumulator 14 | jsr $e716 15 | rts 16 | -------------------------------------------------------------------------------- /Asm4Kids/26adcby2s.asm: -------------------------------------------------------------------------------- 1 | ; adc by two's 2 | ; the accumulator is incremented by two each time the program loops 3 | ; the clc instruction makes sure that the contents of the accumulator 4 | ; are incremented only by two and not two plus the carry 5 | 6 | ; 10 SYS (49152) 7 | 8 | *=$0801 9 | 10 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 11 | 12 | *=$c000 13 | jsr $e544 14 | lda #65 15 | start clc 16 | adc #2 17 | jsr $e716 18 | cmp #89 19 | bne start 20 | rts 21 | -------------------------------------------------------------------------------- /Asm4Kids/27sbcby3s.asm: -------------------------------------------------------------------------------- 1 | ;************************************************ 2 | ;* sbc by three's * 3 | ;* * 4 | ;* Goes backwards, printing only every third * 5 | ;* character. * 6 | ;* * 7 | ;* Important to set the carry flag before * 8 | ;* using subtract! * 9 | ;* * 10 | ;************************************************ 11 | 12 | ; 10 SYS (49152) 13 | 14 | *=$0801 15 | 16 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 17 | 18 | *=$c000 19 | jsr $e544 20 | lda #93 21 | start sec ; set the carry 22 | sbc #3 ; subtract 3 from the accumulator 23 | jsr $e716 24 | cmp #66 25 | bne start 26 | rts 27 | -------------------------------------------------------------------------------- /Asm4Kids/28keyboard2screen.asm: -------------------------------------------------------------------------------- 1 | ;**************************************** 2 | ;* * 3 | ;* Keyboard to screen i/o * 4 | ;* * 5 | ;* Uses labels to clarify * 6 | ;* what's going on' * 7 | ;* * 8 | ;**************************************** 9 | ; 10 SYS (49152) 10 | 11 | *=$0801 12 | 13 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 14 | 15 | *=$c000 16 | clear =$e544 17 | scnkey =$ff9f 18 | getin =$ffe4 19 | chrout =$ffd2 20 | 21 | jsr clear 22 | scan jsr scnkey ; look to see if key is pressed 23 | jsr getin ; put key value in accumulator 24 | beq scan ; compare with zero 25 | jsr chrout ; if not zero, print to screen 26 | rts 27 | -------------------------------------------------------------------------------- /Asm4Kids/29betterkeyboard2screen.asm: -------------------------------------------------------------------------------- 1 | ;**************************************** 2 | ;* * 3 | ;* Read return * 4 | ;* * 5 | ;* Reds keypresses and prints them * 6 | ;* until Return is pressed * 7 | ;* * 8 | ;**************************************** 9 | 10 | ; 10 SYS (49152) 11 | 12 | *=$0801 13 | 14 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 15 | 16 | *=$c000 17 | clear =$e544 18 | scnkey =$ff9f 19 | getin =$ffe4 20 | chrout =$ffd2 21 | 22 | jsr clear 23 | scan jsr scnkey 24 | jsr getin 25 | beq scan 26 | cmp #$0d ; compare with ASCII for return (13) 27 | beq end ; jump to end of program if return is pressed 28 | jsr chrout 29 | jmp scan 30 | end rts 31 | -------------------------------------------------------------------------------- /Asm4Kids/2ldatest.asm: -------------------------------------------------------------------------------- 1 | ; clears the screen, then outputs 'x' to the screen 2 | ; 10 SYS (49152) 3 | 4 | *=$0801 5 | 6 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 7 | 8 | 9 | *=$c000 10 | jsr $e544 ; clear screen 11 | lda #88 ; load the accumulator with the decimal value 88 12 | jsr $e716 ; output to screen 13 | rts 14 | -------------------------------------------------------------------------------- /Asm4Kids/30redgreenbackground.asm: -------------------------------------------------------------------------------- 1 | ;**************************************** 2 | ;* * 3 | ;* Red/green background * 4 | ;* * 5 | ;**************************************** 6 | 7 | ; 10 SYS (49152) 8 | 9 | *=$0801 10 | 11 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 12 | 13 | *=$c000 14 | clear =$e544 ; 58692 15 | scnkey =$ff9f ; 65439 16 | getin =$ffe4 ; 65508 17 | chrout =$ffd2 ; 65490 18 | bkgnd =$d021 ; 53281 19 | 20 | jsr clear 21 | lda #67 ; c 22 | jsr chrout 23 | lda #79 ; o 24 | jsr chrout 25 | lda #76 ; l 26 | jsr chrout 27 | lda #79 ; o 28 | jsr chrout 29 | lda #82 ; r 30 | jsr chrout 31 | lda #63 ; ? 32 | jsr chrout 33 | lda #0 ; null the accumulator 34 | scan jsr scnkey 35 | jsr getin 36 | beq scan 37 | cmp #$0d ; was return pressed? 38 | beq end ; if so, goto end 39 | cmp #82 ; was r pressed? 40 | beq red ; if so, goto red 41 | cmp #71 ; was g pressed? 42 | beq green ; if so, goto green 43 | jmp scan ; if none of the above, go get another key 44 | red lda #2 ; color code for red background 45 | sta bkgnd 46 | jmp scan 47 | green lda #5 ; color code for green 48 | sta bkgnd 49 | jmp scan ; go get another key 50 | end rts 51 | -------------------------------------------------------------------------------- /Asm4Kids/31joystick.asm: -------------------------------------------------------------------------------- 1 | ;**************************************** 2 | ;* * 3 | ;* Joystick * 4 | ;* * 5 | ;* Register at $dc01 : * 6 | ;* * 7 | ;* 7 6 5 4 3 2 1 0 * 8 | ;* X X X F R L D U * 9 | ;* * 10 | ;* X = Unused by joystick * 11 | ;* F = Fire button * 12 | ;* R = Joystick right * 13 | ;* L = Joystick left * 14 | ;* D = Joystick down * 15 | ;* U = Joystick up * 16 | ;* Not pressed = 1 * 17 | ;* Pressed = 0 * 18 | ;* * 19 | ;* Joystick values EORed with $ff : * 20 | ;* 0 - Neutral * 21 | ;* 1 - Up * 22 | ;* 2 - Down * 23 | ;* 4 - Left * 24 | ;* 5 - Up Left * 25 | ;* 6 - Down Left * 26 | ;* 8 - Right * 27 | ;* 9 - Up Right * 28 | ;* 10 - Down Right * 29 | ;* 16 - Fire button pressed * 30 | ;* * 31 | ;**************************************** 32 | 33 | ; 10 SYS (49152) 34 | 35 | *=$0801 36 | 37 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 38 | 39 | *=$c000 40 | jstick =$dc01 41 | ofset =$c100 42 | clear =$e544 43 | fire =$c102 44 | chrout =$ffd2 45 | 46 | jsr clear 47 | lda #$ff ; value to EOR 48 | sta ofset ; offset 49 | lda #64 ; EORed value of fire button + 48 50 | sta fire ; store here for easy reference 51 | start lda jstick ; read joystick 52 | eor ofset ; eor with $ff 53 | clc ; clear the carry flag 54 | adc #48 ; add 48 55 | jsr chrout ; print modified joystick value to screen 56 | cmp fire ; is it the fire button? 57 | beq end ; if it is, then quit 58 | jmp start ; go back and read the joystick 59 | end rts 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /Asm4Kids/32joystickcolors.asm: -------------------------------------------------------------------------------- 1 | ;**************************************** 2 | ;* * 3 | ;* Joystick colors * 4 | ;* * 5 | ;* Change the background colors * 6 | ;* using the joystick * 7 | ;* * 8 | ;**************************************** 9 | 10 | ; 10 SYS (49152) 11 | 12 | *=$0801 13 | 14 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 15 | 16 | *=$c000 17 | jstick =$dc01 18 | ofset =$c100 19 | clear =$e544 20 | fire =$c102 21 | 22 | jsr clear 23 | lda #$ff ; value to eor 24 | sta ofset ; eor offset 25 | lda #16 ; eor'ed value of fire button 26 | sta fire ; store here for easy reference 27 | start lda jstick ; read joystick 28 | eor ofset ; eor with $ff 29 | cmp fire ; fire button pressed? 30 | beq end ; if it is, then quit 31 | sta $d021 ; put joystick value into background color register 32 | jmp start 33 | end rts 34 | -------------------------------------------------------------------------------- /Asm4Kids/33lowreslines.asm: -------------------------------------------------------------------------------- 1 | ;**************************************** 2 | ;* * 3 | ;* low-res lines * 4 | ;* * 5 | ;**************************************** 6 | 7 | ; 10 SYS (49152) 8 | 9 | *=$0801 10 | 11 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 12 | 13 | *=$c000 14 | bar1 =55416 15 | bar2 =55496 16 | lin1 =1144 17 | lin2 =1224 18 | clear =$e544 19 | 20 | jsr clear 21 | ldx #$0 22 | ldy #2 23 | start lda #224 24 | sta lin1,x ; first line of spaces 25 | sta lin2,x ; second line of spaces 26 | tya 27 | sta bar1,x ; first color of line 28 | clc 29 | adc #5 ; change color with adc 30 | sta bar2,x ; second color of line 31 | inx 32 | cpx #39 33 | bne start 34 | rts 35 | -------------------------------------------------------------------------------- /Asm4Kids/34verticallines.asm: -------------------------------------------------------------------------------- 1 | ;**************************************** 2 | ;* * 3 | ;* vertical lines * 4 | ;* * 5 | ;**************************************** 6 | 7 | ; 10 SYS (49152) 8 | 9 | *=$0801 10 | 11 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 12 | 13 | *=$c000 14 | bar1 =55316 15 | bar2 =55556 16 | bar3 =55796 17 | bar4 =56036 18 | bar5 =56276 19 | lin1 =1044 20 | lin2 =1284 21 | lin3 =1324 22 | lin4 =1564 23 | lin5 =1804 24 | clear =$e544 25 | 26 | jsr clear 27 | ldx #$0 28 | start lda #224 29 | sta lin1,x 30 | sta lin2,x 31 | sta lin3,x 32 | sta lin4,x 33 | sta lin5,x 34 | lda #2 35 | sta bar1,x 36 | sta bar2,x 37 | sta bar3,x 38 | sta bar4,x 39 | sta bar5,x 40 | ldy #0 41 | inxr inx 42 | iny 43 | cpy #40 44 | bne inxr 45 | cpx #240 46 | bne start 47 | rts 48 | -------------------------------------------------------------------------------- /Asm4Kids/35diagonallines.asm: -------------------------------------------------------------------------------- 1 | ;**************************************** 2 | ;* * 3 | ;* diagonal lines * 4 | ;* * 5 | ;**************************************** 6 | 7 | ; 10 SYS (49152) 8 | 9 | *=$0801 10 | 11 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 12 | 13 | *=$c000 14 | chrout =$ffd2 15 | clear =$e544 16 | plot =$fff0 17 | 18 | jsr clear 19 | ldx #0 20 | ldy #0 21 | lda #18 ; character for inverse 22 | jsr chrout 23 | start clc 24 | jsr plot 25 | lda #32 ; character for space 26 | jsr chrout 27 | inx ; next row 28 | iny 29 | cpx #25 ; is it at the bottom row yet? 30 | bne start ; if not, go back and do it again 31 | rts 32 | -------------------------------------------------------------------------------- /Asm4Kids/36animation.asm: -------------------------------------------------------------------------------- 1 | ;**************************************** 2 | ;* * 3 | ;* animation * 4 | ;* * 5 | ;* Needs a pause loop because it's too * 6 | ;* fast! * 7 | ;* * 8 | ;**************************************** 9 | 10 | ; 10 SYS (49152) 11 | 12 | *=$0801 13 | 14 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 15 | 16 | *=$c000 17 | clear =$e544 18 | chrout =$ffd2 19 | plot =$fff0 20 | ex =$c200 21 | why =$c202 22 | ball =$c204 23 | space =$c206 24 | 25 | jsr clear 26 | ldx #10 ; set to row 10 27 | stx ex 28 | ldy #0 ; set to column 0 29 | sty why 30 | lda #113 ; ascii for ball 31 | sta ball 32 | lda #32 ; ascii for space 33 | sta space 34 | start ldx ex 35 | ldy why 36 | clc 37 | jsr plot ; plot the ball 38 | lda ball ; load the ball 39 | jsr chrout ; print the ball 40 | 41 | ldy #0 ; begin pause loop 42 | pause1 ldx #0 43 | pause2 inx 44 | cpx #$fe 45 | bne pause2 46 | iny 47 | cpy #$0a 48 | bne pause1 ; end pause loop 49 | 50 | ldx ex ; load x register with last row plot 51 | ldy why ; load y register with last column plot 52 | clc 53 | jsr plot ; plot the space 54 | lda space 55 | jsr chrout ; erase the ball with space 56 | inc why ; increment the column value (y) 57 | ldy why ; load the y register with the next column 58 | cpy #38 ; is it near the last column 59 | bne start ; if not. print and erase another ball 60 | clc 61 | jsr plot 62 | lda ball 63 | jsr chrout ; put a ball on the screen so there's something left 64 | rts 65 | -------------------------------------------------------------------------------- /Asm4Kids/36animation.bas: -------------------------------------------------------------------------------- 1 | 10 print chr$(147) 2 | 20 for x = 1 to 10 : print : next 3 | 30 for x = 1 to 39 : print chr$(113); : print chr$(157); chr$(32); 4 | 40 next 5 | 50 print chr$(113) -------------------------------------------------------------------------------- /Asm4Kids/37joystickcursor.asm: -------------------------------------------------------------------------------- 1 | ;**************************************** 2 | ;* * 3 | ;* joystick cursor * 4 | ;* * 5 | ;* * 6 | ;**************************************** 7 | 8 | ; 10 SYS (49152) 9 | 10 | *=$0801 11 | 12 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 13 | 14 | *=$c000 15 | clear =$e544 16 | jstick =$dc01 17 | ofset =$c200 18 | fire =$c202 19 | inverse =$c204 20 | normal =$c206 21 | mark =$c208 22 | chrout =$ffd2 23 | 24 | jsr clear 25 | lda #$ff ; or value 26 | sta ofset 27 | lda #16 ; fire button 28 | sta fire 29 | lda #32 ; space for the cursor 30 | sta mark 31 | lda #18 ; inverse code 32 | sta inverse 33 | lda #146 ; normal code 34 | sta normal 35 | start lda jstick 36 | eor ofset 37 | cmp #1 ; joystick up? 38 | beq up 39 | cmp #2 ; down? 40 | beq down 41 | cmp #4 ; left? 42 | beq left 43 | cmp #8 ; right? 44 | beq right 45 | cmp fire ; fire button pressed? 46 | beq end ; if so, end 47 | cursor lda mark ; load the space 48 | jsr chrout ; print the space 49 | lda #157 ; load the left cursor 50 | jsr chrout ; back up 51 | lda normal 52 | jsr chrout ; set normal 53 | lda mark 54 | jsr chrout 55 | lda #157 ; back up 56 | jsr chrout 57 | lda inverse 58 | jsr chrout ; set inverse 59 | jmp start ; go do it again 60 | up lda #145 61 | jmp print ; print up cursor 62 | down lda #17 63 | jmp print ; print down cursor 64 | left lda #157 65 | jmp print ; print left cursor 66 | right lda #29 67 | print jsr chrout 68 | jmp cursor 69 | end rts 70 | 71 | -------------------------------------------------------------------------------- /Asm4Kids/38joystickdraw.asm: -------------------------------------------------------------------------------- 1 | ;**************************************** 2 | ;* * 3 | ;* joystick draw * 4 | ;* * 5 | ;* Does not work! * 6 | ;**************************************** 7 | 8 | ; 10 SYS (49152) 9 | 10 | *=$0801 11 | 12 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 13 | 14 | *=$c000 15 | clear =$e544 16 | jstick =$dc01 17 | ofset =$c200 18 | fire =$c202 19 | inverse =$c204 20 | normal =$c206 21 | mark =$c208 22 | chrout =$ffd2 23 | 24 | jsr clear 25 | lda #$ff 26 | sta ofset 27 | lda #16 28 | sta fire 29 | lda #32 30 | sta mark 31 | lda #18 32 | sta inverse 33 | lda #146 34 | sta normal 35 | start lda jstick 36 | eor ofset 37 | cmp #1 38 | beq up 39 | lda inverse 40 | jsr chrout 41 | ldx #0 ; begin pause loop 42 | pause inx 43 | cpx #254 44 | bne pause ; end pause loop 45 | jmp start 46 | up jsr back 47 | lda #145 48 | jmp print 49 | down jsr back 50 | lda #17 51 | jmp print 52 | left jsr back 53 | lda #157 54 | jmp print 55 | print lsr chrout 56 | lda mark 57 | jsr chrout 58 | jmp start 59 | back lda #157 ; subroutine 60 | jsr chrout 61 | rts 62 | end rts 63 | -------------------------------------------------------------------------------- /Asm4Kids/39spritezero.asm: -------------------------------------------------------------------------------- 1 | ;**************************************** 2 | ;* * 3 | ;* Sprite zero * 4 | ;* * 5 | ;* Moves a big, blocky sprite across * 6 | ;* the screen. * 7 | ;* * 8 | ;**************************************** 9 | 10 | ; 10 SYS (49152) 11 | 12 | *=$0801 13 | 14 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 15 | 16 | *=$c000 17 | sprite0 =$7f8 ; 2040 18 | enable =$d015 ; 53269 19 | color0 =$d027 ; 53287 20 | sp0x =$d000 ; 53248 21 | sp0y =$d001 ; 53249 22 | msbx =$d010 ; 53264 23 | shouse =$0340 ; 832 24 | 25 | jsr $e544 26 | lda #$0d ; block 13 27 | sta sprite0 ; store it in pointer for sprite 0 (poke 2040,13) 28 | lda #1 ; sprite 0 enable value 29 | sta enable ; store it in the enable register (poke 53269,1) 30 | lda #2 ; color red 31 | sta color0 ; color register for sprite 0 (poke 53287,2) 32 | 33 | ldx #0 34 | lda #0 35 | cleanup sta shouse,x ; store zeroes in sprite area 36 | inx 37 | cpx #63 38 | bne cleanup 39 | ldx #0 40 | lda #$ff 41 | build sta shouse,x ; fill up sprite area with $ff or 255 42 | inx ; to make solid block 43 | cpx #63 44 | bne build 45 | lda #0 46 | sta msbx ; store 0 in msbx to locate sprite in horizontal 47 | ; locations 0 to 255 only (poke 53264,0) 48 | ldx #0 49 | lda #70 ; vertical location 50 | move stx sp0x ; increment horizontal location by x (poke 53248,x) 51 | sta sp0y ; y register stays constant location of a register (poke 53249,70) 52 | ldy #0 ; delay loop 53 | pause iny 54 | cpy #255 55 | bne pause 56 | inx 57 | cpx #254 58 | bne move 59 | rts 60 | 61 | -------------------------------------------------------------------------------- /Asm4Kids/3printname.asm: -------------------------------------------------------------------------------- 1 | ; prints 'jacob' on the screen 2 | ; 10 SYS (49152) 3 | 4 | *=$0801 5 | 6 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 7 | 8 | 9 | *=$c000 10 | jsr $e544 11 | lda #74 ; j 12 | jsr $e716 13 | lda #65 ; a 14 | jsr $e716 15 | lda #67 ; c 16 | jsr $e716 17 | lda #79 ; o 18 | jsr $e716 19 | lda #66 ; b 20 | jsr $e716 21 | rts 22 | -------------------------------------------------------------------------------- /Asm4Kids/40planetdestroyer.asm: -------------------------------------------------------------------------------- 1 | ;**************************************** 2 | ;* * 3 | ;* Planet destroyer * 4 | ;* * 5 | ;* * 6 | ;**************************************** 7 | 8 | ; 10 SYS (49152) 9 | 10 | *=$0801 11 | 12 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 13 | 14 | *=$c000 15 | sprite0 =$7f8 ; 2040 16 | enable =$d015 ; 53269 17 | color0 =$d027 ; 53287 18 | sp0x =$d000 ; 53248 19 | sp0y =$d001 ; 53249 20 | msbx =$d010 ; 53264 21 | shouse =$0340 ; 832 22 | 23 | jsr $e544 24 | lda #0 ; color for black 25 | sta $d020 ; border black (poke 53280,0) 26 | sta $d021 ; background black (poke 53281,0) 27 | lda #$0d 28 | sta sprite0 29 | lda #1 30 | sta enable 31 | lda #7 ; yellow 32 | sta color0 33 | ldx #0 34 | lda #$00 35 | cleanup sta shouse,x 36 | inx 37 | cpx #64 38 | bne cleanup 39 | ldx #0 40 | build lda data,x ; read byte values one at a time 41 | sta shouse,x ; store in spritehouse 42 | inx 43 | cpx #63 44 | bne build 45 | lda #0 46 | sta msbx 47 | ldx #0 48 | lda #70 49 | move stx sp0x 50 | sta sp0y 51 | ldy #0 52 | pause iny 53 | cpy #255 54 | bne pause 55 | inx 56 | cpx #254 57 | bne move 58 | jmp move 59 | rts 60 | 61 | data byte 0,0,0,0,0,0,0,0,0 62 | byte 0,0,0,0,0,0,128,0,0 63 | byte 224,0,0,252,0,0 64 | byte 255,128,0 65 | byte 255,240,28 66 | byte 31,255,63 67 | byte 63,255,63 68 | byte 63,255,63 69 | byte 31,255,240 70 | byte 255,240,0 71 | byte 255,128,0 72 | byte 252,0,0 73 | byte 224,0,0 74 | byte 128,0,0 75 | byte 0,0,0,0,0,0 76 | -------------------------------------------------------------------------------- /Asm4Kids/41spriteassembler.bas: -------------------------------------------------------------------------------- 1 | 10 print chr$(147) : r = 1 2 | 20 print "starting address as block:" 3 | 30 print "block 11: 704 - 767" 4 | 40 print "block 13: 832 - 895" 5 | 50 print "block 14: 896 - 959" 6 | 60 print "block 15: 960 - 1023" 7 | 70 for x = 1 to 39 8 | 80 print chr$(18);chr$(32); : next : print 9 | 90 input "block number";bl 10 | 100 if bl <> 11 and bl <> 13 and bl <> 14 and bl <> 15 then 90 11 | 110 sa = bl * 64 12 | 120 for x = sa to sa + 62 step 3 13 | 130 print "row";r 14 | 140 input a,b,c 15 | 150 if a <> 255 or b > 255 or c > 255 then 130 16 | 160 poke x,a : poke x + 1,b : poke x + 2,c 17 | 170 r = r + 1 : next 18 | 200 rem **************** 19 | 210 rem write to disk 20 | 220 rem **************** 21 | 230 lb = sa - int(sa/256) * 256 22 | 240 hb = int(sa/256) 23 | 250 input "enter sprite name";sn$ 24 | 260 sn$ = "0:" + sn$ + str$(bl) + ",p,w" 25 | 270 open2,8,2,sn$ 26 | 280 print#2, chr$(lb) + chr$(hb) 27 | 290 for v = sa to sa + 62 : sc = peek(v) 28 | 300 print#2, chr$(sc) 29 | 310 next v 30 | 320 close2 -------------------------------------------------------------------------------- /Asm4Kids/42spritetester.asm: -------------------------------------------------------------------------------- 1 | ;**************************************** 2 | ;* * 3 | ;* Sprite tester * 4 | ;* * 5 | ;* * 6 | ;**************************************** 7 | 8 | ; 10 SYS (49152) 9 | 10 | *=$0801 11 | 12 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 13 | 14 | *=$c000 15 | sprite0 =$7f8 ; 2040 16 | enable =$d015 ; 53269 17 | color0 =$d027 ; 53287 18 | sp0x =$d000 ; 53248 19 | sp0y =$d001 ; 53249 20 | msbx =$d010 ; 53264 21 | shouse =$0340 ; 832 22 | 23 | jsr $e544 24 | lda #0 25 | sta $d020 ; 53280 26 | sta $d021 ; 53281 27 | lda #$0d 28 | sta sprite0 29 | lda #1 30 | sta enable 31 | lda #7 32 | sta color0 33 | ldx #0 34 | lda #$00 35 | sta msbx 36 | lda #70 37 | move stx sp0x 38 | sta sp0y 39 | ldy #0 40 | pause iny 41 | cpy #255 42 | bne pause 43 | inx 44 | cpx #254 45 | bne move 46 | ldx #0 47 | lda #1 48 | sta msbx ; set the high byte of x position 49 | lda #70 ; keep y at 70 50 | move2 stx sp0x ; x position is now 255 + x 51 | sta sp0y 52 | ldy #0 53 | pause2 iny 54 | cpy #255 55 | bne pause2 56 | inx 57 | cpx #90 58 | bne move2 59 | rts 60 | -------------------------------------------------------------------------------- /Asm4Kids/43assemblysounds.asm: -------------------------------------------------------------------------------- 1 | ;**************************************** 2 | ;* * 3 | ;* Assembly sounds * 4 | ;* * 5 | ;* * 6 | ;**************************************** 7 | 8 | ; 10 SYS (49152) 9 | 10 | *=$0801 11 | 12 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 13 | 14 | *=$c000 15 | sigvol =$d418 ; 54296 16 | atdcy1 =$d405 ; 54277 17 | surel1 =$d406 ; 54278 18 | vcreg1 =$d404 ; 54276 19 | frelo1 =$d400 ; 54272 20 | frehi1 =$d401 ; 54273 21 | 22 | lda #15 23 | sta sigvol ; set volume to 15 24 | lda #128 25 | sta atdcy1 ; set attack/decay to 128 26 | sta surel1 ; set sustain/release to 128 27 | lda #195 28 | sta frelo1 ; store 195 in the low frequency 29 | lda #16 30 | sta frehi1 ; store 16 in the high frequency 31 | lda #17 32 | sta vcreg1 33 | ldy #0 34 | ldx #0 35 | set ldx #0 36 | play inx 37 | cpx #255 ; double delay loop to play sound 38 | bne play 39 | iny 40 | cpy #100 41 | bne set 42 | lda #0 ; null registers with 0 43 | sta vcreg1 44 | sta atdcy1 45 | sta surel1 46 | sta frelo1 47 | sta frehi1 48 | rts 49 | -------------------------------------------------------------------------------- /Asm4Kids/44noisysprite.asm: -------------------------------------------------------------------------------- 1 | ;**************************************** 2 | ;* * 3 | ;* Noisy space sprite * 4 | ;* * 5 | ;* * 6 | ;**************************************** 7 | 8 | ; 10 SYS (49152) 9 | 10 | *=$0801 11 | 12 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 13 | 14 | *=$c000 15 | sprite0 =$7f8 ; 2040 16 | enable =$d015 ; 53269 17 | color0 =$d027 ; 53287 18 | sp0x =$d000 ; 53248 19 | sp0y =$d001 ; 53249 20 | msbx =$d010 ; 53264 21 | shouse =$0340 ; 832 22 | sigvol =$d418 ; 54296 23 | atdcy1 =$d405 ; 54277 24 | surel1 =$d406 ; 54278 25 | vcreg1 =$d404 ; 54276 26 | frelo1 =$d400 ; 54272 27 | frehi1 =$d401 ; 54273 28 | hi =$c300 ; 49920 29 | why =$c304 ; 49924 30 | ex =$c306 ; 49926 31 | clear =$e544 ; 58692 32 | 33 | jsr clear 34 | 35 | ; sprite code 36 | lda #0 ; color for black 37 | sta $d020 ; border black (poke 53280,0) 38 | sta $d021 ; background black (poke 53281,0) 39 | lda #$0d 40 | sta sprite0 41 | lda #1 42 | sta enable 43 | lda #2 ; red 44 | sta color0 45 | ldx #0 46 | lda #$00 47 | cleanup sta shouse,x 48 | inx 49 | cpx #64 50 | bne cleanup 51 | ldx #0 52 | build lda data,x ; read byte values one at a time 53 | sta shouse,x ; store in spritehouse 54 | inx 55 | cpx #63 56 | bne build 57 | lda #0 58 | sta msbx 59 | ldx #0 60 | lda #70 61 | sta why ; preserve y 62 | move stx sp0x 63 | lda why 64 | sta sp0y 65 | inc ex ; increment x through ex 66 | ldx ex 67 | 68 | ; sound code 69 | lda #10 70 | sta hi 71 | 72 | start lda #15 73 | sta sigvol ; set volume to 15 74 | lda #128 75 | sta atdcy1 ; set attack/decay to 128 76 | sta surel1 ; set sustain/release to 128 77 | lda hi 78 | sta frelo1 ; store 195 in the low frequency 79 | lda hi 80 | sta frehi1 ; store 16 in the high frequency 81 | lda #17 82 | sta vcreg1 83 | ldy #0 84 | ldx #0 85 | set ldx #0 86 | play inx 87 | cpx #20 88 | bne play 89 | iny 90 | cpy #20 91 | bne set 92 | lda #0 ; null registers with 0 93 | sta vcreg1 94 | sta atdcy1 95 | sta surel1 96 | sta frelo1 97 | sta frehi1 98 | inc hi 99 | lda hi 100 | cmp #40 101 | bne start 102 | ldx ex 103 | cpx #254 104 | bne move ; back to sprite 105 | 106 | rts 107 | 108 | data byte 0,0,0,0,0,0,0,0,0 109 | byte 0,0,0,0,0,0,128,0,0 110 | byte 224,0,0,252,0,0 111 | byte 255,128,0 112 | byte 255,240,28 113 | byte 31,255,63 114 | byte 63,255,63 115 | byte 63,255,63 116 | byte 31,255,240 117 | byte 255,240,0 118 | byte 255,128,0 119 | byte 252,0,0 120 | byte 224,0,0 121 | byte 128,0,0 122 | byte 0,0,0,0,0,0 123 | -------------------------------------------------------------------------------- /Asm4Kids/45joysticksprite.asm: -------------------------------------------------------------------------------- 1 | ;**************************************** 2 | ;* * 3 | ;* Noisy space sprite * 4 | ;* * 5 | ;* * 6 | ;**************************************** 7 | 8 | ; 10 SYS (49152) 9 | 10 | *=$0801 11 | 12 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 13 | 14 | *=$c000 15 | clear =$e544 16 | jstick =$dc01 17 | ofset =$c300 18 | fire =$c302 19 | ex =$c304 20 | why =$c306 21 | sprite0 =$7f8 22 | enable =$d015 23 | color0 =$d027 24 | sp0x =$d000 25 | sp0y =$d001 26 | msbx =$d010 27 | shouse =$0340 28 | 29 | jsr clear 30 | lda #$0d 31 | sta sprite0 32 | lda #1 33 | sta enable 34 | lda #2 35 | sta color0 36 | ldx #0 37 | lda #$00 38 | cleanup sta shouse,x 39 | inx 40 | cpx #64 41 | bne cleanup 42 | ldx #0 43 | build lda data,x 44 | sta shouse,x 45 | inx 46 | cpx #63 47 | bne build 48 | lda #0 49 | sta msbx 50 | lda #$ff 51 | sta ofset 52 | lda #16 53 | sta fire 54 | lda #40 55 | sta ex ; starting x position of sprite 56 | sta sp0x 57 | lda #70 58 | sta why ; starting y position of sprite 59 | sta sp0y 60 | 61 | ; read the joystick 62 | start lda jstick 63 | eor ofset 64 | cmp #1 65 | beq up 66 | cmp #2 67 | beq down 68 | cmp #4 69 | beq left 70 | cmp #8 71 | beq right 72 | cmp fire 73 | beq end 74 | ldx #0 75 | pause inx 76 | cpx #254 77 | bne pause 78 | jmp start 79 | up dec why 80 | ldy why 81 | cpy #0 ; check for adjustment 82 | beq down 83 | jmp move 84 | down inc why 85 | ldy why 86 | cpy #255 87 | beq up 88 | jmp move 89 | left dec ex 90 | ldx ex 91 | cpx #0 92 | beq right 93 | jmp move 94 | right inc ex 95 | ldx ex 96 | cpx #255 97 | beq left 98 | jmp move 99 | end rts 100 | 101 | ; movement of sprite 102 | move stx sp0x 103 | sty sp0y 104 | ldx #0 105 | mpause inx 106 | cpx #254 107 | bne mpause 108 | jmp start 109 | 110 | 111 | ; sprite data 112 | data byte 0,0,0,0,0,0,0,0,0 113 | byte 0,0,0,0,0,0,128,0,0 114 | byte 224,0,0,252,0,0 115 | byte 255,128,0 116 | byte 255,240,28 117 | byte 31,255,63 118 | byte 63,255,63 119 | byte 63,255,63 120 | byte 31,255,240 121 | byte 255,240,0 122 | byte 255,128,0 123 | byte 252,0,0 124 | byte 224,0,0 125 | byte 128,0,0 126 | byte 0,0,0,0,0,0 127 | -------------------------------------------------------------------------------- /Asm4Kids/4ssta.asm: -------------------------------------------------------------------------------- 1 | ; Loads a value into the accumulator in immediate adressing mode (lda) 2 | ; stores the value an an unused adress (sta), clears the accumulator 3 | ; from the absolute mode (lda) adress it first stored the value 4 | ; The program then prints the character for the ASCII code in the accumulator 5 | ; with jsr $e716 6 | ; 10 SYS (49152) 7 | 8 | *=$0801 9 | 10 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 11 | 12 | 13 | *=$c000 14 | jsr $e544 ; cls 15 | lda #$43 ; ASCII 'c' 16 | sta $c050 17 | lda #$0 ; Immediate mode 18 | lda $c050 ; Absolute mode 19 | jsr $e716 20 | rts 21 | -------------------------------------------------------------------------------- /Asm4Kids/5black.asm: -------------------------------------------------------------------------------- 1 | ; Loads 0 into the accumulator 2 | ; sta puts that value into the soft-switch address 3 | ; that controls background color ($d021) 4 | ; 10 SYS (49152) 5 | 6 | *=$0801 7 | 8 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 9 | 10 | 11 | *=$c000 12 | lda #$0 13 | sta $d021 14 | rts 15 | -------------------------------------------------------------------------------- /Asm4Kids/6on.asm: -------------------------------------------------------------------------------- 1 | ; Turn key repeat on 2 | ; 10 SYS (49152) 3 | 4 | *=$0801 5 | 6 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 7 | 8 | 9 | *=$c000 10 | lda #$80 11 | sta $28a ; 650 - repeat all keys if $80 12 | rts 13 | -------------------------------------------------------------------------------- /Asm4Kids/7off.asm: -------------------------------------------------------------------------------- 1 | ; Turn key repeat off 2 | ; 10 SYS (49200) 3 | 4 | *=$0801 5 | 6 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $32, $30, $30, $29, $00, $00, $00 7 | 8 | 9 | *=$c030 10 | lda #$0 11 | sta $28a ; 650 - repeat all keys if $80 12 | rts 13 | -------------------------------------------------------------------------------- /Asm4Kids/8putitonthescreen.asm: -------------------------------------------------------------------------------- 1 | ; Puts a black spade on the screen 2 | ; 10 SYS (49152) 3 | 4 | *=$0801 5 | 6 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 7 | 8 | 9 | *=$c000 10 | jsr $e544 ; jump to subroutine 58692 11 | lda #0 ; black 12 | sta 55296 ; 1st color address 13 | lda #88 ; spade character 14 | sta 1024 ; 1st char address 15 | rts 16 | -------------------------------------------------------------------------------- /Asm4Kids/9xyplot.asm: -------------------------------------------------------------------------------- 1 | ; loads x and y registers with row and column numbers and calls the 2 | ; plot subroutine to move the cursor before it outputs ascii 88 to the screen 3 | ; 10 SYS (49152) 4 | 5 | *=$0801 6 | 7 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 8 | 9 | 10 | *=$c000 11 | jsr $e544 12 | ldx #12 ; row number 13 | ldy #19 ; column number 14 | clc ; clear the c flag 15 | ; c flag must be cleared to set position 16 | ; otherwise plot reads position instead 17 | jsr $fff0 ; plot subroutine 18 | lda #88 ; ASCII for 'x' 19 | jsr $e716 ; output to screen 20 | rts 21 | -------------------------------------------------------------------------------- /C64128Asm/0hitest.asm: -------------------------------------------------------------------------------- 1 | ; 10 sys 49152 2 | 3 | *=$0801 4 | 5 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $34, $39, $31, $35, $32, $29, $00, $00, $00 6 | 7 | 8 | *=$c000 ; origin directive (49152) 9 | 10 | lda #72 ; load ascii 'h' into the accumulator 11 | jsr $ffd2 ; call chrout kernal subroutine 12 | lda #73 ; load ascii 'i' into the accumulator 13 | jsr $ffd2 ; call chrout kernal subroutine 14 | rts ; return to basic 15 | 16 | -------------------------------------------------------------------------------- /C64128Asm/10stacknumbers.asm: -------------------------------------------------------------------------------- 1 | ; putting two numbers on the stack 2 | ; and adds them 3 | ; 10 SYS (32768) 4 | 5 | *=$0801 6 | 7 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $33, $32, $37, $36, $38, $29, $00, $00, $00 8 | 9 | 10 | *=$8000 11 | lda #35 12 | pha ; push the contents of the accumulator on to the stack 13 | lda #49 14 | pha 15 | cld 16 | clc 17 | pla ; pull top value off the stack and into the accumulator 18 | sta $fd 19 | pla 20 | adc $fd 21 | sta $fe 22 | rts 23 | 24 | 25 | ; php = push p register onto the stack 26 | ; plp = pull from the stack into the p register 27 | ; php and plp ops are often used in programs to save and restore the p register 28 | ; so that the p register is not messed about as a result of a subroutine -------------------------------------------------------------------------------- /C64128Asm/1hitest.bas: -------------------------------------------------------------------------------- 1 | 10 rem hi test program - basic version 2 | 20 data 169,72,32,210,255,169,73,32,210,255,96 3 | 30 for l = 49152 to 49162 4 | 40 read x : poke l,x 5 | 50 next l 6 | 60 sys 49152 -------------------------------------------------------------------------------- /C64128Asm/2bindec.bas: -------------------------------------------------------------------------------- 1 | 10 rem binary to decimal conversion program 2 | 20 dim bit(8), bits$(8) 3 | 30 print chr$(147) 4 | 40 print : print " binary-decimal conversion" 5 | 50 print : print "enter an 8-bit binary number:" : print : input a$ 6 | 60 if len(a$) <> 8 then 50 7 | 70 for l = 8 to 1 step -1 8 | 80 bit$(l) = mid$(a$, l, 1) 9 | 90 if bit$(l) <> "0" and bit$(l) <> "1" then 50 10 | 100 next l 11 | 110 for l = 1 to 8 12 | 120 bit(l) = val(bit$(l)) 13 | 130 next l 14 | 140 ans = 0 15 | 150 m = 256 16 | 160 for l = 1 to 8 17 | 170 m = m / 2 : ans = ans + bit(l) * m 18 | 180 next l 19 | 190 print "decimal:";ans 20 | 200 goto 50 -------------------------------------------------------------------------------- /C64128Asm/3decbin.bas: -------------------------------------------------------------------------------- 1 | 10 rem decimal to binary conversion program 2 | 20 dim bt$(8) : print chr$(147) 3 | 30 print : print " decimal-binary conversion" 4 | 40 print : print "enter a positive integer (1 to 255):" 5 | 50 bn$ = "" : print : input a$ 6 | 60 if val(a$) < 1 or val(a$) > 255 then 40 7 | 70 nr = val(a$) 8 | 80 for l = 8 to 1 step -1 9 | 90 q = nr / 2 10 | 100 r = q - int(q) 11 | 110 if r = 0 then bt$(l) = "0" : goto 130 12 | 120 bt$(l) = "1" 13 | 130 nr = int(q) 14 | 140 next l 15 | 150 print "binary: "; 16 | 160 for l = 1 to 8 17 | 170 print bt$(l); 18 | 180 next l 19 | 190 print 20 | 200 goto 40 -------------------------------------------------------------------------------- /C64128Asm/4dechexdec.bas: -------------------------------------------------------------------------------- 1 | 10 rem decimal to hex and hex to decimal conversion program 2 | 20 dim hex$(8) 3 | 30 print chr$(147) 4 | 40 print : print "what type of conversion do you want?" 5 | 50 print : print " (a) decimal to hexadecimal" 6 | 60 print " (b) hexadecimal to decimal" 7 | 70 print : print "type 'a' or 'b'" : print : input a$ 8 | 80 if a$ = "b" then 270 9 | 90 if a$ <> "a" then 40 10 | 100 print chr$(147) : print : print "this program will translate to decimal" 11 | 110 print "numbers from 0 to 99999999" : print "into hexadecimal numbers" 12 | 120 print : print "type decimal number (or 'hex' for hex)" : input a$ 13 | 130 for l = 1 to 8 : hex$(l) = "" : next l 14 | 140 if a$ = "hex" then 270 15 | 150 for l = 1 to 8 : t$ = right$(a$, l) 16 | 155 if asc(t$) < 48 or asc(t$) > 57 then 120 17 | 156 next l 18 | 160 if len(a$) < 1 or len(a$) > 8 then 120 19 | 170 n = val(a$) 20 | 180 i = 8 21 | 190 tmp = n : n = int(n / 16) 22 | 200 tmp = tmp - n * 16 23 | 210 if tmp < 10 then hex$(i) = right$(str$(tmp), 1) : goto 230 24 | 220 hex$(i) = chr$(tmp - 10 + asc("a")) 25 | 230 if n <> 0 then i = i - 1 : goto 190 26 | 240 print "hex: "; 27 | 250 for l = 1 to 8 : print hex$(l); : next l : print 28 | 260 goto 120 29 | 270 print chr$(147) : print : print "this program will convert hexadecimal" 30 | 280 print "numbers from 0 to ffffffff" : print "into decimal numbers" 31 | 290 print : print "type hex number (or 'dcx' for decimal):" : input a$ 32 | 300 if a$ = "dcx" then 100 33 | 310 if len(a$) > 8 then 290 34 | 320 n = 0 35 | 330 for l = 1 to len(a$) 36 | 340 hex$(l) = mid$(a$, l, 1) 37 | 350 if hex$(l) < "9" then n = n * 16 + val(hex$(l)) : goto 390 38 | 360 if hex$(l) < "a" then 290 39 | 370 if hex$(l) > "f" then 290 40 | 380 n = n * 16 + asc(hex$(l)) - asc("a") + 10 41 | 390 next l 42 | 400 print "dec: ";n : print 43 | 410 goto 290 44 | 420 end -------------------------------------------------------------------------------- /C64128Asm/5store16bitinram.bas: -------------------------------------------------------------------------------- 1 | 5 rem store a 16-bit number in two 8-bit memory registers 2 | 10 al = 32768 : ah = 32769 : rem low and high addresses 3 | 20 print "type a positive integer" 4 | 30 print "ranging from 0 to 65,535" 5 | 40 input x 6 | 50 hibyte = int(x / 256) 7 | 60 lobyte = x - hibyte * 256 8 | 70 poke al, lobyte 9 | 80 poke ah, hibyte 10 | 90 rem retrieving the number 11 | 100 n = peek(ah) * 256 + peek(al) 12 | 110 print : print "number is: ";n 13 | 120 end -------------------------------------------------------------------------------- /C64128Asm/6addition.asm: -------------------------------------------------------------------------------- 1 | ; 10 SYS (32768) 2 | 3 | *=$0801 4 | 5 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $33, $32, $37, $36, $38, $29, $00, $00, $00 6 | 7 | 8 | *=$8000 9 | clc ; clear carry 10 | lda #2 ; load 2 into the accumulator 11 | adc #2 ; add with carry 2 12 | sta $02a7 ; store accumulator in memory address $02a7 (679) 13 | rts 14 | -------------------------------------------------------------------------------- /C64128Asm/7printit.asm: -------------------------------------------------------------------------------- 1 | ; 10 SYS (32768) 2 | 3 | *=$0801 4 | 5 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $33, $32, $37, $36, $38, $29, $00, $00, $00 6 | 7 | *=$8000 8 | chrout =$ffd2 9 | 10 | print 11 | lda #$58 ; ascii 'x' 12 | jsr chrout ; print the x 13 | rts 14 | -------------------------------------------------------------------------------- /C64128Asm/8addwithcheck.asm: -------------------------------------------------------------------------------- 1 | ; addition program with error-checking 2 | ; 10 SYS (32768) 3 | 4 | *=$0801 5 | 6 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $33, $32, $37, $36, $38, $29, $00, $00, $00 7 | 8 | *=$8000 9 | add8bit lda #0 10 | sta $02aa 11 | cld 12 | clc 13 | lda $02aa 14 | adc $02a8 15 | bcs error ; jump to error if carry bit is set 16 | sta $02a9 17 | rts 18 | error lda #1 19 | sta $02aa ; store error flag (1) in memory location $02aa 20 | rts 21 | -------------------------------------------------------------------------------- /C64128Asm/9txtbuf.asm: -------------------------------------------------------------------------------- 1 | ; routine for moving a block of text 2 | ; example of indexed addressing 3 | ; 10 sys 32768 4 | 5 | *=$0801 6 | 7 | BYTE $0E, $08, $0A, $00, $9E, $20, $28, $33, $32, $37, $36, $38, $29, $00, $00, $00 8 | 9 | *=$8000 10 | txtbuf =$02a7 11 | eol =$0d 12 | 13 | jmp datmov 14 | 15 | text 16 | byte $54,$41,$4b,$45,$20,$4d,$45,$20 17 | byte $54,$4f,$20,$59,$4f,$55,$52,$20 18 | byte $4c,$45,$41,$44,$45,$52,$21,$0d 19 | 20 | datmov ldx #0 21 | loop lda text,x 22 | sta txtbuf,x 23 | cmp #eol 24 | beq fini 25 | inx 26 | jmp loop 27 | fini rts 28 | -------------------------------------------------------------------------------- /C64AsmLang/10simplesubtraction.bas: -------------------------------------------------------------------------------- 1 | 10 rem simple subtraction 2 | 20 code = 49152 3 | 30 for loop = 0 to 7 4 | 40 read byte 5 | 50 poke code + loop,byte 6 | 60 next loop 7 | 70 rem 8 | 80 rem m/c data 9 | 90 data 56 : rem $38 - sec ; set carry flag 10 | 100 data 165,251 : rem $a5,$fb - lda $fb 11 | 110 data 229,252 : rem $e5,$fc - sbc $fc ; subtract, borrowing carry 12 | 120 data 133,253 : rem $85,$fd - sta $fd 13 | 130 data 96 : rem $60 - rts 14 | 140 rem 15 | 150 print chr$(147) 16 | 160 input "highest number";a 17 | 170 input "lowest number";b 18 | 180 poke 251,a : poke 252,b 19 | 190 sys code 20 | 200 print "answer is"; 21 | 210 print peek(253) -------------------------------------------------------------------------------- /C64AsmLang/11doublebytesubtraction.bas: -------------------------------------------------------------------------------- 1 | 10 rem double byte subtraction 2 | 20 code = 49152 3 | 30 for loop = 0 to 13 4 | 40 read byte 5 | 50 poke code + loop,byte 6 | 60 next loop 7 | 70 rem 8 | 80 rem m/c data 9 | 90 data 56 : rem $38 - sec 10 | 100 data 165,251 : rem $a5,$fb - lda $fb 11 | 110 data 229,253 : rem $e5,$fd - sbc $fd 12 | 120 data 133,251 : rem $85,$fb - sta $fb 13 | 130 data 165,252 : rem $a5,$fc - lda $fc 14 | 140 data 229,254 : rem $e5,$fe - sbc $fe 15 | 150 data 133,252 : rem $85,$fc - sta $fc 16 | 160 data 96 : rem $60 - rts 17 | 170 rem 18 | 180 print chr$(147) 19 | 190 input "highest number";a 20 | 200 input "lowest number";b 21 | 210 rem calculate high and low bytes 22 | 220 ah = int(a / 256) 23 | 230 al = a - (ah * 256) 24 | 240 bh = int(b / 256) 25 | 250 bl = b - (bh * 256) 26 | 260 poke 251,al : poke 252,ah 27 | 270 poke 253,bl : poke 254,bh 28 | 280 sys code 29 | 290 low = peek(251) : high = peek(252) 30 | 300 result = high * 256 + low 31 | 310 print "answer is "; 32 | 320 print result -------------------------------------------------------------------------------- /C64AsmLang/12negation.bas: -------------------------------------------------------------------------------- 1 | 10 rem two's complement converter 2 | 15 rem using sbc 3 | 20 code = 49152 4 | 30 for loop = 0 to 7 5 | 40 read byte 6 | 50 poke code + loop,byte 7 | 60 next loop 8 | 70 rem 9 | 80 rem m/c data 10 | 90 data 56 : rem $38 - sec ; set carry flag 11 | 100 data 169,0 : rem $a9,$00 - lda #0 ; load a with 0 12 | 110 data 229,251 : rem $e5,$fb - sbc $fb ; subtract contents of $fb from i 13 | 120 data 133,252 : rem $85,$fc - sta $fc ; save result in $fc 14 | 130 data 96 : rem $60 - rts 15 | 140 rem 16 | 150 input "number to be converted";a 17 | 160 if a > 255 then print "eror" : goto 160 18 | 170 poke 251,a 19 | 180 sys code 20 | 190 print "the two's complement value is: $"; 21 | 200 print peek(252) -------------------------------------------------------------------------------- /C64AsmLang/13simplebcdaddition.bas: -------------------------------------------------------------------------------- 1 | 10 rem simple bcd addition 2 | 20 code = 49152 3 | 30 for loop = 0 to 7 4 | 40 read byte 5 | 50 poke code + loop,byte 6 | 60 next loop 7 | 70 rem 8 | 80 rem m/c data 9 | 90 data 248 : rem $f8 - sed ; set decimal mode 10 | 100 data 24 : rem $18 - clc ; set carry flag 11 | 110 data 169,9 : rem $a9,$09 - lda #$09 ; get first value 12 | 120 data 105,5 : rem $69,$05 - adc #$05 ; subtract a number 13 | 130 data 133,251 : rem $85,$fb - sta $fb ; save result 14 | 140 data 216 : rem $d8 - cld ; clear decimal mode 15 | 150 data 96 : rem $60 - rts 16 | 160 rem 17 | 170 sys code 18 | 180 print peek(251) -------------------------------------------------------------------------------- /C64AsmLang/14absoluteaddressing.bas: -------------------------------------------------------------------------------- 1 | 10 rem absolute addressing 2 | 20 code = 49152 3 | 30 for loop = 0 to 8 4 | 40 read byte 5 | 50 poke code + loop,byte 6 | 60 next loop 7 | 70 rem 8 | 80 rem m/c data 9 | 90 data 169,1 : rem $a9,$01 - lda #$01 10 | 100 data 141,80,04 : rem $8d,$50,$04 - sta 1104 ; store a into screen memory 11 | 110 data 141,80,216 : rem $8d,$50,$d8 - sta 55376 ; store white code into colour memory 12 | 120 data 96 : rem $60 - rts 13 | 130 rem 14 | 140 print chr$(147) 15 | 150 print : print : print 16 | 160 sys code -------------------------------------------------------------------------------- /C64AsmLang/15absoluteindexedaddressing.bas: -------------------------------------------------------------------------------- 1 | 10 rem absolute indexed addressing 2 | 20 code = 49152 3 | 30 for loop = 0 to 21 4 | 40 read byte 5 | 50 poke code + loop,byte 6 | 60 next loop 7 | 70 rem 8 | 80 rem m/c data 9 | 90 data 162,32 : rem $a2,$20 - ldx #$20 10 | 100 data 189,0,4 : rem $bd,$00,$04 - lda 1024,x 11 | 110 data 157,8,6 : rem $9d,$08,$06 - sta 1544,x 12 | 120 data 202 : rem $ca - dex 13 | 130 data 208,247 : rem $d0,$f7 - bne -9 14 | 140 data 169,1 : rem $a9,$01 - lda #$01 15 | 150 data 162,32 : rem $a2,$20 - ldx #$20 16 | 160 data 157,8,218 : rem $9d,$08,$da - sta 55816 17 | 170 data 202 : rem $ca - dex 18 | 180 data 208,250 : rem $d0,$fa - bne -5 19 | 190 data 96 : rem $60 - rts 20 | 200 rem 21 | 210 print chr$(147) 22 | 220 print "absolute indexed addressing" 23 | 230 get a$ 24 | 240 if a$ = "" then goto 230 25 | 250 sys code -------------------------------------------------------------------------------- /C64AsmLang/16indirectjumping.bas: -------------------------------------------------------------------------------- 1 | 10 rem indirect jumping 2 | 20 code = 49152 3 | 30 for loop = 0 to 15 4 | 40 read byte 5 | 50 poke code + loop,byte 6 | 60 next loop 7 | 70 rem 8 | 80 rem m/c data 9 | 90 data 169,00 : rem $a9,$00 - lda #$00 ; load a with low byte of $c000 10 | 100 data 133,251 : rem $85,$fb - sta $fb ; store in $fb 11 | 110 data 169,192 : rem $a9,$c0 - lda #$c0 ; load a with high byte of $c000 12 | 120 data 133,252 : rem $85,$fc - sta $fc ; store in $fc 13 | 130 data 169,42 : rem $a9,$2a - lda #asc"*" ; load ascii value of star into a 14 | 140 data 32,210,255 : rem $20,$d2,$ff - jsr $ffd2 ; print star to the screen 15 | 150 data 108,251,0 : rem $6c,$fb,$00 - jmp ($fb) ; jump to $c000 16 | 160 rem 17 | 170 sys code -------------------------------------------------------------------------------- /C64AsmLang/17indirectaddressing.bas: -------------------------------------------------------------------------------- 1 | 10 rem indirect addressing 2 | 20 code = 49152 3 | 30 for loop = 0 to 19 4 | 40 read byte 5 | 50 poke code + loop,byte 6 | 60 next loop 7 | 70 rem 8 | 80 rem m/c data 9 | 90 data 160,39 : rem $a0,$27 - ldy #$27 ; y is set to text screen line length count 10 | 100 data 177,251 : rem $b1,$fb - lda ($fb),y ; byte stored at screentop + y is stored in a 11 | 110 data 145,253 : rem $91,$fd - sta ($fd),y ; stored in screen memory at location specified by screenbot + y 12 | 120 data 136 : rem $88 - dey ; decrement y register 13 | 130 data 208,249 : rem $d0,$f9 - bne -7 ; 14 | 140 data 162,39 : rem $a2,$27 - ldx #$27 ; 15 | 150 data 169,1 : rem $a9,$01 - lda #$01 ; 16 | 160 data 157,8,218 : rem $9d,$08,$da - sta 55816,x ; 17 | 170 data 202 : rem $ca - dex ; 18 | 180 data 208,250 : rem $d0,$fa - bne -6 ; 19 | 190 data 96 : rem $60 - rts ; 20 | 200 rem 21 | 210 poke 251,0 : poke 252,4 : rem screentop 22 | 220 poke 253,8 : poke 254,6 : rem screenbot 23 | 230 print chr$(147) 24 | 240 print "indirect indexed addressing" 25 | 250 get a$ 26 | 260 if a$ = "" then goto 250 27 | 270 sys code -------------------------------------------------------------------------------- /C64AsmLang/18incrementingregister.bas: -------------------------------------------------------------------------------- 1 | 10 rem incrementing a register 2 | 20 code = 49152 3 | 30 for loop = 0 to 16 4 | 40 read byte 5 | 50 poke code + loop,byte 6 | 60 next loop 7 | 70 rem 8 | 80 rem m/c data 9 | 90 data 169,65 : rem $a9,$41 - lda #asc"a" ; place ascii a in accumulator 10 | 100 data 170 : rem $aa - tax ; save it in x register 11 | 110 data 232 : rem $e8 - inx ; increment x to give code for 'b' 12 | 120 data 32,210,255 : rem $20,$d2,$ff - jsr $ffd2 ; print 'a' to screen 13 | 130 data 138 : rem $8a - txa ; transfer ascii code for 'b' to accumulator 14 | 140 data 232 : rem $e8 - inx ; increment x to give code for 'c' 15 | 150 data 32,210,255 : rem $20,$d2,$ff - jsr $ffd2 ; print 'b' to screen 16 | 160 data 138 : rem $8a - txa ; transfer ascii code for 'c' into accumulator 17 | 170 data 32,210,255 : rem $20,$d2,$ff - jsr $ffd2 ; print 'c' to screen 18 | 180 data 96 : rem $60 - rts ; back to basic 19 | 190 rem 20 | 200 sys code -------------------------------------------------------------------------------- /C64AsmLang/19tenexlamationmarks.bas: -------------------------------------------------------------------------------- 1 | 10 rem 10 ! marks 2 | 20 code = 49152 3 | 30 for loop = 0 to 12 4 | 40 read byte 5 | 50 poke code + loop,byte 6 | 60 next loop 7 | 70 rem 8 | 80 rem m/c data 9 | 90 data 162,0 : rem $a2,$00 - ldx #0 ; init x register 10 | 100 data 169,33 : rem $a9,$21 - lda #asc"!" ; place ascii code for ! in accumulator 11 | 110 data 32,210,255 : rem $20,$d2,$ff - jsr $ffd2 ; print to screen 12 | 120 data 232 : rem $e8 - inx ; increment x register 13 | 130 data 224,10 : rem $e0,$0a - cpx #10 ; compare x register with 10 14 | 140 data 208,248 : rem $d0,$f8 - bne -8 ; bne opcode followed by a single byte, known as displacement (relative addressing) 15 | 150 data 96 : rem $60 - rts ; back to basic 16 | 160 rem 17 | 170 sys code 18 | 172 rem 19 | 175 rem Calculate displacement: 20 | 180 rem loop 21 | 190 rem jsr $ffd2 3 bytes 22 | 200 rem inx 1 byte 23 | 210 rem cpx #10 2 bytes 24 | 220 rem bne loop 2 bytes 25 | 225 rem 26 | 230 rem 0 0 0 0 1 0 0 0 (8) 27 | 240 rem 1 1 1 1 0 1 1 1 28 | 250 rem + 1 29 | 260 rem ----------------------- 30 | 270 rem 1 1 1 1 1 0 0 0 (-8 = $f8) ; two's complement value -------------------------------------------------------------------------------- /C64AsmLang/1machinecodedemo.bas: -------------------------------------------------------------------------------- 1 | 10 rem machine code demo 2 | 20 rem print 'a' on the screen 3 | 30 code = 828 : rem place code in the tape buffer (828-1020)($033c-$03fc) 4 | 40 for loop = 0 to 5 5 | 50 read byte 6 | 60 poke code + loop,byte 7 | 70 next loop 8 | 90 rem machine code data - 6 bytes 9 | 100 data 169,65 : rem $a9, $41 - lda #asc"a" 10 | 110 data 32,210,255 : rem $20, $d2, $ff - jsr 65490 11 | 120 data 96 : rem $60 - rts 12 | 140 rem execute machine code 13 | 150 sys 828 -------------------------------------------------------------------------------- /C64AsmLang/20forwardbranching.bas: -------------------------------------------------------------------------------- 1 | 10 rem forward branching 2 | 20 code = 49152 3 | 30 for loop = 0 to 14 4 | 40 read byte 5 | 50 poke code + loop,byte 6 | 60 next loop 7 | 70 rem 8 | 80 rem m/c data 9 | 90 data 165,251 : rem $a5,$fb - lda $fb ; load byte at location $fb into accumulator 10 | 100 data 240,6 : rem $f0,$06 - beq zero ; branch to zero if a contains 0 11 | 110 data 169,78 : rem $a9,$4e - lda #asc"n" ; load n into accumulator 12 | 120 rem back 13 | 130 data 32,210,255 : rem $20,$d2,$ff - jsr $ffd2 ; print to screen 14 | 140 data 96 : rem $60 - rts 15 | 150 rem zero 16 | 160 data 169,89 : rem $a9,$59 - lda #asc"y" ; load y into accumulator 17 | 170 data 24 : rem $18 - clc ; clear carry 18 | 180 data 144,247 : rem $90,$f7 - bcc back ; forced branching: carry is clear, so jump to back 19 | 190 rem 20 | 200 sys code -------------------------------------------------------------------------------- /C64AsmLang/21downcount.bas: -------------------------------------------------------------------------------- 1 | 10 rem down count 2 | 20 code = 49152 3 | 30 for loop = 0 to 10 4 | 40 read byte 5 | 50 poke code + loop,byte 6 | 60 next loop 7 | 70 rem 8 | 80 rem m/c data 9 | 90 data 162,10 : rem $a2,$0a - ldx #10 ; load 10 into x register 10 | 100 data 169,33 : rem $a9,$21 - lda #asc"!" ; load ascii ! into accumulator 11 | 110 rem loop 12 | 120 data 32,210,255 : rem $20,$d2,$ff - jsr $ffd2 ; print to screen 13 | 130 data 202 : rem $ca - dex ; deincrement x register 14 | 140 data 208,250 : rem $d0,$fa - bne loop ; branch if non zero, i.e. if zero flag is set 15 | 150 data 96 : rem $60 - rts 16 | 160 rem 17 | 170 sys code -------------------------------------------------------------------------------- /C64AsmLang/22incrementingmemory.bas: -------------------------------------------------------------------------------- 1 | 10 rem incrementing memory 2 | 20 code = 49152 3 | 30 for loop = 0 to 6 4 | 40 read byte 5 | 50 poke code + loop,byte 6 | 60 next loop 7 | 70 rem 8 | 80 rem m/c data 9 | 90 data 230,251 : rem $e6,$fb - inc $fb ; low byte of counter at $fb incremented 10 | 100 data 208,2 : rem $d0,$02 - bne over ; if zero flag is set, branch (when low byte changes from $ff to $00) 11 | 110 data 230,252 : rem $e6,$fc - inc $fc ; increment high byte of counter 12 | 120 rem over 13 | 130 data 96 : rem $60 - rts 14 | 140 rem 15 | 150 poke 251,0 : poke 252,0 16 | 160 sys code 17 | 170 low = peek(251) 18 | 180 high = peek(252) 19 | 190 num = high * 256 + low 20 | 200 print num 21 | 210 goto 160 -------------------------------------------------------------------------------- /C64AsmLang/23decrementingmemory.bas: -------------------------------------------------------------------------------- 1 | 10 rem decrementing memory 2 | 20 code = 49152 3 | 30 for loop = 0 to 8 4 | 40 read byte 5 | 50 poke code + loop,byte 6 | 60 next loop 7 | 70 rem 8 | 80 rem m/c data 9 | 90 data 165,251 : rem $a5,$fb - lda $fb ; load low byte of counter into accumulator 10 | 100 data 208,2 : rem $d0,$02 - bne lsbdec ; check zero flag 11 | 110 data 198,252 : rem $c6,$fc - dec $fc ; if set, high byte need decrementing 12 | 120 rem lsbdec 13 | 130 data 198,252 : rem $c6,$fb - dec $fb ; decrement low byte of counter 14 | 140 data 96 : rem $60 - rts 15 | 150 rem 16 | 160 poke 251,0 : poke 252,0 17 | 170 sys code 18 | 180 low = peek(251) 19 | 190 high = peek(252) 20 | 200 num = high * 256 + low 21 | 210 print num 22 | 220 goto 170 -------------------------------------------------------------------------------- /C64AsmLang/24subroutinedemo.bas: -------------------------------------------------------------------------------- 1 | 10 rem subroutine demo 2 | 15 rem prints input + 1 value higher, i.e. 'a' prints as 'b' 3 | 20 code = 49152 4 | 30 for loop = 0 to 14 5 | 40 read byte 6 | 50 poke code + loop,byte 7 | 60 next loop 8 | 70 rem 9 | 80 rem m/c data 10 | 90 rem wait 11 | 100 data 32,228,255 : rem $20,$e4,$ff - jsr $ffe4 ; call getin subroutine 12 | 110 data 240,251 : rem $f0,$fb - beq wait ; if zero flag jump back to getin 13 | 120 data 133,251 : rem $85,$fb - sta $fb ; store key code in location $fb 14 | 130 data 230,251 : rem $e6,$fb - inc $fb ; increment $fb 15 | 140 data 165,251 : rem $a5,$fb - lda $fb ; load accumulator with value in $fb 16 | 150 data 32,210,255 : rem $20,$d2,$ff - jsr $ffd2 ; call chrout subroutine 17 | 160 data 96 : rem $60 - rts ; back to basic 18 | 170 rem 19 | 180 sys code -------------------------------------------------------------------------------- /C64AsmLang/25jumping.bas: -------------------------------------------------------------------------------- 1 | 10 rem jumping 2 | 20 code = 49152 3 | 30 for loop = 0 to 7 4 | 40 read byte 5 | 50 poke code + loop,byte 6 | 60 next loop 7 | 70 rem 8 | 80 rem m/c data 9 | 90 rem start 10 | 100 data 169,42 : rem $a9,$2a - lda #asc"*" ; load accumulator with ascii * 11 | 110 data 32,210,255 : rem $20,$d2,$ff - jsr $ffd2 ; call chrout subroutine 12 | 120 data 76,0,192 : rem $4c,$00,$c0 - jmp start ; jump back to start 13 | 130 rem 14 | 140 sys code -------------------------------------------------------------------------------- /C64AsmLang/26multiplybyfour.bas: -------------------------------------------------------------------------------- 1 | 10 rem multiply by four 2 | 20 code = 49152 3 | 30 for loop = 0 to 6 4 | 40 read byte 5 | 50 poke code + loop,byte 6 | 60 next loop 7 | 70 rem 8 | 80 rem m/c data 9 | 90 data 165,251 : rem $a5,$fb - lda $fb ; loads number into accumulator 10 | 100 data 10 : rem $0a - asl a ; shift accumulator left (arithmetic shift left) 11 | 110 data 10 : rem $0a - asl a ; shift accumulator left 12 | 120 data 133,251 : rem $85,$fb - sta $fb ; stores result in $fb 13 | 130 data 96 : rem $60 - rts 14 | 140 rem 15 | 150 print chr$(147) 16 | 160 input "number to be multiplied by four";num 17 | 170 poke 251,num 18 | 180 print "x 4 ="; 19 | 190 sys code 20 | 200 print peek(251) 21 | 210 rem 22 | 220 rem every time the accumulator gets shifted left, it gets multiplied by 2 -------------------------------------------------------------------------------- /C64AsmLang/27testbit0.bas: -------------------------------------------------------------------------------- 1 | 10 rem test bit 0 2 | 20 code = 49152 3 | 30 for loop = 0 to 10 4 | 40 read byte 5 | 50 poke code + loop,byte 6 | 60 next loop 7 | 70 rem 8 | 80 rem m/c data 9 | 90 data 165,251 : rem $a5,$fb - lda $fb ; load accumulator with the value in location 251 ($fb) 10 | 100 data 74 : rem $4a - lsr a ; shift bits left 11 | 110 data 169,48 : rem $a9,$30 - lda #asc"0" ; load ascii 0 into accumulator 12 | 120 data 105,0 : rem $69,$00 - adc #0 ; add 1 to a if carry flag is set 13 | 130 data 32,210,255 : rem $20,$d2,$ff - jsr $ffd2 ; print to screen 14 | 140 data 96 : rem $60 - rts 15 | 150 rem 16 | 160 input a 17 | 170 poke 251,a 18 | 180 sys code 19 | -------------------------------------------------------------------------------- /C64AsmLang/28binaryoutputofsr.bas: -------------------------------------------------------------------------------- 1 | 10 rem binary output of sr 2 | 15 rem prints the bits in the status register 3 | 20 code = 49152 4 | 30 for loop = 0 to 18 5 | 40 read byte 6 | 50 poke code + loop,byte 7 | 60 next loop 8 | 70 rem 9 | 80 rem m/c data 10 | 90 data 8 : rem $08 - php ; push the status register onto the stack 11 | 100 data 104 : rem $68 - pla ; pull from the stack into the accumulator 12 | 110 data 133,251 : rem $85,$fb - sta $fb ; store a in location 251 13 | 120 data 162,8 : rem $a2,$08 - ldx #$08 ; init x register (8) 14 | 130 rem nbit ; label marker for next bit 15 | 140 data 6,251 : rem $06,$fb - asl $fb ; arithmetic shift left location 251 (moves most significant bit into the carry flag) 16 | 150 data 169,48 : rem $a9,$30 - lda #asc"0" ; load ascii 0 into a 17 | 160 data 105,0 : rem $69,$00 - adc #$00 ; add carry 18 | 170 data 32,210,255 : rem $20,$d2,$ff - jsr $ffd2 ; print to screen 19 | 180 data 202 : rem $ca - dex ; deincrement x register (bit counter) 20 | 190 data 208,244 : rem $d0,$f4 - bne nbit ; branch to nbit if x has not reached zero 21 | 200 data 96 : rem $60 - rts 22 | 210 rem 23 | 220 print chr$(147) 24 | 230 print "nv-bdizc" 25 | 240 sys code -------------------------------------------------------------------------------- /C64AsmLang/29simplemultiplication.bas: -------------------------------------------------------------------------------- 1 | 10 rem simple multiplication 2 | 15 rem calculates 5 times 6 by simply adding 5 six times 3 | 20 code = 49152 4 | 30 for loop = 0 to 16 5 | 40 read byte 6 | 50 poke code + loop,byte 7 | 60 next loop 8 | 70 rem 9 | 80 rem m/c data 10 | 90 data 169,0 : rem $a9,$00 - lda #$00 ; init accumulator with 0 11 | 100 data 133,251 : rem $85,$fb - sta $fb ; store accumulator in location 251 12 | 110 data 162,6 : rem $a2,$06 - ldx #$06 ; init x register with 6 13 | 120 data 24 : rem $18 - clc ; clear carry flag 14 | 130 rem loop 15 | 140 data 165,251 : rem $a5,$fb - lda $fb ; load value of location 251 into accumulator 16 | 150 data 105,5 : rem $69,$05 - adc #$05 ; add with carry 5 to accumulator 17 | 160 data 133,251 : rem $85,$fb - sta $fb ; store accumulator in location 251 18 | 170 data 202 : rem $ca - dex ; deincrement x register 19 | 180 data 208,247 : rem $d0,$f7 - bne loop ; jump to loop if x is not zero 20 | 190 data 96 : rem $60 - rts 21 | 200 rem 22 | 210 sys code 23 | 220 print "result = " 24 | 230 print peek(251) -------------------------------------------------------------------------------- /C64AsmLang/2abovememsiz.bas: -------------------------------------------------------------------------------- 1 | 10 rem place m/c above memsiz 2 | 20 rem reset memsiz to 40447 3 | 30 rem which is $9dff 4 | 35 rem and 512 bytes (40959 - 512 = 40447) 5 | 40 poke 55,255 : rem low byte (40447 - (157 * 256)) 6 | 50 poke 56,157 : rem high byte (40447 / 256) 7 | 60 clr : rem clear stack 8 | 70 code = 40448 : rem set pc 9 | 80 for loop = 0 to 5 10 | 90 read byte 11 | 100 poke code + loop,byte 12 | 110 next loop 13 | 120 rem 14 | 130 rem m/c data 15 | 140 data 169,147 : rem $a9,$93 - lda #$93 16 | 150 data 32,210,255 : rem $20,$d2,$ff - jsr 65490 17 | 160 data 96 : rem $60 - rts 18 | 170 rem 19 | 180 sys code 20 | 190 rem 21 | 200 rem basic programs are stored in the user ram 22 | 210 rem which stretches from 2048 ($0800) to 40959 ($9fff) 23 | 220 rem a massive 38k 24 | 230 rem memsiz is a label associated with locations 55 ($0037) 25 | 240 rem and 56 ($0038) which holds the address of the highest 26 | 250 rem memory location that may be used by a basic program 27 | 260 rem by moving memsiz, we can create space above the basic user ram. -------------------------------------------------------------------------------- /C64AsmLang/30singlebytemult.bas: -------------------------------------------------------------------------------- 1 | 10 rem single byte mult giving 2 byte result 2 | 20 code = 49152 3 | 30 for loop = 0 to 19 4 | 40 read byte 5 | 50 poke code + loop,byte 6 | 60 next loop 7 | 70 rem 8 | 80 rem m/c data 9 | 90 data 162,8 : rem $a2,$08 - ldx #$08 10 | 100 data 169,0 : rem $a9,$00 - lda #$00 11 | 110 rem again 12 | 120 data 70,252 : rem $46,$fc - lsr $fc 13 | 130 data 144,3 : rem $90,$03 - bcc over 14 | 140 data 24 : rem $18 - clc 15 | 150 data 101,251 : rem $65,$fb - adc $fb 16 | 160 rem over 17 | 170 data 106 : rem $6a - ror a 18 | 180 data 102,253 : rem $66,$fd - ror $fd 19 | 190 data 202 : rem $ca - dex 20 | 200 data 208,243 : rem $d0,$f3 - bne again 21 | 210 data 133,254 : rem $85,$fe - sta $fe 22 | 220 data 96 : rem $60 - rts 23 | 230 rem 24 | 240 print chr$(147) 25 | 250 input "multiplicand";a 26 | 260 input "multiplier";b 27 | 270 poke 251,a : poke 252,b 28 | 280 sys code 29 | 290 high = peek(254) : low = peek(253) 30 | 300 result = high * 256 + low 31 | 310 print "result is"; 32 | 320 print result 33 | 330 rem 34 | 340 rem 010 x 011 (2x3) 35 | 350 rem 010 36 | 360 rem x 011 37 | 370 rem ------- 38 | 380 rem 010 39 | 390 rem 010 40 | 400 rem 000 41 | 410 rem ------- 42 | 420 rem 00110 (6) 43 | 430 rem 44 | 440 rem shift, but ignore if the multiplier digit is 0 45 | 450 rem otherwise add together -------------------------------------------------------------------------------- /C64AsmLang/31singlebytedivide.bas: -------------------------------------------------------------------------------- 1 | 10 rem single byte divide 2 | 20 code = 49152 3 | 30 for loop = 0 to 20 4 | 40 read byte 5 | 50 poke code + loop,byte 6 | 60 next loop 7 | 70 rem 8 | 80 rem m/c data 9 | 90 data 162,8 : rem $a2,$08 - ldx #$08 ; load 8 into x register, representing number of bits to be shifted 10 | 100 data 169,0 : rem $a9,$00 - lda #$00 ; clear accumulator 11 | 110 rem again ; set loop 12 | 120 data 6,251 : rem $06,$fb - asl $fb ; shift the dividend left 13 | 130 data 42 : rem $2a - rol a ; shift dividend left 14 | 140 data 197,252 : rem $c5,$fc - cmp $fc ; divisor and partial dividend compared 15 | 150 data 144,4 : rem $90,$04 - bcc over ; if result = divisor less than or equal to partial dividend.. 16 | 160 data 229,252 : rem $e5,$fc - sbc $fc ; divisor is subtracted from partial dividend 17 | 170 data 230,251 : rem $e6,$fb - inc $fb ; 1 added to quotient 18 | 180 rem over ; skipped if divisor is greater than partial dividend 19 | 190 data 202 : rem $ca - dex ; bit count decremented 20 | 200 data 208,242 : rem $d0,$f2 - bne again ; control returned to 'again' if not complete 21 | 210 data 133,253 : rem $85,$fd - sta $fd ; any remainder saved in $fd 22 | 220 data 96 : rem $60 - rts 23 | 230 rem 24 | 240 print 25 | 250 input "dividend";a 26 | 260 input "divisor";b 27 | 270 poke 251,a : poke 252,b 28 | 280 sys code 29 | 290 print "result = "; 30 | 300 print peek(251) 31 | 310 print "remainder = "; 32 | 320 print peek(253) 33 | 330 rem This program uses the shift instructions of lines 120 and 130 as 2 byte 34 | 340 rem shift register in which the accumulator acts as the higher byte. 35 | 350 rem The carry produced by rol a is insignificant, it is 0, and is eroded by 36 | 360 rem the next asl $fb procedure. -------------------------------------------------------------------------------- /C64AsmLang/32conditionalassembly.bas: -------------------------------------------------------------------------------- 1 | 10 rem conditional assembly 2 | 20 code = 49152 3 | 30 print chr$(147) 4 | 40 print spc(8) 5 | 50 print "conditional assembly" 6 | 60 print "press 1 to assemble mbadd" 7 | 70 print " 2 to assemble mbsub" 8 | 80 get a$ 9 | 90 a = val(a$) 10 | 100 if a = 1 then goto 200 11 | 110 if a = 2 then goto 300 12 | 120 goto 80 13 | 130 rem 14 | 190 rem assemble mbadd 15 | 200 restore 16 | 210 for loop = 0 to 18 17 | 220 read byte 18 | 230 poke code + loop,byte 19 | 240 next loop 20 | 250 end 21 | 260 rem 22 | 290 rem assemble mbsub 23 | 300 restore 24 | 310 read byte 25 | 320 if byte <> 96 then goto 310 26 | 330 goto 210 27 | 340 rem 28 | 350 rem mbadd data 29 | 360 data 164,251 : rem $a4,$fb - ldy $fb ; 30 | 370 data 162,0 : rem $a2,$00 - ldx #$00 ; 31 | 380 data 24 : rem $18 - clc ; 32 | 390 rem again 33 | 400 data 189,0,21 : rem $bd,$00,$15 - lda $1500,x ; 34 | 410 data 125,0,22 : rem $7d,$00,$16 - adc $1600,x ; 35 | 420 data 157,0,21 : rem $9d,$00,$15 - sta $1500,x ; 36 | 430 data 232 : rem $e8 - inx ; 37 | 440 data 136 : rem $88 - dey ; 38 | 450 data 208,243 : rem $d0,$f3 - bne again ; 39 | 460 data 96 : rem $60 - rts 40 | 470 rem 41 | 480 rem mbsub data 42 | 490 data 164,251 : rem $a4,$fb - lda $fb ; 43 | 500 data 162,0 : rem $a2,$00 - ldx #$00 ; 44 | 510 data 56 : rem $38 - sec ; 45 | 520 rem again 46 | 530 data 189,0,23 : rem $bd,$00,$17 - lda $1700,x ; 47 | 540 data 253,0,24 : rem $fd,$00,$18 - sbc $1800,x ; 48 | 550 data 157,0,23 : rem $9d,$00,$17 - sta $1700,x ; 49 | 560 data 232 : rem $e8 - inx ; 50 | 570 data 136 : rem $88 - dey ; 51 | 580 data 208,243 : rem $d0,$f3 - bne again ; 52 | 590 data 96 : rem $60 - rts -------------------------------------------------------------------------------- /C64AsmLang/33centrigradetofahrenheit.bas: -------------------------------------------------------------------------------- 1 | 10 rem centigrade to fahrenheit 2 | 15 rem uses lookup table 3 | 20 code = 49152 4 | 30 for loop = 0 to 7 5 | 40 read byte 6 | 50 poke code + loop,byte 7 | 60 next loop 8 | 70 rem 9 | 80 rem m/c data 10 | 90 data 166,251 : rem $a9,$fb - ldx $fb ; put input value into x register 11 | 100 data 189,0,193 : rem $bd,$00,$c1 - lda $c100,x ; get value by indexing into lookup table 12 | 110 data 133,252 : rem $85,$fc - sta $fc ; store value in location 252 13 | 120 data 96 : rem $60 - rts 14 | 130 rem 15 | 140 rem calculate table values 16 | 150 for c = 0 to 100 17 | 160 f = (1.8 * c) + 32 18 | 170 poke 49408 + c,f : rem $c100 19 | 180 next c 20 | 190 rem 21 | 200 print chr$(147) 22 | 210 input "centigrade value";c 23 | 220 poke 251,c 24 | 230 sys code 25 | 240 print "fahrenheit value"; 26 | 250 print peek(252) -------------------------------------------------------------------------------- /C64AsmLang/36aenterprise.bas: -------------------------------------------------------------------------------- 1 | 100 for n = 0 to 62 2 | 110 read byte 3 | 120 poke 832 + n,byte 4 | 130 next 5 | 200 data 0,0,0 6 | 201 data 127,254,0 7 | 202 data 127,254,0 8 | 203 data 63,254,0 9 | 204 data 63,254,0 10 | 205 data 1,128,0 11 | 206 data 1,128,120 12 | 207 data 1,131,254 13 | 208 data 1,131,254 14 | 209 data 1,129,128 15 | 210 data 1,131,128 16 | 211 data 1,131,128 17 | 212 data 1,131,128 18 | 213 data 1,143,0 19 | 214 data 1,143,0 20 | 215 data 1,140,0 21 | 216 data 15,254,0 22 | 217 data 3,255,0 23 | 218 data 3,255,0 24 | 219 data 1,254,0 25 | 220 data 0,0,0 26 | -------------------------------------------------------------------------------- /C64AsmLang/36benterprise.bas: -------------------------------------------------------------------------------- 1 | 5 rem enterprise as a sprite 2 | 10 code = 49152 3 | 20 for loop = 0 to 26 4 | 25 read byte 5 | 30 poke code + loop,byte 6 | 35 next loop 7 | 40 rem m/c data for sprite control 8 | 42 data 169,147 : rem $a9,$93 - lda #$93 ; load 147 into a 9 | 44 data 32,210,255 : rem $20,$d2,$ff - jsr print ; clear screen 10 | 46 data 169,13 : rem $a9,$0d - lda #13 11 | 48 data 141,250,7 : rem $8d,$fa,$07 - sta 2042 ; poke 2042,13 - data in block 13 12 | 50 data 169,4 : rem $a9,$04 - lda #4 13 | 52 data 141,21,208 : rem $8d,$15,$d0 - sta 53269 ; poke 53269,4 - enable sprite 2 14 | 54 data 141,29,208 : rem $8d,$1d,$d0 - sta 53277 ; poke 53277,4 - expand in x direction 15 | 56 data 169,130 : rem $a9,$82 - lda #130 16 | 58 data 141,4,208 : rem $8d,$04,$d0 - sta 53252 ; poke 53252,130 - x coordinate 17 | 60 data 141,5,208 : rem $8d,$05,$d0 - sta 53253 ; poke 53253 - y coordinate 18 | 70 data 96 : rem $60 - rts 19 | 80 rem 20 | 90 rem sprite data 21 | 100 for n = 0 to 62 22 | 110 read byte 23 | 120 poke 832 + n,byte 24 | 130 next 25 | 200 data 0,0,0 26 | 201 data 127,254,0 27 | 202 data 127,254,0 28 | 203 data 63,254,0 29 | 204 data 63,254,0 30 | 205 data 1,128,0 31 | 206 data 1,128,120 32 | 207 data 1,131,254 33 | 208 data 1,131,254 34 | 209 data 1,129,128 35 | 210 data 1,131,128 36 | 211 data 1,131,128 37 | 212 data 1,131,128 38 | 213 data 1,143,0 39 | 214 data 1,143,0 40 | 215 data 1,140,0 41 | 216 data 15,254,0 42 | 217 data 3,255,0 43 | 218 data 3,255,0 44 | 219 data 1,254,0 45 | 220 data 0,0,0 46 | 300 sys code -------------------------------------------------------------------------------- /C64AsmLang/36centerpriseflies.bas: -------------------------------------------------------------------------------- 1 | 5 rem the enterprise flies 2 | 8 rem a keypress will cause the wessel to move forward 3 | 10 code = 49152 4 | 20 for loop = 0 to 41 5 | 25 read byte 6 | 30 poke code + loop,byte 7 | 35 next loop 8 | 40 rem m/c data for final sprite 9 | 42 data 169,147 : rem $a9,$93 - lda #$93 10 | 44 data 32,210,255 : rem $20,$d2,$ff - jsr $ffd2 11 | 46 data 169,13 : rem $a9,$0d - lda #13 12 | 48 data 141,250,7 : rem $8d,$fa,$07 - sta 2042 13 | 50 data 169,4 : rem $a9,$04 - lda #4 14 | 52 data 141,21,208 : rem $8d,$15,$d0 - sta 53269 15 | 54 data 141,29,208 : rem $8d,$1d,$d0 - sta 53277 16 | 56 data 169,100 : rem $a9,$64 - lda #100 17 | 58 data 141,5,208 : rem $8d,$05,$d0 - sta 53253 18 | 60 data 162,0 : rem $a2,$00 - ldx #00 19 | 62 rem again 20 | 64 data 138 : rem $8a - txa 21 | 66 data 141,4,208 : rem $8d,$04,$d0 - sta 53252 22 | 68 data 134,251 : rem $86,$fb - stx $fb 23 | 70 rem wait 24 | 72 data 32,228,255 : rem $20,$e4,$ff - jsr $ffe4 25 | 74 data 240,251 : rem $f0,$fb - beq wait 26 | 76 data 166,251 : rem $a6,$fb - ldx $fb 27 | 78 data 232 : rem $e8 - inx 28 | 80 data 208,240 : rem $d0,$f0 - bne again 29 | 82 data 96 : rem $60 - rts 30 | 86 rem 31 | 90 rem sprite data 32 | 100 for n = 0 to 62 33 | 110 read byte 34 | 120 poke 832 + n,byte 35 | 130 next 36 | 200 data 0,0,0 37 | 201 data 127,254,0 38 | 202 data 127,254,0 39 | 203 data 63,254,0 40 | 204 data 63,254,0 41 | 205 data 1,128,0 42 | 206 data 1,128,120 43 | 207 data 1,131,254 44 | 208 data 1,131,254 45 | 209 data 1,129,128 46 | 210 data 1,131,128 47 | 211 data 1,131,128 48 | 212 data 1,131,128 49 | 213 data 1,143,0 50 | 214 data 1,143,0 51 | 215 data 1,140,0 52 | 216 data 15,254,0 53 | 217 data 3,255,0 54 | 218 data 3,255,0 55 | 219 data 1,254,0 56 | 220 data 0,0,0 57 | 225 rem 58 | 230 sys code -------------------------------------------------------------------------------- /C64AsmLang/37usrdemo.bas: -------------------------------------------------------------------------------- 1 | 10 rem usr demo 2 | 20 rem set up dummy machine code 3 | 25 poke 820,230 4 | 26 poke 821,98 : rem inc $62 5 | 30 poke 822,96 : rem rts 6 | 40 print chr$(147) 7 | 50 poke 785,52 : rem set up usradd to 8 | 60 poke 786,3 : rem point to 820 9 | 70 a = 0 : b = 837 10 | 80 print "pre usr a = ";a 11 | 90 a = usr(b) 12 | 100 print "post usr a = ";a 13 | 105 rem 14 | 108 rem usr is a basic statement that is used to call sections of machine code 15 | 109 rem unlike a sys call, usr allows arguments to be passed. 16 | 110 rem Before executing usr the address of a machine code subroutine must be 17 | 112 rem seeded into usradd, which is located at the two bytes starting at 785 ($0311) 18 | 114 rem 19 | 115 rem The high byte of the fac#1 mantissa was incremented at location 98 20 | 118 rem 21 | 120 rem Four bytes of fac#1 mantissa: 22 | 130 rem $d2 $40 $00 $00 23 | 140 rem 1101 0010 0100 0000 0000 0000 0000 0000 24 | 150 rem 25 | 160 rem 1101001001.0000000000000000 26 | 170 rem 27 | 180 rem ignoring non-significant zeros and sorting by binary into bytes: 28 | 190 rem 0000 0011 0100 1001 29 | 200 rem $03 049 30 | 210 rem 31 | 220 rem $0349 = 841 -------------------------------------------------------------------------------- /C64AsmLang/38savefac1.bas: -------------------------------------------------------------------------------- 1 | 10 rem save fac#1 2 | 20 code = 49152 3 | 30 for loop = 0 to 10 4 | 40 read byte 5 | 50 poke loop + code,byte 6 | 60 next loop 7 | 70 rem 8 | 80 rem m/c data 9 | 90 data 162,6 : rem $a2,$06 - ldx #6 10 | 100 rem again 11 | 110 data 181,96 : rem $b5,$60 - lda $60,x 12 | 120 data 157,52,3 : rem $9d,$34,$03 - sta $0334,x 13 | 130 data 202 : rem $ca - dex 14 | 140 data 208,248 : rem $d0,$f8 - bne again 15 | 150 data 96 : rem $60 - rts 16 | 160 rem 17 | 170 print chr$(147) 18 | 180 poke 785,0 : rem set usradd pointing 19 | 190 poke 786,192 : rem to 49152 ($c000) 20 | 200 b = 837 : rem value to pass to fac#1 21 | 210 a = usr(b) : rem pass and execute code 22 | 220 print "a = ";a 23 | 230 print "fac#1 = "; 24 | 240 for x = 1 to 6 25 | 250 print peek(820 + x);" "; 26 | 260 next x -------------------------------------------------------------------------------- /C64AsmLang/39integertofp.bas: -------------------------------------------------------------------------------- 1 | 10 rem integer to fp 2 | 20 code = 49152 3 | 30 for loop = 0 to 17 4 | 40 read byte 5 | 50 poke loop + code,byte 6 | 60 next loop 7 | 70 rem 8 | 80 rem m/c data 9 | 90 data 169,1 : rem $a9,$01 - lda #1 ; high byte into a 10 | 100 data 160,35 : rem $a0,$23 - ldy #$23 ; low byte into y 11 | 110 data 32,145,179 : rem $20,$91,$b3 - jsr $b391 ; call conversion routine 12 | 120 data 162,6 : rem $a2,$06 - ldx #6 ; init x to 6 13 | 125 rem again 14 | 130 data 181,96 : rem $b5,$60 - lda $60,x ; extract value from fac#1 15 | 140 data 157,52,3 : rem $9d,$34,$03 - sta $0334,x ; store the value 16 | 150 data 202 : rem $ca - dex ; deincrement x 17 | 160 data 208,248 : rem $d0,$f8 - bne again ; if x is not zero, extract another number 18 | 170 data 96 : rem $60 - rts 19 | 180 rem 20 | 190 print chr$(147) 21 | 200 sys code 22 | 210 print "fac#1 = "; 23 | 220 for x = 1 to 6 24 | 230 print peek(820 + x);" "; 25 | 240 next x 26 | 250 rem 27 | 260 rem The integer value to be converted is $0123, and the high 28 | 270 rem and low bytes are placed in the appropriate registers (lines 90 and 100) 29 | 280 rem before the conversion routine is called (line 110) 30 | 290 rem The floating point value is extracted from fac#1, so that it can be 31 | 300 rem peeked by the basic loop. 32 | 310 rem 33 | 320 rem 34 | 330 rem Result is: 35 | 340 rem fac#1 = 137 145 128 0 0 0 36 | 350 rem 37 | 360 rem Exponent = 9 (137 - 128) 38 | 370 rem Two bytes, in binary: 39 | 380 rem 1101 0001 1000 0000 40 | 390 rem 145 128 41 | 400 rem 42 | 410 rem Moving decimal point 9 places to the right gives: 43 | 420 rem 44 | 430 rem 0000 0001 0010 0011 45 | 440 rem $01 $23 46 | 450 rem 47 | 460 rem $0123 was the original value, so conversion works! -------------------------------------------------------------------------------- /C64AsmLang/3placeinfreeram.bas: -------------------------------------------------------------------------------- 1 | 10 rem place m/c in free ram 2 | 20 rem from 49152 ($c000) onwards ( to $cfff) - 4096 bytes 3 | 30 code = 49152 4 | 40 for loop = 0 to 5 5 | 50 read byte 6 | 60 poke code + loop,byte 7 | 70 next loop 8 | 80 rem 9 | 90 rem m/c data 10 | 100 data 169,14 : rem $a9,$0e - lda #$0e 11 | 110 data 32,210,255 : rem $20,$d2,$ff - jsr 65490 12 | 120 data 96 : rem $60 - rts 13 | 130 rem 14 | 140 sys code 15 | 150 rem 16 | 160 rem to get back to upper case, substitute 142 (8e) for 14 in line 100 -------------------------------------------------------------------------------- /C64AsmLang/40fptointeger.bas: -------------------------------------------------------------------------------- 1 | 10 rem fp to integer 2 | 20 code = 49152 3 | 30 for loop = 0 to 17 4 | 40 read byte 5 | 50 poke loop + code,byte 6 | 60 next loop 7 | 70 rem 8 | 80 rem m/c data 9 | 90 data 162,6 : rem $a2,$06 - ldx #6 10 | 100 rem again 11 | 110 data 189,52,3 : rem $bd,$34,$03 - lda 820,x 12 | 120 data 149,96 : rem $95,$60 - sta $60,x 13 | 130 data 202 : rem $ca - dex 14 | 140 data 208,248 : rem $d0,$f8 - bne again 15 | 150 data 32,170,177 : rem $20,$aa,$b1 - jsr $b1aa ; convert fac to integer in a and y 16 | 160 data 133,251 : rem $85,$fb - sta $fb 17 | 170 data 132,252 : rem $84,$fc - sty $fc 18 | 180 data 96 : rem $60 - rts 19 | 190 rem 20 | 200 for x = 0 to 5 21 | 210 read fac 22 | 220 poke 821 + x,fac 23 | 230 next x 24 | 235 rem 25 | 240 rem fac data 26 | 250 data 137,145,128,0,0,0 27 | 260 print chr$(147) 28 | 270 sys code 29 | 280 print "results returned are:" 30 | 290 print "accumulator = "; peek(251) 31 | 300 print "y register = "; peek(252) 32 | 310 rem 33 | 320 rem accumulator = 1 ($01) 34 | 330 rem y register = 35 ($23) -------------------------------------------------------------------------------- /C64AsmLang/41asciihextobinary.bas: -------------------------------------------------------------------------------- 1 | 10 rem ascii hex to binary 2 | 20 code = 49152 3 | 30 for loop = 0 to 48 4 | 40 read byte 5 | 50 poke code + loop,byte 6 | 60 next loop 7 | 70 rem 8 | 80 rem m/c data 9 | 90 data 32,34,192 : rem $20,$22,$c0 - jsr character 10 | 100 data 165,252 : rem $a6,$fc - lda $fc 11 | 110 data 32,24,192 : rem $20,$18,$c0 - jsr check 12 | 120 data 10 : rem $0a - asl a 13 | 130 data 10 : rem $0a - asl a 14 | 140 data 10 : rem $0a - asl a 15 | 150 data 10 : rem $0a - asl a 16 | 160 data 133,253 : rem $85,$fd - sta $fd 17 | 170 data 165,251 : rem $a5,$fb - lda $fb 18 | 180 data 32,24,192 : rem $20,$18,$c0 - jsr check 19 | 190 data 5,253 : rem $05,$fd - ora $fd 20 | 200 data 133,254 : rem $85,$fe - sta $fd 21 | 210 data 96 : rem $60 - rts 22 | 220 rem check subroutine : $c018 23 | 230 data 201,58 : rem $c9,$3a - cmp #$3a 24 | 240 data 176,3 : rem $b0,$03 - bcs atof 25 | 250 data 41,15 : rem $29,$0f - and #$0f 26 | 260 data 96 : rem $60 - rts 27 | 270 rem atof 28 | 280 data 233,55 : rem $e9,$37 - sbc #$37 29 | 290 data 96 : rem $60 - rts 30 | 300 rem character subroutine : $c022 31 | 310 rem first 32 | 320 data 32,228,255 : rem $20,$e4,$ff - jsr $ffe4 33 | 330 data 240,251 : rem $f0,$fb - beq first 34 | 340 data 133,252 : rem $85,$fc - sta $fc 35 | 350 rem second 36 | 360 data 32,228,255 : rem $20,$e4,$ff - jsr $ffe4 37 | 370 data 240,251 : rem $f0,$fb - beq second 38 | 380 data 133,251 : rem $85,$fb - sta $fb 39 | 390 data 96 : rem $60 - rts 40 | 400 rem 41 | 410 print chr$(147) 42 | 420 print "enter two hex digits"; 43 | 430 sys code 44 | 440 print : print "their binary value is: "; 45 | 450 print peek(254) -------------------------------------------------------------------------------- /C64AsmLang/42binarytoasciihex.bas: -------------------------------------------------------------------------------- 1 | 10 rem print accumulator as hex number 2 | 20 code = 49152 3 | 30 for loop = 0 to 21 4 | 40 read byte 5 | 50 poke code + loop,byte 6 | 60 next loop 7 | 70 rem 8 | 80 rem m/c data 9 | 90 data 72 : rem $48 - pha 10 | 100 data 74 : rem $4a - lsr a 11 | 110 data 74 : rem $4a - lsr a 12 | 120 data 74 : rem $4a - lsr a 13 | 130 data 74 : rem $4a - lsr a 14 | 140 data 32,9,192 : rem $20,$09,$c0 - jsr first 15 | 150 data 104 : rem $68 - pla 16 | 160 rem first subroutine : $c009 17 | 170 data 41,15 : rem $29,$0f - and #$0f 18 | 180 data 201,10 : rem $c9,$0a - cmp #$0a 19 | 190 data 144,2 : rem $90,$02 - bcc over 20 | 200 data 105,6 : rem $69,$06 - adc #$06 21 | 210 rem over 22 | 220 data 105,48 : rem $69,$30 - adc #$30 23 | 230 data 76,210,255 : rem $4c,$d2,$ff - jmp $ffd2 24 | 240 rem 25 | 250 rem demo program 26 | 260 rem lda $fb : jmp $c000 27 | 270 poke 828,165 : poke 829,251 28 | 280 poke 830,76 : poke 831,0 : poke 832,192 29 | 290 print chr$(147) 30 | 300 print "hit a key and its hex value in " 31 | 310 print "ascii will be displayed" 32 | 320 get a$ 33 | 330 if a$ = "" then goto 320 34 | 340 a = asc(a$) 35 | 350 poke 251,a 36 | 360 rem call link routine - lines 270 and 280 37 | 370 sys 828 38 | 380 rem call 'sys code' to use directly -------------------------------------------------------------------------------- /C64AsmLang/43outputasciistring.bas: -------------------------------------------------------------------------------- 1 | 10 rem ascii string output routine 2 | 20 code = 49152 3 | 30 for loop = 0 to 26 4 | 40 read byte 5 | 50 poke code + loop,byte 6 | 60 next loop 7 | 70 rem 8 | 80 rem m/c data 9 | 90 data 104 : rem $68 - pla 10 | 100 data 133,251 : rem $85,$fb - sta $fb 11 | 120 data 104 : rem $68 - pla 12 | 130 data 133,252 : rem $85,$fc - sta $fc 13 | 140 rem repeat 14 | 150 data 160,0 : rem $a0,$00 - ldy #$00 15 | 160 data 230,251 : rem $e6,$fb - inc $fb 16 | 170 data 208,2 : rem $d0,$02 - bne clear 17 | 180 data 230,252 : rem $e6,$fc - inc $fc 18 | 190 rem clear 19 | 200 data 177,251 : rem $b1,$fb - lda ($fb),y 20 | 210 data 48,6 : rem $30,$06 - bmi finish 21 | 220 data 32,210,255 : rem $20,$d2,$ff - jsr $ffd2 22 | 230 data 76,6,192 : rem $4c,$06,$c0 - jmp repeat 23 | 240 rem finish 24 | 250 data 108,251,0 : rem $6c,$fb,$00 - jmp ($fb) 25 | 260 rem 26 | 270 rem demo routine 27 | 280 rem located at $c200 28 | 290 demo = 49664 29 | 300 for loop = 0 to 22 30 | 310 read byte 31 | 320 poke demo + loop,byte 32 | 330 next loop 33 | 340 rem 34 | 350 data 169,147 : rem $a9,$93 - lda #$93 35 | 360 data 32,210,255 : rem $20,$d2,$ff - jsr $ffd2 36 | 370 data 32,0,192 : rem $20,$00,$c0 - jsr output 37 | 380 rem now store ascii codes for printing 38 | 390 data 67,79,77,77,79,68,79,82,69,32,54,52,13 39 | 400 rem c, o, m, m, o, d, o, r, e, , 6, 4, 40 | 410 data 234 : rem $ea - nop 41 | 420 data 96 : rem $60 - rts 42 | 430 sys demo -------------------------------------------------------------------------------- /C64AsmLang/4rvsonusingpokes.bas: -------------------------------------------------------------------------------- 1 | 10 rem rvs on using pokes 2 | 20 rem place m/c in tape buffer 3 | 30 poke 828,169 : rem $a9 - lda #'rvs on' 4 | 40 poke 829,18 : rem $12 5 | 50 poke 830,32 : rem $20 - jsr 61898 6 | 60 poke 831,202 : rem $ca 7 | 70 poke 832,241 : rem $f1 8 | 72 poke 833,169 : rem $a9 - lda #$41 9 | 74 poke 834,65 : rem $41 10 | 76 poke 835,32 : rem $32 - jsr 65490 11 | 78 poke 836,210 : rem $d2 12 | 80 poke 837,255 : rem $ff 13 | 82 poke 840,96 : rem $60 - rts 14 | 90 sys 828 -------------------------------------------------------------------------------- /C64AsmLang/5hexloader.bas: -------------------------------------------------------------------------------- 1 | 10 rem commodore 64 hex loader 2 | 20 print chr$(147) : rem clear screen 3 | 30 print spc(8) : rem home cursor 4 | 40 print "commodore 64 monitor" 5 | 50 print : print 6 | 60 input "assembly address";a$ 7 | 70 addr = val(a$) 8 | 80 rem main program loop 9 | 90 print addr; " :$"; 10 | 100 rem get high nibble of byte 11 | 110 gosub 2000 12 | 120 high = num 13 | 130 print z$; 14 | 140 rem get low nibble of byte 15 | 150 gosub 2000 16 | 160 low = num 17 | 170 print z$ 18 | 180 rem calculate byte and update 19 | 190 byte = high * 16 + low 20 | 200 poke addr,byte 21 | 210 addr = addr + 1 22 | 220 goto 80 23 | 300 rem 24 | 500 rem subroutine 25 | 2000 get z$ 26 | 2010 if z$ = "s" then print "stop" : end 27 | 2020 if z$ > "f" then goto 2000 28 | 2030 if z$ = "a" then num = 10 : return 29 | 2040 if z$ = "b" then num = 11 : return 30 | 2050 if z$ = "c" then num = 12 : return 31 | 2060 if z$ = "d" then num = 13 : return 32 | 2070 if z$ = "e" then num = 14 : return 33 | 2080 if z$ = "f" then num = 15 : return 34 | 2090 if z$ = " " goto 2000 35 | 2100 num = val(z$) : return 36 | -------------------------------------------------------------------------------- /C64AsmLang/6zeropageimmediate.bas: -------------------------------------------------------------------------------- 1 | 10 rem zero page and immediate addressing 2 | 20 code = 49152 : rem $c000 3 | 30 for loop = 0 to 9 4 | 40 read byte 5 | 50 poke code + loop,byte 6 | 60 next loop 7 | 70 rem 8 | 80 rem m/c data 9 | 90 data 162,33 : rem $a2,$21 - ldx #asc"!" 10 | 100 data 164,251 : rem $86,$fb - stx $fb 11 | 110 data 165,251 : rem $a5,$fb - lda $fb 12 | 120 data 32,210,255 : rem $20,$d2,$ff - jsr $ffd2 13 | 130 data 96 : rem $60 - rts 14 | 140 rem 15 | 150 sys code -------------------------------------------------------------------------------- /C64AsmLang/7simpleadd.bas: -------------------------------------------------------------------------------- 1 | 10 rem simple add 2 | 20 code = 49152 : rem $c000 3 | 30 for loop = 0 to 7 4 | 40 read byte 5 | 50 poke code + loop,byte 6 | 60 next loop 7 | 70 rem 8 | 80 rem m/c data 9 | 90 data 24 : rem $18 - clc 10 | 100 data 169,7 : rem $a9,$07 - lda #$07 11 | 110 data 105,3 : rem $69,$03 - adc #$03 12 | 120 data 133,251 : rem $85,$fb - sta $fb 13 | 130 data 96 : rem $60 - rts 14 | 140 rem 15 | 150 sys code 16 | 160 print "answer is :"; 17 | 170 print peek(251) -------------------------------------------------------------------------------- /C64AsmLang/8singlebyteadd.bas: -------------------------------------------------------------------------------- 1 | 10 rem single byte add 2 | 20 code = 49152 3 | 30 for loop = 0 to 7 4 | 40 read byte 5 | 50 poke code + loop,byte 6 | 60 next loop 7 | 70 rem 8 | 80 rem m/c data 9 | 90 data 24 : rem $18 - clc 10 | 100 data 165,251 : rem $a5,$fb - lda $fb 11 | 110 data 101,252 : rem $65,$fc - adc $fc 12 | 120 data 133,253 : rem $85,$fd - sta $fd 13 | 130 data 96 : rem $60 - rts 14 | 140 rem 15 | 150 print chr$(147) 16 | 160 print "single byte add demo" 17 | 170 print : print 18 | 180 input "first number";a 19 | 190 input "second number";b 20 | 200 poke 251,a : poke 252,b 21 | 210 sys code 22 | 220 print "answer is:"; 23 | 230 print peek(253) -------------------------------------------------------------------------------- /C64AsmLang/9doublebyteadd.bas: -------------------------------------------------------------------------------- 1 | 10 rem double byte add 2 | 20 code = 49152 3 | 30 for loop = 0 to 13 4 | 40 read byte 5 | 50 poke code + loop,byte 6 | 60 next loop 7 | 70 rem 8 | 80 rem m/c data 9 | 90 data 24 : rem $18 - clc 10 | 100 data 165,251 : rem $a5,$fb - lda $fb 11 | 110 data 101,253 : rem $65,$fd - adc $fd 12 | 120 data 133,251 : rem $85,$fd - sta $fb 13 | 130 data 165,252 : rem $a5,$fc - lda $fc 14 | 140 data 101,254 : rem $65,$fe - adc $fe 15 | 150 data 133,252 : rem $85,$fc - sta $fc 16 | 160 data 96 : rem $60 - rts 17 | 170 rem 18 | 180 print chr$(147) 19 | 190 print "double byte add demo" 20 | 200 print : print 21 | 210 input "first number";a 22 | 220 rem calculate high and low byte 23 | 230 ah = int(a/256) 24 | 240 al = a - (ah * 256) 25 | 250 input "second number";b 26 | 260 rem calculate high and low byte 27 | 270 bh = int(b/256) 28 | 280 bl = b - (bh * 256) 29 | 290 poke 251,al : poke 252,ah 30 | 300 poke 253,bl : poke 254,bh 31 | 310 sys code 32 | 320 low = peek(251) : high = peek(252) 33 | 330 result = high * 256 + low 34 | 340 print "answer is:"; 35 | 350 print result -------------------------------------------------------------------------------- /C64AsmLang/enterprise.spt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | True 7 | False 8 | 1 9 | 0 10 | 6 11 | 7 12 | False 13 | False 14 | 15 | 0 16 | 8388096 17 | 8388096 18 | 4193792 19 | 4193792 20 | 98304 21 | 98424 22 | 99326 23 | 99326 24 | 98688 25 | 99200 26 | 99200 27 | 99200 28 | 102144 29 | 102144 30 | 101376 31 | 1048064 32 | 261888 33 | 261888 34 | 130560 35 | 0 36 | 37 | 38 | 39 | 40 | 0 41 | A 42 | A 43 | A 44 | A 45 | A 46 | A 47 | A 48 | A 49 | A 50 | A 51 | A 52 | A 53 | A 54 | A 55 | A 56 | A 57 | A 58 | A 59 | A 60 | A 61 | A 62 | A 63 | A 64 | A 65 | A 66 | A 67 | A 68 | A 69 | A 70 | A 71 | A 72 | A 73 | A 74 | A 75 | A 76 | A 77 | A 78 | A 79 | A 80 | A 81 | A 82 | A 83 | A 84 | A 85 | A 86 | A 87 | A 88 | A 89 | A 90 | A 91 | A 92 | A 93 | A 94 | A 95 | A 96 | A 97 | A 98 | A 99 | A 100 | A 101 | A 102 | A 103 | A 104 | A 105 | A 106 | A 107 | A 108 | A 109 | A 110 | A 111 | A 112 | A 113 | A 114 | A 115 | A 116 | A 117 | A 118 | A 119 | A 120 | A 121 | A 122 | A 123 | A 124 | A 125 | A 126 | A 127 | A 128 | A 129 | A 130 | A 131 | A 132 | A 133 | A 134 | A 135 | A 136 | A 137 | A 138 | A 139 | A 140 | A 141 | A 142 | A 143 | A 144 | A 145 | A 146 | A 147 | A 148 | A 149 | A 150 | A 151 | A 152 | A 153 | A 154 | A 155 | A 156 | A 157 | A 158 | A 159 | A 160 | A 161 | A 162 | A 163 | A 164 | A 165 | A 166 | A 167 | A 168 | A 169 | A 170 | A 171 | A 172 | A 173 | A 174 | A 175 | A 176 | A 177 | A 178 | A 179 | A 180 | A 181 | A 182 | A 183 | A 184 | A 185 | 186 | 187 | -------------------------------------------------------------------------------- /C64ColorGraphics/1beginner/1lighthouse.bas: -------------------------------------------------------------------------------- 1 | 1 goto 1000 2 | 10 rem:::::::::::zap! 3 | 11 a = 256 : b = 2049 : c = 1003 4 | 12 if peek(b + 2) + a * peek(b + 3) >= c then 15 5 | 13 b = peek(b) + a * peek(b + 1) : on abs(b <> 0) goto 12 : end 6 | 14 a = 256 : b = peek(251) + a * peek(252) 7 | 15 if peek(b + 1) = 0 then end 8 | 16 print chr$(147) peek(B + 2) + a * peek(b + 3) : print "goto 14" 9 | 17 poke 251,b - int(b/a) * a : poke 252,b/a 10 | 18 poke 631,19 : poke 632,13 : poke 633,13 : poke 198,3 : end 11 | 20 rem:::::::::::graphics 12 | 21 poke 53265,59 13 | 22 poke 53272,29 14 | 23 poke 56576,198 15 | 24 return 16 | 30 rem:::::::::::text 17 | 31 poke 53265,27 18 | 32 poke 53272,21 19 | 33 poke 56576,199 20 | 34 return 21 | 40 rem:::::::::::colors 22 | 41 for i = 17408 to 18407 23 | 42 poke i,c 24 | 43 next 25 | 44 return 26 | 50 rem:::::::::::paint background 27 | 51 for i = 24576 to 32575 28 | 52 poke i,0 29 | 53 next i 30 | 54 return 31 | 60 rem:::::::::::find a point 32 | 61 row = int(y/8) 33 | 62 col = int(x/8) 34 | 63 line = y and 7 35 | 64 bit = 7 - (x and 7) 36 | 65 byte = 24576 + row*320 + col*8 + line 37 | 66 cbyte = 17408 + row * 40 + col 38 | 67 return 39 | 70 rem:::::::::::plot a point 40 | 71 gosub 60 41 | 72 poke byte,peek(byte) or 2 ^ bit 42 | 73 poke cbyte,c 43 | 74 return 44 | 80 rem:::::::::::plot a line 45 | 81 dx = x2 - x1 : dy = y2 - y1 46 | 82 l = abs(dx) : if abs(dy) > l then l = abs(dy) 47 | 83 if l > 0 then xi = dx/l : yi = dy/l 48 | 84 x = x1 + .5 : y = y1 + .5 49 | 85 for i = 0 to l 50 | 86 gosub 70 : rem plot point 51 | 87 x = x + xi : y = y + yi 52 | 88 next i 53 | 89 return 54 | 90 rem:::::::::::paint a shape 55 | 91 pc = pc + abs(pc=0) : for x = x0 to x0 + w : fl$ = "f" : pr = 0 56 | 92 for yc = y0 to y0 + h : y = yc : gosub 60 57 | 93 on abs((peek(byte) and 2 ^ bit) <> 0) goto 97 : if pr=0 then 96 58 | 94 pr = 0 : if fl$ = "f" then y1 = yc : fl$ = "t" : goto 96 59 | 95 gosub 99 : fl$ = "f" 60 | 96 next yc : goto 98 61 | 97 pr = 1 : next yc : if fl$ = "t" then gosub 99 62 | 98 next x : return 63 | 99 for y = y1 to yc - 1 : on abs(rnd(1) < pc) gosub 70 : next y : return 64 | 100 rem:::::::::::save picture 65 | 101 input "enter filename"; file$ 66 | 102 input "enter 8 for disk, or 1 for casette"; de 67 | 103 sys 57812 file$ + ".pic", de 68 | 104 poke 174,64 : poke 175,127 : poke 193,0 : poke 194,96 69 | 105 sys 62954 70 | 106 sys 57812 file$ + ".col", de 71 | 107 poke 174,232 : poke 175,71 : poke 193,0 : poke 194,68 72 | 108 sys 62954 : end 73 | 1000 rem:::::::::::main 74 | 1100 gosub 20 : rem graphics 75 | 1110 c = 14 : gosub 40 : rem colors 76 | 1120 gosub 50 : rem background 77 | 1200 rem:::::::::::lighthouse 78 | 1210 poke 18090,0 : poke 18130,17 79 | 1220 poke 18170,17 : poke 18210,17 80 | 1300 rem:::::::::::water 81 | 1310 for y = 176 to 199 82 | 1320 for x = 0 to 319 83 | 1330 if rnd(1) < .3 then gosub 70 84 | 1340 next x : next y 85 | 1400 rem:::::::::::left land 86 | 1410 c = 94 : rem color = green on blue 87 | 1420 x1 = 0 : y1 = 160 88 | 1430 x2 = 16 : y2 = 168 : gosub 80 89 | 1440 x1 = 24 : y1 = 168 : gosub 80 90 | 1450 x2 = 40 : y2 = 175 : gosub 80 91 | 1460 x1 = 0 : y1 = 175 : gosub 80 92 | 1470 x2 = 0 : y2 = 160 : gosub 80 93 | 1500 rem:::::::::::right land 94 | 1510 x1 = 240 : y1 = 175 95 | 1520 x2 = 261 : y2 = 164 : gosub 80 96 | 1530 x1 = 279 : y1 = 164 : gosub 80 97 | 1540 x2 = 319 : y2 = 152 : gosub 80 98 | 1550 x1 = 319 : y1 = 159 : gosub 80 99 | 1560 x2 = 319 : y2 = 175 : gosub 80 100 | 1570 x1 = 240 : y1 = 175 : gosub 80 101 | 1600 rem:::::::::::left wave 102 | 1610 c = 14 : rem color = black on blue 103 | 1620 x1 = 48 : y1 = 175 104 | 1630 x2 = 87 : y2 = 169 : gosub 80 105 | 1640 x1 = 95 : y1 = 175 : gosub 80 106 | 1650 x2 = 48 : y2 = 175 : gosub 80 107 | 1700 rem:::::::::::right wave 108 | 1710 x1 = 144 : y1 = 175 109 | 1720 x2 = 183 : y2 = 169 : gosub 80 110 | 1730 x1 = 191 : y1 = 175 : gosub 80 111 | 1740 x2 = 144 : y2 = 175 : gosub 80 112 | 1800 rem:::::::::::paint left wave 113 | 1810 c = 14 : rem color black on blue 114 | 1820 x0 = 48 : y0 = 169 115 | 1830 w = 47 : h = 6 116 | 1840 pc = .3 : gosub 90 117 | 1900 rem:::::::::::paint right wave 118 | 1910 x0 = 144 : y0 = 169 119 | 1920 w = 47 : h = 6 120 | 1930 pc = .3 : gosub 90 121 | 2000 rem:::::::::::paint left land 122 | 2010 c = 94 : rem color green on blue 123 | 2020 x0 = 0 : y0 = 160 124 | 2030 w = 40 : h = 15 125 | 2040 pc = 1 : gosub 90 126 | 2100 rem:::::::::::paint right land 127 | 2110 x0 = 237 : y0 = 152 128 | 2120 w = 82 : h = 23 129 | 2130 pc = 1 : gosub 90 130 | 3000 rem:::::::::::shade lighthouse 131 | 3010 c = 241 132 | 3020 x1 = 16 : x2 = 16 : y1 = 136 : y2 = 167 : gosub 80 133 | 3030 x1 = 17 : x2 = 17 : gosub 80 134 | 3040 x1 = 18 : x2 = 18 : gosub 80 135 | 3050 poke 18090,11 136 | 4000 rem:::::::::::draw border 137 | 4010 c = 94 : rem color = green on blue 138 | 4020 x1 = 0 : y1 = 159 139 | 4030 x2 = 0 : y2 = 0 : gosub 80 140 | 4040 x1 = 319 : y1 = 0 : gosub 80 141 | 4050 x2 = 319 : y2 = 166 : gosub 80 142 | 5000 get a$ 143 | 5010 if a$ = " " then 6000 144 | 5020 goto 5000 145 | 6000 gosub 30 : rem return to text mode 146 | 6010 end -------------------------------------------------------------------------------- /C64ColorGraphics/1beginner/C64ColorGraphicsBeginner.cbmprj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 2 7 | c64colorgraphicsbeginner.prg 8 | 2049 9 | False 10 | False 11 | False 12 | False 13 | True 14 | 15 | Commodore 64 Color Graphics - a Beginners Guide 16 | Jacob Moen 17 | c64colorgraphicsbeginner.prg 18 | 19 | False 20 | C64 CARTRIDGE 21 | 22 | 40 23 | 1 24 | 0 25 | 0 26 | False 27 | False 28 | CHIP 29 | 0 30 | 31 | 32 | False 33 | False 34 | False 35 | 36 | 37 | 38 | 39 | 1lighthouse.bas 40 | 2ship.bas 41 | 3sun.bas 42 | 4toolkit.bas 43 | 5tookitoptimized.bas 44 | 45 | 0 46 | 0 47 | 48 | 49 | 1lighthouse.bas 50 | 51 | 1 52 | True 53 | 54 | 55 | 56 | False 57 | False 58 | 59 | 60 | 2ship.bas 61 | 62 | 1 63 | True 64 | 65 | 66 | 67 | False 68 | False 69 | 70 | 71 | 3sun.bas 72 | 73 | 1 74 | True 75 | 76 | 77 | 78 | False 79 | False 80 | 81 | 82 | 4toolkit.bas 83 | 84 | 1 85 | True 86 | 87 | 88 | 89 | False 90 | False 91 | 92 | 93 | 5tookitoptimized.bas 94 | 95 | 1 96 | True 97 | 98 | 99 | 100 | True 101 | True 102 | 103 | 104 | sun.spt 105 | 106 | 7 107 | True 108 | 109 | 110 | 111 | False 112 | False 113 | 114 | 115 | -------------------------------------------------------------------------------- /C64ColorGraphics/1beginner/boat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jacmoe/c64adventures/5822bec20522d3168bb985b3dbe6c2f025484a02/C64ColorGraphics/1beginner/boat.png -------------------------------------------------------------------------------- /C64ColorGraphics/1beginner/disk.d64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jacmoe/c64adventures/5822bec20522d3168bb985b3dbe6c2f025484a02/C64ColorGraphics/1beginner/disk.d64 -------------------------------------------------------------------------------- /C64ColorGraphics/1beginner/sun.spt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | True 7 | False 8 | 1 9 | 0 10 | 6 11 | 7 12 | False 13 | False 14 | 15 | 0 16 | 0 17 | 130944 18 | 524256 19 | 1048560 20 | 2097144 21 | 4194300 22 | 8388606 23 | 16777215 24 | 16777215 25 | 16777215 26 | 16777215 27 | 16777215 28 | 8388606 29 | 4194300 30 | 2097144 31 | 1048560 32 | 524256 33 | 130944 34 | 0 35 | 0 36 | 37 | 38 | 39 | 40 | 0 41 | A 42 | A 43 | A 44 | A 45 | A 46 | A 47 | A 48 | A 49 | A 50 | A 51 | A 52 | A 53 | A 54 | A 55 | A 56 | A 57 | A 58 | A 59 | A 60 | A 61 | A 62 | A 63 | A 64 | A 65 | A 66 | A 67 | A 68 | A 69 | A 70 | A 71 | A 72 | A 73 | A 74 | A 75 | A 76 | A 77 | A 78 | A 79 | A 80 | A 81 | A 82 | A 83 | A 84 | A 85 | A 86 | A 87 | A 88 | A 89 | A 90 | A 91 | A 92 | A 93 | A 94 | A 95 | A 96 | A 97 | A 98 | A 99 | A 100 | A 101 | A 102 | A 103 | A 104 | A 105 | A 106 | A 107 | A 108 | A 109 | A 110 | A 111 | A 112 | A 113 | A 114 | A 115 | A 116 | A 117 | A 118 | A 119 | A 120 | A 121 | A 122 | A 123 | A 124 | A 125 | A 126 | A 127 | A 128 | A 129 | A 130 | A 131 | A 132 | A 133 | A 134 | A 135 | A 136 | A 137 | A 138 | A 139 | A 140 | A 141 | A 142 | A 143 | A 144 | A 145 | A 146 | A 147 | A 148 | A 149 | A 150 | A 151 | A 152 | A 153 | A 154 | A 155 | A 156 | A 157 | A 158 | A 159 | A 160 | A 161 | A 162 | A 163 | A 164 | A 165 | A 166 | A 167 | A 168 | A 169 | A 170 | A 171 | A 172 | A 173 | A 174 | A 175 | A 176 | A 177 | A 178 | A 179 | A 180 | A 181 | A 182 | A 183 | A 184 | A 185 | 186 | 187 | -------------------------------------------------------------------------------- /C64ColorGraphics/2advanced/1helper.bas: -------------------------------------------------------------------------------- 1 | 2000 rem :::::: helper program 2 | 2010 print chr$(147) chr$(18) spc(15) "helper" 3 | 2020 a$ = "" : input "mem/data"; a$ : if a$ = "" then end 4 | 2030 i = 0 : j = 7 : gosub 4030 : rem get addr 5 | 2040 addr = t : if t < 49152 or t > 50504 then print "error. try again." : goto 2020 6 | 2050 if len(a$) = 28 then 3070 : rem poker 7 | 2060 if len(a$) > 4 then print "error. try again." : goto 2020 8 | 2070 ck = 0 9 | 2080 for i = 0 to 7 10 | 2090 print " "; 11 | 3000 p% = peek(addr + i) : ck = ck + p% 12 | 3010 ph% = p% / 16 : pl% = p% - ph% * 16 13 | 3020 if ph% > 9 then ph% = ph% + 7 14 | 3030 if pl% > 9 then pl% = pl% + 7 15 | 3040 print chr$(ph% + 48) chr$(pl% + 48) 16 | 3050 next i : print : print "sum for this row:" ck : print 17 | 3060 goto 2020 18 | 3070 ck = 0 19 | 3080 for j = 0 to 7 20 | 3090 gosub 4030 : ck = ck + t 21 | 4000 poke ad + j,t 22 | 4010 next j : print "sum for this row:" ck : print 23 | 4020 goto 2020 24 | 4030 t = 0 25 | 4040 i = i + 1 26 | 4050 if i > len(a$) and j = 7 then return 27 | 4060 a = asc(mid$(a$, i)) 28 | 4070 if a = 32 then return 29 | 4080 a = a + 48 * (a < 58) 30 | 4090 a = a + 55 * (a > 64) 31 | 5000 if a < 0 or a > 15 then print "error. try again." : goto 2020 32 | 5010 t = t * 16 + a 33 | 5020 goto 4040 -------------------------------------------------------------------------------- /C64ColorGraphics/2advanced/2checker.bas: -------------------------------------------------------------------------------- 1 | 1 i=49152 : r = 1 2 | 2 t = 0 3 | 3 for j = i to i + 127 4 | 4 t = t - peek(j) * (j < 50509) 5 | 5 next 6 | 6 reads : if s <> t then print "error in block"r : end 7 | 7 i = i + 128 : print "block"r"is ok" : r = r + 1 : if r > 11 then end 8 | 8 goto 2 9 | 10 data 15494, 13405, 13567, 12697, 13656, 11506, 13622 10 | 11 data 14447, 13025, 15192, 8817 -------------------------------------------------------------------------------- /C64ColorGraphics/2advanced/3.first.bas: -------------------------------------------------------------------------------- 1 | 0 if peek(49152) <> 128 then load "m/l",8,1 2 | 1 goto 1000 3 | 10 rem:::::::graphics 4 | 11 if mu then poke 53270,216 : rem mu = multi color graphics 5 | 12 poke 53265,59 : rem 59 for graphics, 27 for text 6 | 13 poke 53272,29 : rem pixel pattern storage, 29 means patterns not stored in same location as colors 7 | 14 poke 56576,198 : rem which bank used for pixel patterns and color - 198: use bank 1 8 | 15 return 9 | 20 rem:::::::text 10 | 21 poke 53270,200 11 | 22 poke 53265,27 12 | 23 poke 53272,21 13 | 24 poke 56576,199 14 | 25 return 15 | 30 rem:::::::clear hires/multi 16 | 31 sys 49164,c 17 | 32 xl = 0 : xh = 319 : yl = 0 : yh = 199 18 | 33 return 19 | 40 rem:::::::plot a point 20 | 41 sys 49502,x,y,c,mu 21 | 42 return 22 | 50 rem:::::::plot a line 23 | 51 sys 49502,x1,y1 to x2,y2,c,mu 24 | 52 return 25 | 170 rem:::::::zap! 26 | 171 gosub 20 : print "do you know what you are doing?" : end 27 | 172 a = 256 : b = 2049 : c = 1003 28 | 173 if peek(b + 2) + a * peek(b + 3) >= c then 176 29 | 174 b = peek(b) + a * peek(b + 1) : on abs(b <> 0) goto 173 : end 30 | 175 a = 256 : b = peek(251) + a * peek(252) 31 | 176 if peek(b + 1) = 0 then end 32 | 177 print chr$(147) peek(b + 2) + a * peek(b + 3) : print "goto 175" 33 | 178 poke 251, b - int(b/a) * a : poke 252,b/a 34 | 179 poke 631,19 : poke 632,13 : poke 633,13 : poke 198,3 : end 35 | 1000 rem:::::::::::::::::::::::: 36 | 1001 rem main routine 37 | 1002 rem:::::::::::::::::::::::: 38 | 2000 gosub 10 : c = 15 : gosub 30 39 | 2010 for k = 0 to 99 step 3 40 | 2020 x1 = 0 : y1 = 0 41 | 2030 y2 = k : x2 = 160 - k * 1.6 : c = 2 : gosub 50 42 | 2040 y1 = 199 43 | 3000 y2 = 199 - y2 : c = 5 : gosub 50 44 | 3010 x1 = 319 45 | 3020 x2 = 319 - x2 : c = 8 : gosub 50 46 | 3030 y1 = 0 47 | 3040 y2 = 199 - y2 : c = 6 : gosub 50 48 | 4000 next k 49 | 5000 x1 = 159 : y1 = 10 50 | 5010 x2 = 305 : y2 = 100 : c = 10 : gosub 50 51 | 5020 x2 = 319 - x2 : gosub 50 52 | 5030 y1 = 199 - y1 : gosub 50 53 | 5040 x2 = 319 - x2 : gosub 50 54 | 5050 for p = 0 to 3000 : next p 55 | 6000 run -------------------------------------------------------------------------------- /C64ColorGraphics/2advanced/4shapes.bas: -------------------------------------------------------------------------------- 1 | 0 if peek(49152) <> 128 then load "m/l",8,1 2 | 1 goto 1000 3 | 10 rem:::::::graphics 4 | 11 if mu then poke 53270,216 : rem mu = multi color graphics 5 | 12 poke 53265,59 : rem 59 for graphics, 27 for text 6 | 13 poke 53272,29 : rem pixel pattern storage, 29 means patterns not stored in same location as colors 7 | 14 poke 56576,198 : rem which bank used for pixel patterns and color - 198: use bank 1 8 | 15 return 9 | 20 rem:::::::text 10 | 21 poke 53270,200 11 | 22 poke 53265,27 12 | 23 poke 53272,21 13 | 24 poke 56576,199 14 | 25 return 15 | 30 rem:::::::clear hires/multi 16 | 31 sys 49164,c 17 | 32 xl = 0 : xh = 319 : yl = 0 : yh = 199 18 | 33 return 19 | 40 rem:::::::plot a point 20 | 41 sys 49502,x,y,c,mu 21 | 42 return 22 | 50 rem:::::::plot a line 23 | 51 sys 49502,x1,y1 to x2,y2,c,mu 24 | 52 return 25 | 70 rem:::::::clip a shape 26 | 71 s1 = 0 : s2 = 0 27 | 72 if x1 < xl then s1 = 1 28 | 73 if x1 > xh then s1 = 2 29 | 74 if y1 > yh then s1 = s1 + 4 30 | 75 if y1 < yl then s1 = s1 + 8 31 | 76 if x2 < xl then s2 = 1 32 | 77 if x2 > xh then s2 = 2 33 | 78 if y2 > yh then s2 = s2 + 4 34 | 79 if y2 < yl then s2 = s2 + 8 35 | 80 if s1 = 0 and s2 = 0 then 50 36 | 81 if s1 and s2 then return 37 | 82 s = s1 : if s = 0 then s = s2 38 | 83 if s and 1 then y = y1 + (y2 - y1) * (xl - x1)/(x2 - x1) : x = xl : goto 87 39 | 84 if s and 2 then y = y1 + (y2 - y1) * (xh - x1)/(x2 - x1) : x = xh : goto 87 40 | 85 if s and 4 then x = x1 + (x2 - x1) * (yh - y1)/(y2 - y1) : y = yh : goto 87 41 | 86 if s and 8 then x = x1 + (x2 - x1) * (yl - y1)/(y2 - y1) : y = yl 42 | 87 if s = s1 then x1 = x : y1 = y : goto 71 43 | 88 x2 = x : y2 = y : goto 71 44 | 90 rem:::::::draw a shape 45 | 92 for j = 0 to nl 46 | 93 e1% = l%(j,0) : e2% = l%(j,1) 47 | 94 x1 = p%(e1%,0) : y1 = p%(e1%,1) 48 | 95 x2 = p%(e2%,0) : y2 = p%(e2%,1) 49 | 96 gosub 70 50 | 97 next j 51 | 98 return 52 | 170 rem:::::::zap! 53 | 171 gosub 20 : print "do you know what you are doing?" : end 54 | 172 a = 256 : b = 2049 : c = 1003 55 | 173 if peek(b + 2) + a * peek(b + 3) >= c then 176 56 | 174 b = peek(b) + a * peek(b + 1) : on abs(b <> 0) goto 173 : end 57 | 175 a = 256 : b = peek(251) + a * peek(252) 58 | 176 if peek(b + 1) = 0 then end 59 | 177 print chr$(147) peek(b + 2) + a * peek(b + 3) : print "goto 175" 60 | 178 poke 251, b - int(b/a) * a : poke 252,b/a 61 | 179 poke 631,19 : poke 632,13 : poke 633,13 : poke 198,3 : end 62 | 800 rem:::::::retrieve a shape 63 | 801 restore 64 | 802 read s$, nd, nl 65 | 803 for i = 0 to nd 66 | 804 read p%(i,0), p%(i,1) : p%(i,2) = 1 67 | 805 next i 68 | 806 for i = 0 to nl 69 | 807 read l%(i,0), l%(i,1) 70 | 808 next i 71 | 809 on abs(s$ <> se$) goto 802 : return 72 | 1000 rem:::::::::::::::::::::::: 73 | 1001 rem main routine 74 | 1002 rem:::::::::::::::::::::::: 75 | 1003 rem: shape library : 76 | 1004 rem:::::::::::::::::::::::: 77 | 1006 data "rectangle", 3, 3 78 | 1008 data 8,8,47,8,47,31,8,31 79 | 1010 data 0,1,1,2,2,3,3,0 80 | 1020 data "inv-triangles", 5,5 81 | 1022 data 30,8,30,40,16,23 82 | 1024 data 33,8,33,40,47,23 83 | 1026 data 0,1,1,2,2,0 84 | 1028 data 3,4,4,5,5,3 85 | 1030 data "butterfly",41,44 86 | 1032 data 143,71,23,7,47,119 87 | 1034 data 87,127,63,143,127,167 88 | 1036 data 151,103,143,103,63,63 89 | 1038 data 63,103,135,111,95,127 90 | 1040 data 135,127,151,87,159,191 91 | 1042 data 167,87,151,79,159,55 92 | 1044 data 167,79,143,55,151,55 93 | 1046 data 151,71,151,47,135,7 94 | 1048 data 183,7,167,47,167,55 95 | 1050 data 175,55,167,71,175,71 96 | 1052 data 295,7,271,119,231,127 97 | 1054 data 255,143,191,167,167,103 98 | 1056 data 175,103,255,63,255,103 99 | 1058 data 183,111,183,127,223,127 100 | 1060 data 0,1,1,2,2,3,3,4 101 | 1062 data 4,5,5,6,6,0,7,8 102 | 1064 data 8,1,8,9,9,2,9,7 103 | 1066 data 12,10,10,11,11,12,22,23 104 | 1068 data 20,19,19,21,21,20,16,17 105 | 1070 data 17,18,18,16,13,15,15,14 106 | 1072 data 13,14,25,24,26,27,27,28 107 | 1074 data 26,28,35,29,29,30,30,31 108 | 1076 data 32,31,32,33,34,33,35,34 109 | 1078 data 29,35,36,37,37,30,37,38 110 | 1080 data 36,38,39,41,40,41,39,40 111 | 1082 data 38,31 112 | 1090 data "split-triangle",3,4 113 | 1092 data 0,0,15,23,0,47,-15,23 114 | 1094 data 0,1,1,2,2,3,3,0 115 | 1096 data 0,2 116 | 2000 rem mu = 1 117 | 2010 gosub 10 : c = 14 : gosub 30 118 | 2020 dim p%(99,2), l%(99,1) 119 | 2030 se$ = "butterfly" : gosub 800 120 | 2035 rem:::::::set viewing area 121 | 2036 xl = 144 : xh = 175 122 | 2037 yl = 56 : yh = 79 123 | 2040 c = 2 : gosub 90 124 | 6000 print chr$(5) : get a$ 125 | 6010 if a$ = " " then gosub 20 : end 126 | 6020 goto 6000 -------------------------------------------------------------------------------- /C64ColorGraphics/2advanced/5painting.bas: -------------------------------------------------------------------------------- 1 | 0 if peek(49152) <> 128 then load "m/l",8,1 2 | 1 goto 1000 3 | 10 rem:::::::graphics 4 | 11 if mu then poke 53270,216 : rem mu = multi color graphics 5 | 12 poke 53265,59 : rem 59 for graphics, 27 for text 6 | 13 poke 53272,29 : rem pixel pattern storage, 29 means patterns not stored in same location as colors 7 | 14 poke 56576,198 : rem which bank used for pixel patterns and color - 198: use bank 1 8 | 15 return 9 | 20 rem:::::::text 10 | 21 poke 53270,200 11 | 22 poke 53265,27 12 | 23 poke 53272,21 13 | 24 poke 56576,199 14 | 25 return 15 | 30 rem:::::::clear hires/multi 16 | 31 sys 49164,c 17 | 32 xl = 0 : xh = 319 : yl = 0 : yh = 199 18 | 33 return 19 | 40 rem:::::::plot a point 20 | 41 sys 49502,x,y,c,mu 21 | 42 return 22 | 50 rem:::::::plot a line 23 | 51 sys 49502,x1,y1 to x2,y2,c,mu 24 | 52 return 25 | 60 rem:::::::paint a shape 26 | 62 sys 49748,x,y,c,mu 27 | 63 return 28 | 70 rem:::::::clip a shape 29 | 71 s1 = 0 : s2 = 0 30 | 72 if x1 < xl then s1 = 1 31 | 73 if x1 > xh then s1 = 2 32 | 74 if y1 > yh then s1 = s1 + 4 33 | 75 if y1 < yl then s1 = s1 + 8 34 | 76 if x2 < xl then s2 = 1 35 | 77 if x2 > xh then s2 = 2 36 | 78 if y2 > yh then s2 = s2 + 4 37 | 79 if y2 < yl then s2 = s2 + 8 38 | 80 if s1 = 0 and s2 = 0 then 50 39 | 81 if s1 and s2 then return 40 | 82 s = s1 : if s = 0 then s = s2 41 | 83 if s and 1 then y = y1 + (y2 - y1) * (xl - x1)/(x2 - x1) : x = xl : goto 87 42 | 84 if s and 2 then y = y1 + (y2 - y1) * (xh - x1)/(x2 - x1) : x = xh : goto 87 43 | 85 if s and 4 then x = x1 + (x2 - x1) * (yh - y1)/(y2 - y1) : y = yh : goto 87 44 | 86 if s and 8 then x = x1 + (x2 - x1) * (yl - y1)/(y2 - y1) : y = yl 45 | 87 if s = s1 then x1 = x : y1 = y : goto 71 46 | 88 x2 = x : y2 = y : goto 71 47 | 90 rem:::::::draw a shape 48 | 92 for j = 0 to nl 49 | 93 e1% = l%(j,0) : e2% = l%(j,1) 50 | 94 x1 = p%(e1%,0) : y1 = p%(e1%,1) 51 | 95 x2 = p%(e2%,0) : y2 = p%(e2%,1) 52 | 96 gosub 70 53 | 97 next j 54 | 98 return 55 | 170 rem:::::::zap! 56 | 171 gosub 20 : print "do you know what you are doing?" : end 57 | 172 a = 256 : b = 2049 : c = 1003 58 | 173 if peek(b + 2) + a * peek(b + 3) >= c then 176 59 | 174 b = peek(b) + a * peek(b + 1) : on abs(b <> 0) goto 173 : end 60 | 175 a = 256 : b = peek(251) + a * peek(252) 61 | 176 if peek(b + 1) = 0 then end 62 | 177 print chr$(147) peek(b + 2) + a * peek(b + 3) : print "goto 175" 63 | 178 poke 251, b - int(b/a) * a : poke 252,b/a 64 | 179 poke 631,19 : poke 632,13 : poke 633,13 : poke 198,3 : end 65 | 800 rem:::::::retrieve a shape 66 | 801 restore 67 | 802 read s$, nd, nl 68 | 803 for i = 0 to nd 69 | 804 read p%(i,0), p%(i,1) : p%(i,2) = 1 70 | 805 next i 71 | 806 for i = 0 to nl 72 | 807 read l%(i,0), l%(i,1) 73 | 808 next i 74 | 809 on abs(s$ <> se$) goto 802 : return 75 | 1000 rem:::::::::::::::::::::::: 76 | 1001 rem main routine 77 | 1002 rem:::::::::::::::::::::::: 78 | 1003 rem: shape library : 79 | 1004 rem:::::::::::::::::::::::: 80 | 1006 data "rectangle", 3, 3 81 | 1008 data 8,8,47,8,47,31,8,31 82 | 1010 data 0,1,1,2,2,3,3,0 83 | 1020 data "inv-triangles", 5,5 84 | 1022 data 30,8,30,39,16,23 85 | 1024 data 33,8,33,39,47,23 86 | 1026 data 0,1,1,2,2,0 87 | 1028 data 3,4,4,5,5,3 88 | 1030 data "butterfly",41,44 89 | 1032 data 143,71,23,7,47,119 90 | 1034 data 87,127,63,143,127,167 91 | 1036 data 151,103,143,103,63,63 92 | 1038 data 63,103,135,111,95,127 93 | 1040 data 135,127,151,87,159,191 94 | 1042 data 167,87,151,79,159,55 95 | 1044 data 167,79,143,55,151,55 96 | 1046 data 151,71,151,47,135,7 97 | 1048 data 183,7,167,47,167,55 98 | 1050 data 175,55,167,71,175,71 99 | 1052 data 295,7,271,119,231,127 100 | 1054 data 255,143,191,167,167,103 101 | 1056 data 175,103,255,63,255,103 102 | 1058 data 183,111,183,127,223,127 103 | 1060 data 0,1,1,2,2,3,3,4 104 | 1062 data 4,5,5,6,6,0,7,8 105 | 1064 data 8,1,8,9,9,2,9,7 106 | 1066 data 12,10,10,11,11,12,22,23 107 | 1068 data 20,19,19,21,21,20,16,17 108 | 1070 data 17,18,18,16,13,15,15,14 109 | 1072 data 13,14,25,24,26,27,27,28 110 | 1074 data 26,28,35,29,29,30,30,31 111 | 1076 data 32,31,32,33,34,33,35,34 112 | 1078 data 29,35,36,37,37,30,37,38 113 | 1080 data 36,38,39,41,40,41,39,40 114 | 1082 data 38,31 115 | 1090 data "split-triangle",3,4 116 | 1092 data 0,0,15,23,0,47,-15,23 117 | 1094 data 0,1,1,2,2,3,3,0 118 | 1096 data 0,2 119 | 2010 mu = 1 : gosub 10 : c = 14 : gosub 30 120 | 2020 dim p%(99,2), l%(99,1) 121 | 2030 se$ = "butterfly" : gosub 800 122 | 2035 rem:::::::set viewing area 123 | 2036 rem xl = 144 : xh = 175 124 | 2037 rem yl = 56 : yh = 79 125 | 2040 c = 0 : gosub 90 126 | 2050 x = 56 : y = 40 : c = 12 : gosub 60 127 | 2060 x = 263 : gosub 60 128 | 2070 x = 40 : y = 48 : gosub 60 129 | 2080 x = 279 : gosub 60 130 | 2090 x = 80 : y = 80 : c = 8 : gosub 60 131 | 2100 x = 239 : gosub 60 132 | 2110 x = 120 : y = 120 : gosub 60 133 | 2120 x = 199 : gosub 60 134 | 2130 x = 160 : y = 96 : c = 0 : gosub 60 135 | 2140 y = 72 : gosub 60 136 | 2150 x = 148 : y = 58 : c = 2 : gosub 60 137 | 2160 x = 170 : gosub 60 138 | 6000 get a$ 139 | 6010 if a$ = " " then goto 6030 140 | 6020 goto 6000 141 | 6030 print chr$(5) chr$(147) : gosub 20 : end -------------------------------------------------------------------------------- /C64ColorGraphics/2advanced/8scale.bas: -------------------------------------------------------------------------------- 1 | 0 if peek(49152) <> 128 then load "m/l",8,1 2 | 1 goto 1000 3 | 10 rem:::::::graphics 4 | 11 if mu then poke 53270,216 : rem mu = multi color graphics 5 | 12 poke 53265,59 : rem 59 for graphics, 27 for text 6 | 13 poke 53272,29 : rem pixel pattern storage, 29 means patterns not stored in same location as colors 7 | 14 poke 56576,198 : rem which bank used for pixel patterns and color - 198: use bank 1 8 | 15 return 9 | 20 rem:::::::text 10 | 21 poke 53270,200 11 | 22 poke 53265,27 12 | 23 poke 53272,21 13 | 24 poke 56576,199 14 | 25 return 15 | 30 rem:::::::clear hires/multi 16 | 31 sys 49164,c 17 | 32 xl = 0 : xh = 319 : yl = 0 : yh = 199 18 | 33 return 19 | 40 rem:::::::plot a point 20 | 41 sys 49502,x,y,c,mu 21 | 42 return 22 | 50 rem:::::::plot a line 23 | 51 sys 49502,x1,y1 to x2,y2,c,mu 24 | 52 return 25 | 60 rem:::::::paint a shape 26 | 61 x = r%(pp,0) : y = r%(pp,1) : if x < 0 or y < 0 or x > 319 or y > 199 then return 27 | 62 sys 49748,x,y,c,mu 28 | 63 return 29 | 70 rem:::::::clip a shape 30 | 71 s1 = 0 : s2 = 0 31 | 72 if x1 < xl then s1 = 1 32 | 73 if x1 > xh then s1 = 2 33 | 74 if y1 > yh then s1 = s1 + 4 34 | 75 if y1 < yl then s1 = s1 + 8 35 | 76 if x2 < xl then s2 = 1 36 | 77 if x2 > xh then s2 = 2 37 | 78 if y2 > yh then s2 = s2 + 4 38 | 79 if y2 < yl then s2 = s2 + 8 39 | 80 if s1 = 0 and s2 = 0 then 50 40 | 81 if s1 and s2 then return 41 | 82 s = s1 : if s = 0 then s = s2 42 | 83 if s and 1 then y = y1 + (y2 - y1) * (xl - x1)/(x2 - x1) : x = xl : goto 87 43 | 84 if s and 2 then y = y1 + (y2 - y1) * (xh - x1)/(x2 - x1) : x = xh : goto 87 44 | 85 if s and 4 then x = x1 + (x2 - x1) * (yh - y1)/(y2 - y1) : y = yh : goto 87 45 | 86 if s and 8 then x = x1 + (x2 - x1) * (yl - y1)/(y2 - y1) : y = yl 46 | 87 if s = s1 then x1 = x : y1 = y : goto 71 47 | 88 x2 = x : y2 = y : goto 71 48 | 90 rem:::::::draw a shape 49 | 91 gosub 100 50 | 92 for j = 0 to nl 51 | 93 e1% = l%(j,0) : e2% = l%(j,1) 52 | 94 x1 = r%(e1%,0) : y1 = r%(e1%,1) 53 | 95 x2 = r%(e2%,0) : y2 = r%(e2%,1) 54 | 96 gosub 70 55 | 97 next j 56 | 98 return 57 | 100 rem:::::::apply transforms 58 | 101 for s = 0 to nd : for j = 0 to 2 59 | 102 r%(s,j) = 0 60 | 103 for i = 0 to 2 61 | 104 r%(s,j) = r%(s,j) + p%(s,i) * c(i,j) 62 | 105 next i,j,s 63 | 106 return 64 | 110 rem:::::::clear c matrix 65 | 111 for i = 0 to 2 : for j = 0 to 2 66 | 112 c(i,j) = abs(i = j) 67 | 113 next j,i 68 | 114 return 69 | 120 rem:::::::clear t matrix 70 | 121 for i = 0 to 2 : for j = 0 to 2 71 | 122 t(i,j) = abs(i = j) 72 | 123 next j,i 73 | 124 return 74 | 130 rem:::::::combine matrices 75 | 131 for i = 0 to 2 : for j = 0 to 2 76 | 132 w(i,j) = c(i,j) 77 | 133 next j,i 78 | 134 for s = 0 to 2 : for j = 0 to 2 79 | 135 c(s,j) = 0 80 | 136 for i = 0 to 2 81 | 137 c(s,j) = c(s,j) + w(s,i) * t(i,j) 82 | 138 next i,j,s 83 | 139 return 84 | 140 rem:::::::translate a shape 85 | 141 gosub 120 86 | 142 t(2,0) = xt : t(2,1) = yt 87 | 143 goto 130 88 | 150 rem:::::::scale a shape 89 | 151 gosub 120 90 | 152 xs = xs - (sx = 0) : ys = ys - (ys = 0) 91 | 153 t(0,0) = xs : t(1,1) = ys 92 | 154 goto 130 93 | 170 rem:::::::zap! 94 | 171 gosub 20 : print "do you know what you are doing?" : end 95 | 172 a = 256 : b = 2049 : c = 1003 96 | 173 if peek(b + 2) + a * peek(b + 3) >= c then 176 97 | 174 b = peek(b) + a * peek(b + 1) : on abs(b <> 0) goto 173 : end 98 | 175 a = 256 : b = peek(251) + a * peek(252) 99 | 176 if peek(b + 1) = 0 then end 100 | 177 print chr$(147) peek(b + 2) + a * peek(b + 3) : print "goto 175" 101 | 178 poke 251, b - int(b/a) * a : poke 252,b/a 102 | 179 poke 631,19 : poke 632,13 : poke 633,13 : poke 198,3 : end 103 | 800 rem:::::::retrieve a shape 104 | 801 restore 105 | 802 read s$, nd, nl 106 | 803 for i = 0 to nd 107 | 804 read p%(i,0), p%(i,1) : p%(i,2) = 1 108 | 805 next i 109 | 806 for i = 0 to nl 110 | 807 read l%(i,0), l%(i,1) 111 | 808 next i 112 | 809 on abs(s$ <> se$) goto 802 : return 113 | 1000 rem:::::::::::::::::::::::: 114 | 1001 rem main routine 115 | 1002 rem:::::::::::::::::::::::: 116 | 1003 rem: shape library : 117 | 1004 rem:::::::::::::::::::::::: 118 | 1005 dim p%(99,2), l%(99,1), r%(99,2), t(2,2), c(2,2), w(2,2) 119 | 1008 data "square", 3, 3 120 | 1010 data 16,8,31,8,31,23,16,23 121 | 1012 data 0,1,1,2,2,3,3,0 122 | 1014 data "scale shape",3,3 123 | 1016 data -31,-4,31,-4,31,4 124 | 1018 data -31,4 125 | 1020 data 0,1,1,2,2,3,3,0 126 | 2000 gosub 10 : c = 7 : gosub 30 127 | 2010 poke 53280,c 128 | 2020 se$ = "scale shape" : gosub 800 129 | 2030 gosub 110 130 | 2040 c = 6 131 | 2045 for l = 1 to 10 132 | 2050 xt = 159 : yt = 99 : gosub 140 133 | 2060 gosub 90 134 | 2070 gosub 110 135 | 2080 xs = xs * 1.2 : ys = ys * 1.2 : gosub 150 136 | 2090 next l 137 | 6000 get a$ 138 | 6010 if a$ = " " then goto 6030 139 | 6020 goto 6000 140 | 6030 print chr$(6) chr$(147) : gosub 20 : end -------------------------------------------------------------------------------- /C64ColorGraphics/2advanced/disk.d64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jacmoe/c64adventures/5822bec20522d3168bb985b3dbe6c2f025484a02/C64ColorGraphics/2advanced/disk.d64 -------------------------------------------------------------------------------- /C64ColorGraphics/2advanced/spacecraft.spt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | True 7 | False 8 | 1 9 | 0 10 | 6 11 | 7 12 | False 13 | False 14 | 15 | 0 16 | 0 17 | 4096 18 | 14336 19 | 14336 20 | 14336 21 | 14336 22 | 14336 23 | 113408 24 | 262016 25 | 262016 26 | 1048544 27 | 16546942 28 | 16529534 29 | 8402946 30 | 8402946 31 | 14336 32 | 14336 33 | 31744 34 | 37376 35 | 37376 36 | 37 | 38 | 39 | 40 | 0 41 | A 42 | A 43 | A 44 | A 45 | A 46 | A 47 | A 48 | A 49 | A 50 | A 51 | A 52 | A 53 | A 54 | A 55 | A 56 | A 57 | A 58 | A 59 | A 60 | A 61 | A 62 | A 63 | A 64 | A 65 | A 66 | A 67 | A 68 | A 69 | A 70 | A 71 | A 72 | A 73 | A 74 | A 75 | A 76 | A 77 | A 78 | A 79 | A 80 | A 81 | A 82 | A 83 | A 84 | A 85 | A 86 | A 87 | A 88 | A 89 | A 90 | A 91 | A 92 | A 93 | A 94 | A 95 | A 96 | A 97 | A 98 | A 99 | A 100 | A 101 | A 102 | A 103 | A 104 | A 105 | A 106 | A 107 | A 108 | A 109 | A 110 | A 111 | A 112 | A 113 | A 114 | A 115 | A 116 | A 117 | A 118 | A 119 | A 120 | A 121 | A 122 | A 123 | A 124 | A 125 | A 126 | A 127 | A 128 | A 129 | A 130 | A 131 | A 132 | A 133 | A 134 | A 135 | A 136 | A 137 | A 138 | A 139 | A 140 | A 141 | A 142 | A 143 | A 144 | A 145 | A 146 | A 147 | A 148 | A 149 | A 150 | A 151 | A 152 | A 153 | A 154 | A 155 | A 156 | A 157 | A 158 | A 159 | A 160 | A 161 | A 162 | A 163 | A 164 | A 165 | A 166 | A 167 | A 168 | A 169 | A 170 | A 171 | A 172 | A 173 | A 174 | A 175 | A 176 | A 177 | A 178 | A 179 | A 180 | A 181 | A 182 | A 183 | A 184 | A 185 | 186 | 187 | -------------------------------------------------------------------------------- /C64StepByStep/book1/10conversion.bas: -------------------------------------------------------------------------------- 1 | 10 for n=1 to 5 2 | 20 print chr$(147) 3 | 30 print : print tab(8);"temperature conversion" 4 | 40 poke 214,10 : print : input "give me a fahrenheit temperature";temp 5 | 50 poke 214,18 : print : poke 211,5 6 | 60 print temp;"fahrenheit = ";int((temp-32)*5/9+0.5);"centigrade" 7 | 70 for a=1 to 5000 8 | 80 next a 9 | 90 next n -------------------------------------------------------------------------------- /C64StepByStep/book1/11alphasorter.bas: -------------------------------------------------------------------------------- 1 | 10 print chr$(147) 2 | 20 print : input "enter word 1";a$ 3 | 30 input "enter word 2";b$ 4 | 40 if a$=b$ then print "they are the same string" : goto 10 5 | 50 if a$>b$ then print a$;" comes after ";b$ : goto 20 6 | 60 print a$;" comes before ";b$ : goto 20 -------------------------------------------------------------------------------- /C64StepByStep/book1/12colorchange.bas: -------------------------------------------------------------------------------- 1 | 10 print chr$(147) 2 | 20 for c=1 to 15 3 | 30 poke 53280,c : poke 53281,c 4 | 40 for k=1 to 300 5 | 50 next k 6 | 60 next c 7 | 70 c=0 : o$="black" : gosub 1000 8 | 80 c=1 : o$="white" : gosub 1000 9 | 90 c=2 : o$="red" : gosub 1000 10 | 100 c=3 : o$="cyan" : gosub 1000 11 | 110 c=4 : o$="purple" : gosub 1000 12 | 120 c=5 : o$="green" : gosub 1000 13 | 130 c=6 : o$="blue" : gosub 1000 14 | 140 c=7 : o$="yellow" : gosub 1000 15 | 150 c=8 : o$="orange" : gosub 1000 16 | 160 c=9 : o$="brown" : gosub 1000 17 | 170 c=10 : o$="light red" : gosub 1000 18 | 180 c=11 : o$="dark gray" : gosub 1000 19 | 190 c=12 : o$="medium gray" : gosub 1000 20 | 200 c=13 : o$="light green" : gosub 1000 21 | 210 c=14 : o$="light blue" : gosub 1000 22 | 220 c=15 : o$="light gray" : gosub 1000 23 | 999 end 24 | 1000 poke 53280,c 25 | 1010 for w=1 to 300 : next w 26 | 1020 print o$ 27 | 1999 return -------------------------------------------------------------------------------- /C64StepByStep/book1/13cursorcontrol.bas: -------------------------------------------------------------------------------- 1 | 10 print chr$(147) 2 | 20 input "(0-38) x=";x 3 | 30 input "(0-24) y=";y 4 | 40 print chr$(147) 5 | 50 poke 214,y : rem address 214 holds the cursor y position 6 | 55 print 7 | 56 poke 211,x : rem address 211 holds the cursor x position 8 | 60 print "x" -------------------------------------------------------------------------------- /C64StepByStep/book1/14jiffyclock.bas: -------------------------------------------------------------------------------- 1 | 10 rem commodore's real-time "jiffy" clock 2 | 20 rem is a 3-byte binary counter 3 | 30 rem incremented by one sixty times a second 4 | 40 poke 162,0 : rem location 162 changes sixty times a second 5 | 50 poke 161,0 : rem location 161 changes whenever 162 overflows from 255 6 | 60 rem location 160 is incremented whenever 161 overflows 7 | 65 print "what is your name"; 8 | 70 input name$ : print 9 | 75 rem peek what's in locations 162 and 161 10 | 80 t=int((peek(162)+peek(161)*256)/60) 11 | 90 print "your answer took";t;"seconds" -------------------------------------------------------------------------------- /C64StepByStep/book1/15characterset.bas: -------------------------------------------------------------------------------- 1 | 10 poke 53280,6 : poke 53281,7 : print chr$(28) : print chr$(147) 2 | 20 for n=1 to 4 3 | 30 for x=33 to 126 4 | 40 print chr$(x);" "; 5 | 50 next x 6 | 60 next n -------------------------------------------------------------------------------- /C64StepByStep/book1/16keyboardgraphics.bas: -------------------------------------------------------------------------------- 1 | 10 print chr$(147) : poke 53280,12 : poke 53281,2 2 | 20 c=1 : print chr$(5) 3 | 30 for k=1 to 20 : for d=1 to 40 4 | 40 if c=1 then print "{cm e}"; : goto 60 5 | 50 print "{cm r}"; 6 | 60 c=1-c 7 | 70 next d 8 | 80 c=1-c 9 | 90 next k -------------------------------------------------------------------------------- /C64StepByStep/book1/17rectangle.bas: -------------------------------------------------------------------------------- 1 | 10 print chr$(147);chr$(31) 2 | 20 poke 53280,0 : poke 53281,0 3 | 30 print "{cm o*18}" 4 | 40 for y=1 to 18 5 | 50 print "{cm h}{cm g*17}{cm j}" 6 | 60 next y 7 | 70 print "{cm u*18}" 8 | -------------------------------------------------------------------------------- /C64StepByStep/book1/18screencolormap.bas: -------------------------------------------------------------------------------- 1 | 10 poke 53280,11 : poke 53281,0 2 | 20 for y=0 to 24 3 | 30 for x=0 to 39 4 | 40 poke 1024+y*40+x,81 5 | 50 poke 55296+y*40+x,x 6 | 60 next x 7 | 70 next y -------------------------------------------------------------------------------- /C64StepByStep/book1/19screencolormap.bas: -------------------------------------------------------------------------------- 1 | 10 print chr$(147) : rem clear screen 2 | 15 poke 53280,0 : poke 53281,0 3 | 20 x=0 : y=0 : c=81 : d=11 : gosub 1000 4 | 30 x=0 : y=1 : c=81 : d=11 : gosub 1000 5 | 40 x=1 : y=1 : c=81 : d=8 : gosub 1000 6 | 50 x=1 : y=2 : c=81 : d=8 : gosub 1000 7 | 60 x=2 : y=2 : c=81 : d=8 : gosub 1000 8 | 70 x=2 : y=3 : c=81 : d=2 : gosub 1000 9 | 80 x=2 : y=4 : c=81 : d=2 : gosub 1000 10 | 85 rem position cursor at 0,6 11 | 90 poke 211,0 : poke 214,6 12 | 999 end 13 | 1000 rem plots to screen memory 14 | 1005 rem screen memory starts at 1024 15 | 1006 rem there is 25 rows 16 | 1008 rem each row is 40 columns wide 17 | 1010 poke 1024+y*40+x,c 18 | 2000 rem plots to colour memory 19 | 2010 rem colour memory starts at 55296 20 | 2015 rem 25 rows, 40 columns 21 | 2020 poke 55296+y*40+x,d 22 | 2999 return -------------------------------------------------------------------------------- /C64StepByStep/book1/1squared.bas: -------------------------------------------------------------------------------- 1 | 10 print chr$(147) 2 | 20 let x=150 3 | 30 let text$=" squared = " 4 | 40 print : print " ****************************" 5 | 50 print : print tab(8);x;text$;x^2 6 | 60 print : print " ****************************" -------------------------------------------------------------------------------- /C64StepByStep/book1/20bouncingball.bas: -------------------------------------------------------------------------------- 1 | 10 print chr$(147);chr$(5) : rem clear screen and set text to white 2 | 20 v=10 : x=20 : dx=1 3 | 25 poke 53280,6 : poke 53281,12 4 | 30 poke 214,y : print : poke 211,x 5 | 40 print " ";chr$(113);" "; 6 | 50 x=x+dx 7 | 60 for t=1 to 5 : next t 8 | 70 if x<1 then dx=-dx 9 | 80 if x>36 then dx=-dx 10 | 90 goto 30 11 | -------------------------------------------------------------------------------- /C64StepByStep/book1/21constellation.bas: -------------------------------------------------------------------------------- 1 | 5 rem demonstation of how to use a data statement 2 | 10 poke 53280,6 : poke 53281,6 : print chr$(147);chr$(5) 3 | 20 poke 214,6 : print : poke 211,7 4 | 30 print "ursa major" 5 | 40 data 8,25,12,18,13,11,13,14,13,27,16,7,16,21 6 | 50 number=7 : rem 14/2=7 7 | 60 for n=1 to number 8 | 70 read y,x 9 | 80 poke 214,y : print : poke 211,x 10 | 90 print "*" 11 | 100 for t=1 to 300 : next t 12 | 110 next n 13 | 120 print chr$(31) -------------------------------------------------------------------------------- /C64StepByStep/book1/22telephonelist.bas: -------------------------------------------------------------------------------- 1 | 10 print chr$(147) 2 | 20 data j.baker,322,g.hilton,166,r.hermann,103,s.klein,191 3 | 30 data m.perekera,86,t.philips,71,p.richard,100 4 | 40 data d.smith,27 5 | 50 print "personal telephone listing" 6 | 60 for t=1 to 2000 : next 7 | 70 print chr$(147) : poke 214,4 : print 8 | 80 print "complete list......press 1" 9 | 90 print "selective list.....press 2" 10 | 100 input "choice";choice 11 | 110 if choice=2 then 190 12 | 120 print chr$(147) 13 | 130 print : print : print 14 | 140 for c=1 to 8 15 | 150 read name$,n 16 | 160 print tab(6);name$;tab(20);n : print 17 | 170 next c 18 | 180 end 19 | 190 print chr$(147) 20 | 200 input entry$ 21 | 210 result$="name not found" 22 | 220 for c=1 to 8 23 | 230 read name$,n$ 24 | 240 if name$=entry$ then result$=name$+".........."+n$ 25 | 250 next c : print chr$(147) 26 | 260 print result$ : for t=1 to 2000 27 | 265 rem 'restore' sets the data pointer back to the beginning 28 | 270 next : restore : print chr$(147) : goto 50 -------------------------------------------------------------------------------- /C64StepByStep/book1/23maze.bas: -------------------------------------------------------------------------------- 1 | 10 poke 53280,8 : poke 53281,0 : print chr$(147);chr$(5) : print 2 | 20 for y=1 to 13 : for x=1 to 13 3 | 30 read m : print tab(12) 4 | 40 rem on var goto line, line, line works like this: 5 | 50 rem pick the goto that matches var 6 | 60 rem if m = 1 then goto 90 7 | 65 rem if m = 2 then goto 100 8 | 70 on m goto 90,100,110,120,130,140 9 | 80 on m-6 goto 150,160,170,180,190 10 | 90 print chr$(98); : goto 200 11 | 100 print chr$(99); : goto 200 12 | 110 print chr$(173); : goto 200 13 | 120 print chr$(176); : goto 200 14 | 130 print chr$(174); : goto 200 15 | 140 print chr$(189); : goto 200 16 | 150 print chr$(177); : goto 200 17 | 160 print chr$(171); : goto 200 18 | 170 print chr$(178); : goto 200 19 | 180 print chr$(179); : goto 200 20 | 190 print " "; 21 | 200 next x 22 | 210 print 23 | 220 next y 24 | 230 data 4,2,2,2,6,11,8,2,2,2,2,2,5 25 | 240 data 1,11,11,11,11,11,1,11,11,11,11,11,1 26 | 250 data 1,11,4,2,5,11,3,2,2,2,5,11,1 27 | 260 data 1,11,1,11,1,11,11,11,11,11,1,11,1 28 | 270 data 1,11,1,11,3,2,2,2,5,11,1,11,1 29 | 280 data 1,11,1,11,11,11,11,11,1,11,1,11,1 30 | 290 data 1,11,3,2,11,2,5,11,1,11,1,11,1 31 | 300 data 1,11,11,11,11,11,1,11,1,11,1,11,1 32 | 310 data 8,2,9,2,2,2,6,11,3,2,6,11,1 33 | 320 data 1,11,1,11,11,11,11,11,11,11,11,11,1 34 | 330 data 1,11,3,2,11,2,2,2,2,2,5,11,1 35 | 340 data 1,11,11,11,11,11,11,11,11,11,1,11,1 36 | 350 data 3,2,2,2,2,2,2,2,2,2,10,11,1 -------------------------------------------------------------------------------- /C64StepByStep/book1/24dataanimation.bas: -------------------------------------------------------------------------------- 1 | 10 print chr$(147) 2 | 20 poke 53280,12 : poke 53281,0 3 | 30 x=10 : y=7 : dx=1 : dy=-1 4 | 40 if x<3 then dx=-dx 5 | 50 if x>35 then dx=-dx 6 | 60 if y<2 then dy=-dy 7 | 70 if y>19 then dy=-dy 8 | 80 x=x+dx : y=y+dy : restore 9 | 90 poke 214,y : print : poke 211,x 10 | 100 read a$ : print a$ 11 | 110 poke 214,y+1 : print : poke 211,x+1 12 | 120 read b$ : print b$ 13 | 130 for t=1 to 10 : next t 14 | 140 print chr$(147) : goto 40 15 | 150 data "{red}{reverse on}{cm v}K {reverse off}","{blue}Q Q" -------------------------------------------------------------------------------- /C64StepByStep/book1/25taxrates.bas: -------------------------------------------------------------------------------- 1 | 10 print chr$(147) 2 | 20 print : input "a=";a 3 | 30 print 4 | 40 for c=1 to 6 5 | 50 read t 6 | 60 print a,"+";t"% =";a+a*t/100 7 | 70 next c 8 | 80 restore 9 | 90 goto 20 10 | 100 data 10,12.5,15,17.5,20,25 -------------------------------------------------------------------------------- /C64StepByStep/book1/26singlesprite.bas: -------------------------------------------------------------------------------- 1 | 10 poke 53280,6 : poke 53281,2 2 | 20 print chr$(147) 3 | 30 for c=0 to 63 4 | 40 read byte 5 | 50 poke 832+c,byte 6 | 60 next c 7 | 70 poke 2040,13 8 | 80 poke 53287,7 9 | 90 poke 53248,50 : poke 53249,100 : poke 53264,0 10 | 100 poke 53269,1 11 | 110 poke 53271,1 : poke 53277,1 12 | 1000 REM 13 | 1010 DATA 15,248,0 14 | 1020 DATA 1,192,0 15 | 1030 DATA 1,96,0 16 | 1040 DATA 1,240,0 17 | 1050 DATA 1,28,0 18 | 1060 DATA 241,254,0 19 | 1070 DATA 97,193,0 20 | 1080 DATA 114,31,224 21 | 1090 DATA 127,252,96 22 | 1100 DATA 255,254,56 23 | 1110 DATA 198,3,47 24 | 1120 DATA 255,254,56 25 | 1130 DATA 127,252,96 26 | 1140 DATA 114,31,224 27 | 1150 DATA 97,193,0 28 | 1160 DATA 241,254,0 29 | 1170 DATA 1,28,0 30 | 1180 DATA 1,240,0 31 | 1190 DATA 1,96,0 32 | 1200 DATA 1,192,0 33 | 1210 DATA 15,248,0,0 34 | -------------------------------------------------------------------------------- /C64StepByStep/book1/27singlespritesimplified.bas: -------------------------------------------------------------------------------- 1 | 5 let v=53248 : rem VIC chip address 2 | 10 poke 53280,6 : poke 53281,2 3 | 20 print chr$(147) 4 | 30 for c=0 to 63 5 | 40 read byte 6 | 50 poke 832+c, byte : rem poke sprite data into memory, 13th 64bit page 7 | 60 next c 8 | 70 poke 2040,13 : rem tell VIC to use page 13 9 | 80 poke v+39,1 : rem set sprite 0 color to white 10 | 85 rem set x position, y position, extra bit in v+16 (bit zero) 11 | 90 poke v,50 : poke v+1,100 : poke v+16,0 12 | 100 poke v+21,1 : rem turn sprite 0 on 13 | 105 rem horizontal expansion, vertical expansion 14 | 110 poke v+23,1 : poke v+29,1 15 | 1000 REM 16 | 1010 DATA 15,248,0 17 | 1020 DATA 1,192,0 18 | 1030 DATA 1,96,0 19 | 1040 DATA 1,240,0 20 | 1050 DATA 1,28,0 21 | 1060 DATA 241,254,0 22 | 1070 DATA 97,193,0 23 | 1080 DATA 114,31,224 24 | 1090 DATA 127,252,96 25 | 1100 DATA 255,254,56 26 | 1110 DATA 198,3,47 27 | 1120 DATA 255,254,56 28 | 1130 DATA 127,252,96 29 | 1140 DATA 114,31,224 30 | 1150 DATA 97,193,0 31 | 1160 DATA 241,254,0 32 | 1170 DATA 1,28,0 33 | 1180 DATA 1,240,0 34 | 1190 DATA 1,96,0 35 | 1200 DATA 1,192,0 36 | 1210 DATA 15,248,0,0 37 | -------------------------------------------------------------------------------- /C64StepByStep/book1/28doublesprite.bas: -------------------------------------------------------------------------------- 1 | 10 print chr$(147);chr$(19); 2 | 20 poke 53280,2 : poke 53281,12 3 | 30 print chr$(18);chr$(31); 4 | 40 v=53248 : for c=1 to 15 5 | 50 print " "; : next c 6 | 60 for c=0 to 127 : read byte 7 | 70 poke 832+c,byte : next c 8 | 80 x0=0 : y0=190 : x1=300 : y1=75 9 | 90 d0=1 : d1=-4 : poke v+21,3 10 | 100 poke 2040,13 : poke 2041,14 11 | 110 poke v+39,0 : poke v+40,7 12 | 120 poke v+23,3 : poke v+29,3 13 | 130 t0=int(x0/256) : t1=int(x1/256) 14 | 140 poke v+16,t0+2*t1 15 | 150 poke v,x0-t0*256 : poke v+1,y0 16 | 160 poke v+2,x1-t1*256 : poke v+3,y1 17 | 170 if x0>350 then x0=0 18 | 180 if x1>300 then d1=-d1 19 | 190 if x1<50 then d1=-d1 20 | 200 x0=x0+d0 : x1=x1+d1 : goto 120 21 | 210 poke v+23,3 : poke v+29,3 22 | 400 data 0,0,0,64,0,0,16,0,0 23 | 410 data 8,0,0,4,16,0,2,31,128 24 | 420 data 2,236,0,7,254,0,29,127,0 25 | 430 data 29,63,255,31,255,0,3,254,0 26 | 440 data 121,248,0,127,255,0,3,254,0 27 | 450 data 191,255,176,122,170,224,95,255,160 28 | 460 data 118,187,224,54,187,192,31,255,128,0 29 | 470 data 0,24,0,0,255,0,0,165,128 30 | 480 data 3,255,192,60,0,60,255,255,255 31 | 490 data 169,36,149,169,36,149,255,255,255 32 | 500 data 48,0,12,15,255,240,1,126,128 33 | 510 data 3,24,192,6,0,96,4,0,32 34 | 520 data 12,0,48,30,0,120,0,0,0 35 | 530 data 0,0,0,0,0,0,0,0,0,0 -------------------------------------------------------------------------------- /C64StepByStep/book1/29siren.bas: -------------------------------------------------------------------------------- 1 | 300 s=54272 : poke s+24,15 : rem s+24 is master volume 2 | 310 poke s+5,0 : poke s+6,240 : rem envelope 3 | 320 for k=1 to 4 4 | 330 poke s+4,33 : rem start sawtooth waveform (32 + 1) 5 | 340 poke s,0 : poke s+1,40 : rem frequency, first note 6 | 350 for t=1 to 500 : next 7 | 360 poke s,0 : poke s+1,30 : rem frequency, second note 8 | 370 for t=1 to 500 : next 9 | 380 poke s+4,32 : rem stop sawtooth (32 + 0) 10 | 390 next k -------------------------------------------------------------------------------- /C64StepByStep/book1/2display.bas: -------------------------------------------------------------------------------- 1 | 10 rem screen print 2 | 20 print chr$(147) 3 | 30 print tab(9);"%%%%%%%%%%%%%%%%%%%" 4 | 40 print tab(9);"%";tab(27);"%" 5 | 50 print tab(9);"%";tab(11);"demonstration";tab(27);"%" 6 | 60 print tab(9);"%";tab(11);"screen display";tab(27);"%" 7 | 70 print tab(9);"%";tab(27);"%" 8 | 80 print tab(9);"%%%%%%%%%%%%%%%%%%%" -------------------------------------------------------------------------------- /C64StepByStep/book1/30machinegun.bas: -------------------------------------------------------------------------------- 1 | 10 s=54272 : poke s+24,15 : rem turn up the volume! 2 | 20 for k=1 to 10 3 | 30 poke s+4,129 : rem random noise on 4 | 40 poke s+5,6 : poke s+6,89 : rem envelope: rise quickly, decay fast 5 | 50 poke s,0 : poke s+1,50 6 | 60 for t=1 to 65 : next 7 | 70 poke s+4,128 : rem random noise off 8 | 80 next k -------------------------------------------------------------------------------- /C64StepByStep/book1/31lasercannon.bas: -------------------------------------------------------------------------------- 1 | 100 s=54272 : poke s+24,15 : rem turn the volume up! 2 | 110 poke s+5,0 : poke s+6,249 3 | 120 poke s+4,129 4 | 130 for c=0 to 8 5 | 140 poke s,0 : poke s+1,44-c*4 : rem frequency change while looping 6 | 150 for t=1 to 30 : next 7 | 160 next c 8 | 170 poke s+4,128 -------------------------------------------------------------------------------- /C64StepByStep/book1/32bird.bas: -------------------------------------------------------------------------------- 1 | 10 s=54272 : poke s+24,15 2 | 20 poke s+5,0 : poke s+6,240 3 | 30 k=1 4 | 40 poke s+4,65 : poke s+3,8 5 | 50 poke s,0 : poke s+1,100 6 | 60 for t=1 to 60 : next 7 | 70 poke s+4,65 : for c=0 to 6 8 | 80 poke s+1,c*15+150 9 | 90 next c : poke s+4,0 10 | 100 for t=1 to 200 : next 11 | 110 k=k+1 : if k=2 then 70 12 | 120 for t=1 to 250 : next : goto 10 -------------------------------------------------------------------------------- /C64StepByStep/book1/33engine.bas: -------------------------------------------------------------------------------- 1 | 10 z=1 2 | 20 s=54272 : poke s+24,10 3 | 30 poke s+5,9 : poke s+4,129 4 | 40 poke s,10 : poke s+1,20 5 | 50 for t=1 to z : next 6 | 60 poke s+5,9 : poke s+4,17 7 | 70 poke s,17 : poke s+1,37 8 | 80 poke s+4,0 9 | 90 for t=1 to 10 : next 10 | 100 z=1.2*z 11 | 110 goto 20 -------------------------------------------------------------------------------- /C64StepByStep/book1/34datatune.bas: -------------------------------------------------------------------------------- 1 | 300 s=54272 : poke s+24,15 2 | 310 poke s+5,0 : poke s+6,160 3 | 320 read l,h,d 4 | 330 if h=0 then for t=1 to 20 : next t : goto 320 5 | 340 if h<0 then end 6 | 350 poke s+0,l : poke s+1,h 7 | 360 poke s+4,33 8 | 370 for t=1 to d : next t 9 | 380 poke s+4,32 10 | 390 goto 320 11 | 400 data 195,16,160,0,0,0,195,16,80 12 | 410 data 209,18,320,30,21,320,0,-1,0 -------------------------------------------------------------------------------- /C64StepByStep/book1/35chordsimple.bas: -------------------------------------------------------------------------------- 1 | 10 s=54272 : poke s+24,15 2 | 20 poke s+5,0 : poke s+6,160 3 | 30 poke s+12,0 : poke s+13,160 4 | 40 poke s+19,0 : poke s+20,160 5 | 50 poke s+4,17 6 | 60 poke s+0,98 : poke s+1,8 7 | 70 for t=1 to 500 : next t 8 | 80 poke s+11,17 9 | 90 poke s+7,143 : poke s+8,10 10 | 100 for t=1 to 500 : next t 11 | 110 poke s+18,17 12 | 120 poke s+14,143 : poke s+15,12 13 | 130 for t=1 to 2000 : next t 14 | 140 poke s+4,16 : poke s+11,16 : poke s+18,16 -------------------------------------------------------------------------------- /C64StepByStep/book1/36sheetmusic.bas: -------------------------------------------------------------------------------- 1 | 10 s=54272 : poke s+24,15 2 | 15 rem channel 1 - envelope shape: attack/decay, sustain/release 3 | 20 poke s+5,0 : poke s+6,240 4 | 25 rem channel 2 - envelope shape: attack/decay, sustain/release 5 | 30 poke s+12,0 : poke s+13,240 6 | 35 rem channel 3 - envelope shape: attack/decay, sustain/release 7 | 40 poke s+19,0 : poke s+20,240 8 | 45 rem turn all channels on: waveform + 1 9 | 50 poke s+4,33 : poke s+11,33 : poke s+18,33 10 | 60 read c 11 | 70 if c=0 then read d : for t=1 to d : next t : goto 60 12 | 80 if c<0 then 120 13 | 90 read l,h 14 | 100 poke s+(c*7)-7,l : poke s+(c*7)-6,h 15 | 110 goto 50 16 | 115 rem turn all channels off 17 | 120 poke s+4,32 : poke s+11,32 : poke s+18,32 : end 18 | 130 data 1,209,18,2,210,15,3,143,12 19 | 140 data 0,160,2,24,14,3,218,11,0,80 20 | 150 data 3,143,10,0,80,1,30,21,2,24,14,3,48,11,3,104,9 21 | 160 data 0,80,3,225,8,0,80,1,180,23 22 | 170 data 3,233,7,0,80,3,12,7,0,80 23 | 180 data 1,30,21,2,210,15,3,71,6,0,160 24 | 190 data 2,194,17,3,12,7,0,80 25 | 200 data 1,209,18,0,80,1,218,11,2,24,14 26 | 210 data 3,104,9,0,320 27 | 220 data -1 -------------------------------------------------------------------------------- /C64StepByStep/book1/37random.bas: -------------------------------------------------------------------------------- 1 | 5 rem displays a box in which random numbers are displayed 2 | 10 print chr$(147);chr$(5) : print : print 3 | 20 poke 53280,4 : poke 53281,6 4 | 30 for c=9 to 27 : poke 214,10 : print 5 | 40 print tab(c);"*" : poke 214,14 6 | 50 print : print tab(c);"*" 7 | 60 next c 8 | 70 for r=11 to 13 : poke 214,r : print 9 | 80 print tab(9);"*";tab(27);"*" 10 | 90 next r 11 | 100 poke 214,12 : print : poke 211,12 12 | 105 rem generates random numbers between 0 and 0.999999999 13 | 110 print rnd(0) 14 | 115 rem random whole numbers between 0 and 9 inclusive: 15 | 118 rem int(rnd(0)*10) 16 | 120 for t=1 to 1000 : next 17 | 130 poke 214,12 : print : poke 211,10 18 | 140 print " "; 19 | 150 goto 100 -------------------------------------------------------------------------------- /C64StepByStep/book1/38cointoss.bas: -------------------------------------------------------------------------------- 1 | 5 rem simuates tossed coins 2 | 10 print chr$(147) 3 | 20 print "heads-tails" 4 | 30 print : print 5 | 35 rem a is a whole random number between 1 and 2 inclusive 6 | 40 a=int(rnd(0)*2)+1 7 | 50 if a=1 then coin$="heads" : goto 70 8 | 60 coin$="tails" 9 | 70 print coin$, 10 | 80 for q=1 to 200 : next 11 | 90 goto 40 -------------------------------------------------------------------------------- /C64StepByStep/book1/39randomtest.bas: -------------------------------------------------------------------------------- 1 | 5 rem throws a dice 100 times and reports the result 2 | 10 print chr$(147) : n=0 : h=0 : t=0 3 | 20 print tab(13);"heads-tails" 4 | 30 for k=1 to 100 5 | 40 a=int(rnd(0)*2)+1 : n=n+1 6 | 50 if a=1 then coin$="heads" : goto 70 7 | 60 coin$="tails" 8 | 70 poke 214,5 : print : poke 211,10 9 | 80 print "this throw - ";coin$ : print 10 | 90 print tab(5);"heads";tab(28);"tails" 11 | 100 if a=1 then h=h+1 : goto 120 12 | 110 t=t+1 13 | 120 poke 214,9 : print : poke 211,5 14 | 130 print tab(6);h;tab(29);t : print 15 | 140 print tab(10);"total throws =";n 16 | 150 for z=1 to 500 : next 17 | 160 next k -------------------------------------------------------------------------------- /C64StepByStep/book1/3calculations.bas: -------------------------------------------------------------------------------- 1 | 10 print chr$(147) : rem clear the screen 2 | 20 print : print tab(8);"43/3 =";43/3 3 | 30 print : print tab(8);"3*18 =";3*18 4 | 40 print : print tab(8);"6.25*4 =";6.25*4 5 | 50 print : print tab(8);"179*9.8 =";179*9.8 6 | 60 print : print tab(8);"1002/28.7+3 =";1002/28.7+3 7 | 70 print : print tab(8);"100*9/5+32 ="100*9/5+32 -------------------------------------------------------------------------------- /C64StepByStep/book1/40randomgraphics.bas: -------------------------------------------------------------------------------- 1 | 5 rem plots ramdom graphics to the screen 2 | 10 print chr$(147);chr$(5) 3 | 20 poke 53280,5 : poke 53281,0 4 | 30 for n=1 to 1000 5 | 40 col=rnd(0)*15 6 | 50 x=int(rnd(0)*40) 7 | 60 y=int(rnd(0)*23) 8 | 70 poke 1024+y*40+x,90+rnd(1)*2 : poke 55296+y*40+x,col 9 | 80 next n -------------------------------------------------------------------------------- /C64StepByStep/book1/4conversions.bas: -------------------------------------------------------------------------------- 1 | 10 print chr$(147) 2 | 20 print "conversions" 3 | 30 print "{cm y*11}" 4 | 40 print 5 | 50 print "1 foot =";12*2.54;" centimeters" 6 | 60 print 7 | 70 print "30 centigrade =";(30*9/5)+32;" fahrenheit" 8 | 80 print 9 | 90 print "10 kilometers =";10*5/8;" miles" 10 | 100 print 11 | 110 print "1 year =";365*24*60*60;" seconds" -------------------------------------------------------------------------------- /C64StepByStep/book1/5operator.bas: -------------------------------------------------------------------------------- 1 | 10 print chr$(147) 2 | 20 print : print tab(5);"-------------------------" 3 | 30 print : print tab(7);"what is your name"; : input name$ 4 | 40 print : print tab(2);"commodore 64 - programmed by ";name$ 5 | 50 print : print tab(5);"-------------------------" -------------------------------------------------------------------------------- /C64StepByStep/book1/6asciicolors.bas: -------------------------------------------------------------------------------- 1 | 10 print chr$(147) : rem clear the screen 2 | 15 poke 53280,0 : poke 53281,0 : rem paint the screen black 3 | 20 print chr$(144);"black" 4 | 30 print chr$(5);"white" 5 | 40 print chr$(28);"red" 6 | 50 print chr$(159);"cyan" 7 | 60 print chr$(156);"purple" 8 | 70 print chr$(30);"green" 9 | 80 print chr$(31);"blue" 10 | 90 print chr$(158);"yellow" 11 | 100 print chr$(129);"orange" 12 | 110 print chr$(149);"brown" 13 | 120 print chr$(150);"light red" 14 | 130 print chr$(151);"dark gray" 15 | 140 print chr$(152);"medium gray" 16 | 150 print chr$(153);"light green" 17 | 160 print chr$(154);"light blue" 18 | 170 print chr$(155);"light gray" 19 | 180 print chr$(18);"reverse on" 20 | 190 print chr$(146);"reverse off" -------------------------------------------------------------------------------- /C64StepByStep/book1/7printing.bas: -------------------------------------------------------------------------------- 1 | 10 print chr$(147) : rem clear screen 2 | 12 poke 53280,1 : poke 53281,1 : rem paint the screen white 3 | 14 print chr$(144) : rem black text 4 | 15 print "printing with space between" 5 | 18 print chr$(151);"print 1;2;3;4;5;6;7;8";chr$(144) 6 | 20 print : print 1;2;3;4;5;6;7;8 : print 7 | 25 print "printing in zones" 8 | 28 print chr$(151);"print 1,2,3,4,5,6,7,8";chr$(144) 9 | 30 print : print 1,2,3,4,5,6,7,8 : print -------------------------------------------------------------------------------- /C64StepByStep/book1/8neverending.bas: -------------------------------------------------------------------------------- 1 | 10 print chr$(147) 2 | 20 poke 53280,6: poke 53281,7 3 | 30 let x=1 4 | 40 print x,x*2,x*x 5 | 50 let x=x+1 6 | 60 goto 40 -------------------------------------------------------------------------------- /C64StepByStep/book1/9fornext.bas: -------------------------------------------------------------------------------- 1 | 10 poke 53280,6: poke 53281,7 2 | 20 print chr$(144);chr$(147) 3 | 30 for x=1 to 20 4 | 40 print x, x*2, x*x 5 | 50 next x -------------------------------------------------------------------------------- /C64StepByStep/book2/10andorcalculator.bas: -------------------------------------------------------------------------------- 1 | 5 rem shows how and and or works 2 | 10 print chr$(147);chr$(5) : rem clear screen, white text 3 | 20 poke 214,5 : print : poke 211,2 : rem set cursor row, column 4 | 30 input "do you wish to see and/or (a/o)";a$ 5 | 40 input " enter 1st value (0-255)";v1 6 | 50 input " enter 2nd value (0-255)";v2 7 | 60 print : print tab(4);v1;tab(9); 8 | 70 v=v1 : gosub 500 : print 9 | 80 print tab(4);v2;tab(9); 10 | 90 v=v2 : gosub 500 : print 11 | 100 if a$="a" then 130 12 | 110 print tab(3);"=";v1 or v2;tab(9); 13 | 120 v=v1 or v2 : gosub 500 : goto 150 14 | 130 print tab(3);"=";v1 and v2;tab(9); 15 | 140 v=v1 and v2 : gosub 500 16 | 150 print : print : print tab(2); 17 | 160 input "press return to continue";a$ 18 | 170 goto 10 19 | 500 for c=7 to 0 step -1 20 | 510 print sgn(v and 2^c); 21 | 520 next c : print : return -------------------------------------------------------------------------------- /C64StepByStep/book2/11highresbasic.bas: -------------------------------------------------------------------------------- 1 | 1 rem Clears memory and prepares high res graphics 2 | 2 rem First, we need to move the BASIC storage area: 3 | 3 rem 1) poke 642,64 4 | 4 rem 2) poke 44,64 5 | 5 rem 3) poke 16384,0 6 | 6 rem 4) new 7 | 7 rem this must be performed manually 8 | 8 rem Not sure if this is needed in VICE .. 9 | 10 gosub 100 10 | 20 col=18 : gosub 200 11 | 30 end 12 | 100 rem tell VIC chip to use high-resolution mode 13 | 110 poke 53272,peek(53272) or 8 14 | 120 poke 53265,peek(53265) or 32 15 | 130 return 16 | 200 rem clear all 8000 bytes for graphics 17 | 210 for mem=8192 to 16191 18 | 220 poke mem,0 : next mem 19 | 230 rem clear 1000 bytes for display codes 20 | 240 for mem=1024 to 2023 21 | 250 poke mem,col : next mem 22 | 260 return -------------------------------------------------------------------------------- /C64StepByStep/book2/12highresmachinecode.bas: -------------------------------------------------------------------------------- 1 | 1 rem Clears memory and prepares high res graphics 2 | 2 rem Machine code version 3 | 3 rem First, we need to move the BASIC storage area: 4 | 4 rem 1) poke 642,64 5 | 5 rem 2) poke 44,64 6 | 6 rem 3) poke 16384,0 7 | 7 rem 4) new 8 | 8 rem this must be performed manually 9 | 9 rem Hint: run, reset, do above, then paste the code in 10 | 10 gosub 100 11 | 20 col=18 : gosub 200 12 | 30 end 13 | 100 rem tell VIC chip to use high-resolution mode 14 | 110 poke 53272,peek(53272) or 8 15 | 120 poke 53265,peek(53265) or 32 16 | 130 return 17 | 200 data 0,165,252,197,254,208,7,165 18 | 210 data 251,197,253,208,1,96,160,0 19 | 220 data 173,80,195,145,251,230,251 20 | 230 data 208,232,230,252,76,81,195 21 | 235 rem clears 8000 bytes for graphics 22 | 237 rem and 1000 bytes for diplay codes 23 | 240 restore : for c=50000 to 50029 24 | 250 read byte : poke c,byte : next c 25 | 260 poke 251,0 : poke 252,4 : poke 253,232 26 | 270 poke 254,7 : poke 50000,col : sys 50001 27 | 280 poke 251,0 : poke 252,32 : poke 253,64 28 | 290 poke 254,63 : poke 50000,0 : sys 50001 : return 29 | 300 byte=8192+int(ly/8)*320+int(lx/8)*8+(ly and 7) 30 | 310 mask=2^(7-(lx and 7)) 31 | 320 return 32 | 400 gosub 300 33 | 410 poke byte,peek(byte) or mask 34 | 420 cmem=1024+int(ly/8)*40+int(lx/8) 35 | 430 poke cmem,col 36 | 440 return 37 | 500 gosub 300 38 | 520 poke byte,peek(byte) and (255-mask) 39 | 530 return 40 | 600 gt=abs(nx-lx) 41 | 610 if abs(ny-ly)>gt then gt=abs(ny-ly) 42 | 620 xinc=(nx-lx)/gt : yinc=(ny-ly)/gt 43 | 630 xx=lx+0.5 : yy=ly+0.5 44 | 640 for cc=1 to gt 45 | 650 lx=int(xx) : ly=int(yy) : gosub 400 46 | 660 xx=xx+xinc : yy=yy+yinc 47 | 670 next cc : lx=nx : ly=ny : return -------------------------------------------------------------------------------- /C64StepByStep/book2/13parallellines.bas: -------------------------------------------------------------------------------- 1 | 10 gosub 100 2 | 20 col=18 : gosub 200 3 | 30 for ly=80 to 120 step 10 4 | 40 for lx=100 to 220 5 | 50 gosub 400 6 | 60 next lx 7 | 70 next ly 8 | 80 end 9 | 100 rem tell VIC chip to use high-resolution mode 10 | 110 poke 53272,peek(53272) or 8 11 | 120 poke 53265,peek(53265) or 32 12 | 130 return 13 | 200 data 0,165,252,197,254,208,7,165 14 | 210 data 251,197,253,208,1,96,160,0 15 | 220 data 173,80,195,145,251,230,251 16 | 230 data 208,232,230,252,76,81,195 17 | 235 rem clears 8000 bytes for graphics 18 | 237 rem and 1000 bytes for diplay codes 19 | 240 restore : for c=50000 to 50029 20 | 250 read byte : poke c,byte : next c 21 | 260 poke 251,0 : poke 252,4 : poke 253,232 22 | 270 poke 254,7 : poke 50000,col : sys 50001 23 | 280 poke 251,0 : poke 252,32 : poke 253,64 24 | 290 poke 254,63 : poke 50000,0 : sys 50001 : return 25 | 300 byte=8192+int(ly/8)*320+int(lx/8)*8+(ly and 7) 26 | 310 mask=2^(7-(lx and 7)) 27 | 320 return 28 | 400 gosub 300 29 | 410 poke byte,peek(byte) or mask 30 | 420 cmem=1024+int(ly/8)*40+int(lx/8) 31 | 430 poke cmem,col 32 | 440 return 33 | 500 gosub 300 34 | 520 poke byte,peek(byte) and (255-mask) 35 | 530 return -------------------------------------------------------------------------------- /C64StepByStep/book2/14triangle.bas: -------------------------------------------------------------------------------- 1 | 5 rem triangle plotter (code is at line 1000) 2 | 10 goto 1000 3 | 100 rem tell VIC chip to use high-resolution mode 4 | 110 poke 53272,peek(53272) or 8 5 | 120 poke 53265,peek(53265) or 32 6 | 130 return 7 | 200 data 0,165,252,197,254,208,7,165 8 | 210 data 251,197,253,208,1,96,160,0 9 | 220 data 173,80,195,145,251,230,251 10 | 230 data 208,232,230,252,76,81,195 11 | 235 rem clears 8000 bytes for graphics 12 | 237 rem and 1000 bytes for diplay codes 13 | 240 restore : for c=50000 to 50029 14 | 250 read byte : poke c,byte : next c 15 | 260 poke 251,0 : poke 252,4 : poke 253,232 16 | 270 poke 254,7 : poke 50000,col : sys 50001 17 | 280 poke 251,0 : poke 252,32 : poke 253,64 18 | 290 poke 254,63 : poke 50000,0 : sys 50001 : return 19 | 300 byte=8192+int(ly/8)*320+int(lx/8)*8+(ly and 7) 20 | 310 mask=2^(7-(lx and 7)) 21 | 320 return 22 | 400 gosub 300 23 | 410 poke byte,peek(byte) or mask 24 | 420 cmem=1024+int(ly/8)*40+int(lx/8) 25 | 430 poke cmem,col 26 | 440 return 27 | 500 gosub 300 28 | 520 poke byte,peek(byte) and (255-mask) 29 | 530 return 30 | 1000 gosub 100 : poke 53280,4 31 | 1010 col=103 : gosub 200 32 | 1020 lx=50 33 | 1030 for ly=50 to 150 34 | 1040 gosub 400 : next ly 35 | 1050 ly=150 36 | 1060 for lx=50 to 150 37 | 1070 gosub 400 : next lx 38 | 1080 for c=150 to 50 step -1 39 | 1090 lx=c : ly=c 40 | 1100 gosub 400 : next c 41 | 1110 goto 1110 -------------------------------------------------------------------------------- /C64StepByStep/book2/15pinandstring.bas: -------------------------------------------------------------------------------- 1 | 10 goto 1000 2 | 100 rem tell VIC chip to use high-resolution mode 3 | 110 poke 53272,peek(53272) or 8 4 | 120 poke 53265,peek(53265) or 32 5 | 130 return 6 | 200 data 0,165,252,197,254,208,7,165 7 | 210 data 251,197,253,208,1,96,160,0 8 | 220 data 173,80,195,145,251,230,251 9 | 230 data 208,232,230,252,76,81,195 10 | 235 rem clears 8000 bytes for graphics 11 | 237 rem and 1000 bytes for diplay codes 12 | 240 restore : for c=50000 to 50029 13 | 250 read byte : poke c,byte : next c 14 | 260 poke 251,0 : poke 252,4 : poke 253,232 15 | 270 poke 254,7 : poke 50000,col : sys 50001 16 | 280 poke 251,0 : poke 252,32 : poke 253,64 17 | 290 poke 254,63 : poke 50000,0 : sys 50001 : return 18 | 300 byte=8192+int(ly/8)*320+int(lx/8)*8+(ly and 7) 19 | 310 mask=2^(7-(lx and 7)) 20 | 320 return 21 | 400 gosub 300 22 | 410 poke byte,peek(byte) or mask 23 | 420 cmem=1024+int(ly/8)*40+int(lx/8) 24 | 430 poke cmem,col 25 | 440 return 26 | 500 gosub 300 27 | 520 poke byte,peek(byte) and (255-mask) 28 | 530 return 29 | 600 gt=abs(nx-lx) 30 | 610 if abs(ny-ly)>gt then gt=abs(ny-ly) 31 | 620 xinc=(nx-lx)/gt : yinc=(ny-ly)/gt 32 | 630 xx=lx+0.5 : yy=ly+0.5 33 | 640 for cc=1 to gt 34 | 650 lx=int(xx) : ly=int(yy) : gosub 400 35 | 660 xx=xx+xinc : yy=yy+yinc 36 | 670 next cc : lx=nx : ly=ny : return 37 | 1000 poke 53280,11 : gosub 100 38 | 1010 col=124 : gosub 200 39 | 1020 for c=0 to 160 step 10 40 | 1030 ly=20 : nx=260 41 | 1040 lx=c+100 : ny=c+20 42 | 1050 gosub 600 43 | 1060 next c 44 | 1070 for c=0 to 160 step 10 45 | 1080 lx=60 : ny=180 : col=124 46 | 1090 ly=c+20 : nx=c+60 47 | 1100 gosub 600 -------------------------------------------------------------------------------- /C64StepByStep/book2/16linemachine.bas: -------------------------------------------------------------------------------- 1 | 10 goto 1000 2 | 100 rem tell VIC chip to use high-resolution mode 3 | 110 poke 53272,peek(53272) or 8 4 | 120 poke 53265,peek(53265) or 32 5 | 130 return 6 | 200 data 0,165,252,197,254,208,7,165 7 | 210 data 251,197,253,208,1,96,160,0 8 | 220 data 173,80,195,145,251,230,251 9 | 230 data 208,232,230,252,76,81,195 10 | 235 rem clears 8000 bytes for graphics 11 | 237 rem and 1000 bytes for diplay codes 12 | 240 restore : for c=50000 to 50029 13 | 250 read byte : poke c,byte : next c 14 | 260 poke 251,0 : poke 252,4 : poke 253,232 15 | 270 poke 254,7 : poke 50000,col : sys 50001 16 | 280 poke 251,0 : poke 252,32 : poke 253,64 17 | 290 poke 254,63 : poke 50000,0 : sys 50001 : return 18 | 300 byte=8192+int(ly/8)*320+int(lx/8)*8+(ly and 7) 19 | 310 mask=2^(7-(lx and 7)) 20 | 320 return 21 | 400 gosub 300 22 | 410 poke byte,peek(byte) or mask 23 | 420 cmem=1024+int(ly/8)*40+int(lx/8) 24 | 430 poke cmem,col 25 | 440 return 26 | 500 gosub 300 27 | 520 poke byte,peek(byte) and (255-mask) 28 | 530 return 29 | 600 gt=abs(nx-lx) 30 | 610 if abs(ny-ly)>gt then gt=abs(ny-ly) 31 | 620 xinc=(nx-lx)/gt : yinc=(ny-ly)/gt 32 | 630 xx=lx+0.5 : yy=ly+0.5 33 | 640 for cc=1 to gt 34 | 650 lx=int(xx) : ly=int(yy) : gosub 400 35 | 660 xx=xx+xinc : yy=yy+yinc 36 | 670 next cc : lx=nx : ly=ny : return 37 | 1000 poke 53280,0 : gosub 100 38 | 1010 col=208 : gosub 200 39 | 1020 pen=0 : lx=0 : ly=0 40 | 1030 read nx,ny 41 | 1040 if nx>1 then 1090 42 | 1050 if ny=1 then pen=1 : goto 1030 43 | 1060 if ny=0 then pen=0 : goto 1030 44 | 1070 if ny=2 then 1070 45 | 1080 col=-ny : goto 1030 46 | 1090 if pen=0 then lx=nx : ly=ny : goto 1030 47 | 1100 gosub 600 : goto 1030 48 | 1200 data -1,0,49,123,-1,1,74,102,73,112,78,112,81,98,74,102,88,94,212,78 49 | 1210 data 207,85,254,4,266,2,256,82,207,85,-1,0,258,72,-1,1 50 | 1220 data 272,70,286,98,250,137,236,108,272,70 51 | 1230 data 258,72,272,62,304,60,280,86,-1,0,245,125,-1,1 52 | 1240 data 90,130,136,156,145,192,173,195,245,125 53 | 1250 data -1,0,236,108,-1,1,158,114,-1,0,106,140,-1,1,78,140,49,134,49,123 54 | 1260 data -1,0,250,137,-1,1,233,137 55 | 1360 data -1.2 -------------------------------------------------------------------------------- /C64StepByStep/book2/1stardistance.bas: -------------------------------------------------------------------------------- 1 | 5 rem converts star distance from lightyears to miles 2 | 6 rem uses a function 3 | 10 print chr$(147) : poke 53280,0 : poke 53281,0 4 | 20 poke 214,5 : print 5 | 30 print tab(8);"star distance program" 6 | 40 print tab(8);"{cm i*21}" 7 | 50 def fnc(l)=l*5.88 8 | 60 print : print : print 9 | 70 print "enter star's distance in light years" : print : print tab(15); 10 | 80 input l 11 | 90 print : print : print 12 | 100 print "the star is ";fnc(l);" thousand billion" 13 | 110 print : print tab(10);"miles from earth" -------------------------------------------------------------------------------- /C64StepByStep/book2/2carpetcoster.bas: -------------------------------------------------------------------------------- 1 | 10 print chr$(147) : def fnc(z)=(x*y)*z : poke 53280,0 : poke 53281,0 2 | 20 print "carpet costing program" : print : print 3 | 30 input "how many rooms to carpet";n : print 4 | 40 print "what is the cost of carpet" 5 | 50 input "per unit area";p 6 | 60 t=0 : for c=1 to n 7 | 70 print chr$(147) 8 | 80 poke 214,4 : print : poke 211,5 : poke 53280,4 : poke 53281,6 9 | 90 print chr$(176); 10 | 100 for k=1 to 20 11 | 110 print chr$(99); : next k 12 | 120 print chr$(174) 13 | 130 for k=1 to 10 14 | 140 poke 211,5 : print chr$(98); 15 | 150 poke 211,26 : print chr$(98) 16 | 160 next k 17 | 170 poke 211,5 : print chr$(173); 18 | 180 for k=1 to 20 19 | 190 print chr$(99); : next k 20 | 200 print chr$(189) 21 | 210 poke 214,9 : print : poke 211,9 22 | 220 print "n =";c 23 | 230 poke 214,2 : print : poke 211,6 24 | 240 poke 214,9 : print : poke 211,28 25 | 250 print "x =" 26 | 260 poke 211,28 : input x 27 | 270 poke 214,17 : print : poke 211,10 28 | 280 input "y =";y 29 | 290 print chr$(147) : poke 53280,0 : poke 53281,0 30 | 300 poke 214,6 : print : poke 211,8 31 | 310 print "cost per unit area";p 32 | 320 print : print tab(8);"length";x 33 | 330 print : print tab(8);"width";y 34 | 340 print : print tab(8);"cost";fnc(p) 35 | 350 t=t+fnc(p) : print : print 36 | 360 print tab(8);"total cost";t 37 | 370 for z=1 to 2000 : next z : next c -------------------------------------------------------------------------------- /C64StepByStep/book2/3bouncingball.bas: -------------------------------------------------------------------------------- 1 | 5 rem from page 73 in book 1 and 2, but does not appear to work 2 | 10 s=54272 : poke s+24,15 3 | 20 poke s+5,0 : poke s+6,240 4 | 30 poke 53280,0 : poke 53281,0 5 | 40 poke s+4,16 : print chr$(147) 6 | 50 for r=3 to 18 7 | 60 poke 214,r : print chr$(129) 8 | 70 print tab(11);chr$(18);" "; 9 | 80 print tab(26);" " 10 | 90 poke 214,3 : print : poke 211,r+8 11 | 100 print chr$(18);" " 12 | 110 poke 214,18 : print : poke 211,r+8 13 | 120 print chr$(18);" " 14 | 130 next r 15 | 140 x1=int(rnd(0)*10)+14 : y1=15 16 | 150 d1=0.9 : d2=-1 17 | 160 x2=14 : y2=int(rnd(1)*10)+6 18 | 170 d3=-1 : d4=0.8 19 | 180 poke 214,y1 : print : poke 211,x1 20 | 190 print " " : poke s+4,16 21 | 200 poke 214,y2 : print : poke 211,x2 22 | 210 poke 214,y : print : poke 211,x 23 | 220 print chr$(113) 24 | 230 if x<13 or x>25 then dx=-dx : f=1 25 | 240 if y<5 or y>16 then dy=-dy : f=1 26 | 250 if f=0 then 180 27 | 260 poke s+4,17 28 | 270 goto 180 -------------------------------------------------------------------------------- /C64StepByStep/book2/4doublebouncingball.bas: -------------------------------------------------------------------------------- 1 | 5 rem two bouncing balls - does not work either - page 73 (book 1 and 2) 2 | 10 s=54272 : poke s+24,15 3 | 20 poke s+1,115 : poke s,88 4 | 30 poke s+5,0 : poke s+6,240 5 | 40 poke 53280,0 : poke 53281,0 6 | 50 print chr$(147) 7 | 60 for r=3 to 18 8 | 70 poke 214,r : print chr$(129) 9 | 80 print tab(11);chr$(18);" "; 10 | 90 print tab(26);" " 11 | 100 poke 214,3 : print : poke 211,r+8 12 | 110 print chr$(18);" " 13 | 120 poke 214,18 : print : poke 211,r+8 14 | 130 print chr$(18);" " 15 | 140 next r 16 | 150 print chr$(159) 17 | 160 x=15 : y=15 18 | 170 dx=1.2 : dy=-1 19 | 180 poke 214,y : print : poke 211,x 20 | 190 poke s+4,16 21 | 200 x=x+dx : y=y+dy : f=0 22 | 210 print " " 23 | 220 x1=x1+d1 : y1=y1+d2 : f=0 24 | 230 x2=x2+d3 : y2=y2+d4 25 | 240 poke 214,y1 : print : poke 211,x1 26 | 250 print chr$(156);chr$(113) 27 | 260 poke 214,y2 : print : poke 211,x2 28 | 270 print chr$(159);chr$(113) 29 | 280 if x1<13 or x1>25 then d1=-d1 : f=1 30 | 290 if y1<5 or y1>16 then d2=-d2 : f=1 31 | 300 if x2<13 or x2>24 then d3=-d3 : f=2 32 | 310 if x2<5 or y2>17 then d4=-d4 : f=2 33 | 320 if x2<=x1+1 and x2>=x1-1 and y2<=y1+1 and y2>=y1-1 then f=3 34 | 330 if f=0 then 180 35 | 340 if f=1 then poke s+1,115 : poke s,88 : goto 370 36 | 350 if f=3 then poke s+1,55 : poke s,80 : goto 370 37 | 360 poke s+1,85 : poke s,88 38 | 370 poke s+4,17 : if f=3 then 10 39 | 380 goto 180 -------------------------------------------------------------------------------- /C64StepByStep/book2/5firebase.bas: -------------------------------------------------------------------------------- 1 | 10 print chr$(147);chr$(158) 2 | 20 poke 53280,5 : poke 53281,0 3 | 30 poke 214,20 : print 4 | 40 print tab(18);chr$(191);chr$(18);chr$(183);chr$(191) 5 | 50 print tab(17);chr$(191);chr$(18);chr$(184);" ";chr$(184);chr$(191) 6 | 60 x=7 : y=19 7 | 70 poke 214,y : print 8 | 80 print tab(19);" " 9 | 90 poke 214,6 : print 10 | 100 print tab(x);" " 11 | 110 x=x+1 : y=y-1 12 | 120 if x>36 then x=5 13 | 130 if y<1 then y=19 14 | 140 poke 214,6 : print 15 | 150 print tab(x);chr$(153);"]>" 16 | 160 poke 214,y : print 17 | 170 print tab(19);chr$(5);"^" 18 | 180 if x=18 and y=6 or x=19 and y=6 then 200 19 | 190 goto 70 20 | 200 for t=1 to 1000 : next t : goto 10 -------------------------------------------------------------------------------- /C64StepByStep/book2/6keyboardencoder.bas: -------------------------------------------------------------------------------- 1 | 10 print chr$(147) 2 | 20 print "type encoder" 3 | 30 get a$ : if a$="" then 30 4 | 40 if a$<"a" then 90 5 | 50 if a$>"z" then 90 6 | 60 a=asc(a$)+2 7 | 70 if a>90 then a=a-26 8 | 80 a$=chr$(a) 9 | 90 print a$; 10 | 100 goto 30 -------------------------------------------------------------------------------- /C64StepByStep/book2/7functionkeydetect.bas: -------------------------------------------------------------------------------- 1 | 10 print chr$(147) 2 | 20 get a$ : if a$="" then 20 3 | 30 a=asc(a$) 4 | 40 if a=133 then print "f1" : goto 20 5 | 50 if a=137 then print "f2" : goto 20 6 | 60 if a=134 then print "f3" : goto 20 7 | 70 if a=138 then print "f4" : goto 20 8 | 80 if a=135 then print "f5" : goto 20 9 | 90 if a=139 then print "f6" : goto 20 10 | 100 if a=136 then print "f7" : goto 20 11 | 110 if a=140 then print "f8" : goto 20 12 | 120 print "not a function" : goto 20 -------------------------------------------------------------------------------- /C64StepByStep/book2/8reactiontester.bas: -------------------------------------------------------------------------------- 1 | 5 rem uses ti and ti$ to get and set the clock 2 | 10 print chr$(147) : poke 53280,0 : poke 53281,0 3 | 20 poke 214,5 : print : poke 211,6 4 | 30 print "test your reflexes against" 5 | 40 print : print tab(10); 6 | 50 print "the reaction tester" 7 | 60 for t=1 to 1500 : next t 8 | 70 a$=chr$(int(rnd(0)*26)+65) 9 | 80 poke 214,10 : print : poke 211,10 10 | 90 print "find this key: "; 11 | 100 for t=1 to 500 : next t 12 | 110 print a$ : ti$="000000" 13 | 120 get r$ : if r$="" then 120 14 | 130 if r$<>a$ then 120 15 | 140 poke 214,14 : print : poke 211,8 16 | 150 print "you took";int(ti/0.6)/100; 17 | 160 print "seconds" 18 | 170 for t=1 to 3000 : next t 19 | 180 goto 10 -------------------------------------------------------------------------------- /C64StepByStep/book2/9andorsprites.bas: -------------------------------------------------------------------------------- 1 | 5 rem using and and or with sprites 2 | 10 print chr$(147); : poke 53280,6 3 | 20 poke 53281,2 : for c=0 to 62 4 | 30 read byte 5 | 40 poke 832+c,byte 6 | 50 next c : v=53248 : poke v+16,0 7 | 60 for c=0 to 7 8 | 70 poke 2040+c,13 9 | 80 poke v+39+c,7 10 | 90 poke v+2*c+1,90 11 | 100 hx=int((32*c+54)/256) 12 | 110 poke v+2*c,(32*c+54)-(hx*256) 13 | 120 poke v+16,peek(v+16) or (2^c*hx) 14 | 130 poke v+21,peek(v+21) or 2^c 15 | 140 next c : print chr$(158); 16 | 150 poke 214,10 : print : poke 211,1 17 | 160 for c=0 to 7 18 | 170 print tab(c*4+4);c; 19 | 180 next c : print 20 | 190 poke 214,15 : print : poke 211,3 21 | 200 print "0/1 "; 22 | 210 poke 211,6 : input a 23 | 220 poke 214,18 : print : poke 211,3 24 | 230 print "0-7"; : poke 211,6 : input s 25 | 240 poke 214,18 : print : poke 211,3 26 | 250 print " " 27 | 260 if a=1 then 290 28 | 270 poke v+21,peek(v+21) and (255-2^s) 29 | 280 goto 190 30 | 290 poke v+21,peek(v+21) or 2^s 31 | 300 goto 190 32 | 800 data 3,0,192,2,129,0,0,66,0 33 | 810 data 0,126,0,96,255,6,145,153,137 34 | 820 data 11,153,208,7,255,224,3,231,192 35 | 830 data 3,231,192,99,231,198,147,255,201 36 | 840 data 11,126,208,7,0,224,3,255,192 37 | 850 data 3,255,192,0,255,0,0,195,0 38 | 860 data 0,195,0,4,195,32,7,195,224 -------------------------------------------------------------------------------- /C64StepByStep/book2/andorsprites.spt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | True 7 | False 8 | 1 9 | 0 10 | 6 11 | 7 12 | False 13 | False 14 | 15 | 196800 16 | 164096 17 | 16896 18 | 32256 19 | 6356742 20 | 9542025 21 | 760272 22 | 524256 23 | 255936 24 | 255936 25 | 6547398 26 | 9699273 27 | 753360 28 | 458976 29 | 262080 30 | 262080 31 | 65280 32 | 49920 33 | 49920 34 | 312096 35 | 508896 36 | 37 | 38 | 39 | 40 | 0 41 | A 42 | A 43 | A 44 | A 45 | A 46 | A 47 | A 48 | A 49 | A 50 | A 51 | A 52 | A 53 | A 54 | A 55 | A 56 | A 57 | A 58 | A 59 | A 60 | A 61 | A 62 | A 63 | A 64 | A 65 | A 66 | A 67 | A 68 | A 69 | A 70 | A 71 | A 72 | A 73 | A 74 | A 75 | A 76 | A 77 | A 78 | A 79 | A 80 | A 81 | A 82 | A 83 | A 84 | A 85 | A 86 | A 87 | A 88 | A 89 | A 90 | A 91 | A 92 | A 93 | A 94 | A 95 | A 96 | A 97 | A 98 | A 99 | A 100 | A 101 | A 102 | A 103 | A 104 | A 105 | A 106 | A 107 | A 108 | A 109 | A 110 | A 111 | A 112 | A 113 | A 114 | A 115 | A 116 | A 117 | A 118 | A 119 | A 120 | A 121 | A 122 | A 123 | A 124 | A 125 | A 126 | A 127 | A 128 | A 129 | A 130 | A 131 | A 132 | A 133 | A 134 | A 135 | A 136 | A 137 | A 138 | A 139 | A 140 | A 141 | A 142 | A 143 | A 144 | A 145 | A 146 | A 147 | A 148 | A 149 | A 150 | A 151 | A 152 | A 153 | A 154 | A 155 | A 156 | A 157 | A 158 | A 159 | A 160 | A 161 | A 162 | A 163 | A 164 | A 165 | A 166 | A 167 | A 168 | A 169 | A 170 | A 171 | A 172 | A 173 | A 174 | A 175 | A 176 | A 177 | A 178 | A 179 | A 180 | A 181 | A 182 | A 183 | A 184 | A 185 | 186 | 187 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 2-Clause License 2 | 3 | Copyright (c) 2017, Jacob Moen 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # c64adventures [Moved to codeberg] 2 | 3 | *Achtung*: This repository will not be updated. 4 | 5 | If anything new happens to this, it will happen at -> https://codeberg.org/jacmoe/c64adventures 6 | 7 | ---------------------------------------------------------------------------------- 8 | 9 | # c64adventures 10 | Adventures into retro 8 bit Commodore 64 programming 11 | 12 | The books used in this adventure: 13 | 14 | * Step by Step Programming Commodore 64 15 | * Commodore 64 Color Graphics - a Beginner's Guide 16 | * Commodore 64 Color Graphics - an Advanced Guide 17 | * Assembly Language for Kids - Commodore 64 18 | * Commodore 64 Assembly Language 19 | * Commodore 64/128 Assembly Language Programming 20 | 21 | 22 | 23 | The books can be obtained from [DLH's Commodore Archive][bombjack] 24 | 25 | 26 | This adventure is powered by [CBM .prg Studio][cbmstudio] and [WinVICE][winvice] 27 | 28 | 29 | Since CBM .prg Studio is only available for Windows, I ran Windows 7 in VirtualBox, and it works fine :) 30 | 31 | 32 | ----------------------------- 33 | 34 | ![Step by Step Programming Commodore 64][book1n2] 35 | 36 | ----------------------------- 37 | 38 | ![Commodore 64 Color Graphics - a Beginner's Guide][cgraphicsb] 39 | ![Final project][boat] 40 | 41 | ----------------------------- 42 | 43 | ![Commodore 64 Color Graphics - an Advanced Guide][cgraphicsa] 44 | 45 | ----------------------------- 46 | 47 | ![Assembly Language for Kids][asm4kids] 48 | 49 | ----------------------------- 50 | 51 | ![Commodore 64 Assembly Language][c64asmlang] 52 | 53 | ----------------------------- 54 | 55 | ![Commodore 64/128 Assembly Language Programming][c64128asm] 56 | 57 | ----------------------------- 58 | [book1n2]: https://github.com/jacmoe/c64adventures/raw/master/book1n2.jpg "Step by Step Programming Commodore 64" 59 | [cgraphicsb]: https://github.com/jacmoe/c64adventures/raw/master/cgraphicsb.jpg "Commodore 64 Color Graphics - a Beginner's Guide" 60 | [asm4kids]: https://github.com/jacmoe/c64adventures/raw/master/asm4kids.jpg "Assembly Language for Kids Commodore 64" 61 | [c64asmlang]: https://github.com/jacmoe/c64adventures/raw/master/c64asmlang.jpg "Commodore 64 Assembly Language" 62 | [c64128asm]: https://github.com/jacmoe/c64adventures/raw/master/c64128asm.jpg "Commodore 64/128 Assembly Language Programming" 63 | 64 | [boat]: https://github.com/jacmoe/c64adventures/raw/master/C64ColorGraphics/1beginner/boat.png "Final beginner's project" 65 | [cgraphicsa]: https://github.com/jacmoe/c64adventures/raw/master/cgraphicsa.jpg "Commodore 64 Color Graphics - an Advanced Guide" 66 | [bombjack]: http://www.bombjack.org/commodore/books.htm "DLH's Commodore Archive" 67 | [cbmstudio]: http://www.ajordison.co.uk/index.html "CBM .prg Studio" 68 | [winvice]: http://vice-emu.sourceforge.net/windows.html "WINVice" 69 | -------------------------------------------------------------------------------- /asm4kids.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jacmoe/c64adventures/5822bec20522d3168bb985b3dbe6c2f025484a02/asm4kids.jpg -------------------------------------------------------------------------------- /book1n2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jacmoe/c64adventures/5822bec20522d3168bb985b3dbe6c2f025484a02/book1n2.jpg -------------------------------------------------------------------------------- /c64128asm.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jacmoe/c64adventures/5822bec20522d3168bb985b3dbe6c2f025484a02/c64128asm.jpg -------------------------------------------------------------------------------- /c64asmlang.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jacmoe/c64adventures/5822bec20522d3168bb985b3dbe6c2f025484a02/c64asmlang.jpg -------------------------------------------------------------------------------- /cgraphicsa.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jacmoe/c64adventures/5822bec20522d3168bb985b3dbe6c2f025484a02/cgraphicsa.jpg -------------------------------------------------------------------------------- /cgraphicsb.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jacmoe/c64adventures/5822bec20522d3168bb985b3dbe6c2f025484a02/cgraphicsb.jpg -------------------------------------------------------------------------------- /cheatsheet.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------- 2 | Processor Status Register 3 | 4 | bits 7 6 5 4 3 2 1 0 5 | flags N V - B D I Z C 6 | 7 | N = negative 8 | V = bit overflow 9 | B = break 10 | D = decimal mode 11 | I = interrupt disable 12 | Z = zero 13 | C = carry 14 | 15 | -------------------------------------------------------- 16 | 17 | Adressing Modes 18 | 19 | Mode sample machine- bytes 20 | . statement code 21 | 22 | Immediate adc #$03 69 03 2 23 | Zero Page adc #$03 65 03 2 24 | Zero Page,X adc $03,x 75 03 2 25 | Absolute adc $0300 6d 00 03 3 26 | Absolute Indexed,X adc $0300,x 7d 00 03 3 27 | Absolute Indexed,Y adc $0300,y 79 00 03 3 28 | Indexed Indirect adc ($03,x) 61 03 2 29 | Indirect Indexed adc ($03),y 71 03 2 30 | 31 | 32 | . Adressing Mode format 33 | 1 Implicit (implied) rts 34 | 2 Accumulator asl a 35 | 3 Immediate lda #2 36 | 4 Absolute lda $02a7 37 | 5 Zero Page sta $fb 38 | 6 Relative bcc label 39 | 7 Absolute Indexed,x lda $02a7,x 40 | 8 Absolute Indexed,y lda $02a7,y 41 | 9 Zero Page,x lda $fb,x 42 | 10 Zero Page,y stx $fb,y 43 | 11 Indexed Indirect lda ($fd,x) 44 | 12 Indirect Indexed lda ($fd),y 45 | 13 Unindexed Indirect jmp 46 | 47 | 48 | Zero-Page,X Adressing 49 | Format: lda $fb,x 50 | Instructions that can be used: adc, and, asl, cmp, dec, eor, inc, lda, ldy, lsr, ora, rol, ror, sbc, sta, sty. 51 | 52 | Zero-Page,Y Addressing 53 | Format: stx $fb,y 54 | Instructions that can be used: ldx, stx 55 | This addressing mode exists because ldx and stx cannot be used with zero-page,x adressing mode. 56 | 57 | Indirect Indexed Adressing 58 | Format: lda ($fd),y 59 | Indirect indexed addressing uses the y register, never the x register, as an offset to calculate the base address 60 | of the start of the page. 61 | It must use a page zero starting address but the table itself does not have to be. 62 | 63 | 64 | 65 | LOGICAL 66 | -------------------------------------------------------- 67 | AND 68 | 69 | 0 0 = 0 70 | 0 1 = 0 71 | 1 0 = 0 72 | 1 1 = 0 73 | 74 | 10010011 75 | 00000111 76 | -------- 77 | 00000011 78 | 79 | AND can be used as a filter / mask, e.g. in the example above, 80 | we are only interested in the last 3 bits. 81 | 82 | -------------------------------------------------------- 83 | 84 | OR 85 | 86 | 0 0 = 0 87 | 0 1 = 1 88 | 1 0 = 1 89 | 1 1 = 1 90 | 91 | 10010011 92 | 00100111 93 | -------- 94 | 10110111 95 | 96 | OR can be used to set specific bits. 97 | 98 | -------------------------------------------------------- 99 | 100 | XOR (EOR) 101 | 102 | 0 0 = 0 103 | 0 1 = 1 104 | 1 0 = 1 105 | 1 1 = 0 106 | 107 | 10010011 108 | 00100111 109 | -------- 110 | 10110100 111 | 112 | If the inputs are different, we get a 1 out, otherwise 0. 113 | 114 | XOR can be used for many things, e.g. test where bits are different, i.e. for collision detection. 115 | 116 | -------------------------------------------------------- 117 | 118 | NOT 119 | 120 | 6502 does not have an instruction for NOT, but we can XOR with $ff (EOR #$ff 121 | 122 | 0 1 = 1 123 | 0 1 = 1 124 | 1 1 = 0 125 | 1 1 = 0 126 | 127 | 10010011 128 | 11111111 129 | -------- 130 | 01101100 131 | --------------------------------------------------------------------------------