Author Topic: C64 Programming Adventures  (Read 11664 times)

0 Members and 1 Guest are viewing this topic.

Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
C64 Programming Adventures
« on: February 06, 2014, 06:23:27 pm »
I decided to dig up the old commodore64 and started programming it.
Projects so far:

Name: HEXEDIT
Lang: CBM BASIC
Description: Debug tool
Features:
-Edit bytes
-Memory monitor
-Save/load part of memory to/from file (60% done)
-Execute from memory address + dump cpu registers after execution
Download: (no link yet)


Name: NESC
Lang: 6502 Assembler  (+BASIC for doing something with the input)
Description: Reads buttonpresses from an NES controller hooked up to the user I/O port.
Features:
-Stores the incoming byte in $0002
-Byte can be read by a basic program like this:
Code: [Select]
10 SYS(32768)
20 PRINT PEEK(2)
30 GOTO 10
-A passive pin adapter is required in order to hook up an nes controller to the userport.
(Can be made using:userport connector,nes controller connector and a bunch of wire)
Picture of the c64's user I/O port:


Download: (no link yet)
« Last Edit: February 06, 2014, 06:25:15 pm by Keoni29 »
If you like my work: why not give me an internet?








Offline Juju

  • Incredibly sexy mare
  • Coder Of Tomorrow
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 5730
  • Rating: +500/-19
  • Weird programmer
    • View Profile
    • juju2143's shed
Re: C64 Programming Adventures
« Reply #1 on: February 06, 2014, 06:26:27 pm »
Ooh, hooking up a NES controller, nice.

Remember the day the walrus started to fly...

I finally cleared my sig after 4 years you're happy now?
THEGAME
This signature is ridiculously large you've been warned.

The cute mare that used to be in my avatar is Yuki Kagayaki, you can follow her on Facebook and Tumblr.

Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
Re: C64 Programming Adventures
« Reply #2 on: February 06, 2014, 06:28:15 pm »
I made a basic program that does the same thing, but that was slow, so I wrote an assembly version.
« Last Edit: February 06, 2014, 06:28:30 pm by Keoni29 »
If you like my work: why not give me an internet?








Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: C64 Programming Adventures
« Reply #3 on: February 08, 2014, 03:41:25 am »
nice!
Maybe I should grab a C64 out of my basement and do some stuff on it... :P

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
Re: C64 Programming Adventures
« Reply #4 on: February 08, 2014, 04:43:15 am »
I have been obsessed with programming the c64 for 3 days now. It almost made me fail my test because I did not study enough as a result :P I probably did allright on the test. I got an A for the first test, so I have to get an E in order to fail that course.
It reminds me of the time when I first discovered calculator programming.

My first 6502 asm program worked the first time I tested it :D I guess that's because I already know how to write eZ8 asm


Edit: Experimenting with sprites. This code will make a metroid fly across the screen. But that's not all: It also flashes bright colors.
Code: [Select]
*=$1000
;Set sprite pointer0 to $2000 ($80*$40)
        lda #$80        
        sta $07f8
;Enable sprites
        lda #$01
        sta $d015
;Expand X,Y
        sta $d01d
        sta $d017
;Set X position of sprite0 (128)
        lda #$80
        sta $d000
        sta $d001
loop
        inc $d001
        ldx #$00
delay1
        ldy #$05
delay2
        dey
        bne delay2
        dex
        bne delay1

        lda $d001
        lsr a
        lsr a
        lsr a
        lsr a
        sta $d027      

        jmp loop
        rts
Code: [Select]
*=$2000
; Metroid
 BYTE $01,$FF,$80
 BYTE $07,$FF,$E0
 BYTE $0E,$63,$F0
 BYTE $19,$99,$F8
 BYTE $33,$3D,$FC
 BYTE $37,$3D,$FC
 BYTE $66,$3C,$FE
 BYTE $68,$18,$3E
 BYTE $79,$42,$9E
 BYTE $CB,$A5,$DF
 BYTE $F3,$C3,$DF
 BYTE $F9,$E7,$BF
 BYTE $8C,$C3,$31
 BYTE $87,$18,$E1
 BYTE $59,$C3,$9A
 BYTE $3C,$FF,$3C
 BYTE $3A,$3C,$5C
 BYTE $34,$DB,$2C
 BYTE $10,$81,$08
 BYTE $08,$C3,$10
 BYTE $00,$42,$00
« Last Edit: February 08, 2014, 11:52:50 am by Keoni29 »
If you like my work: why not give me an internet?








Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
Re: C64 Programming Adventures
« Reply #5 on: February 12, 2014, 04:40:54 pm »
I wrote some code that shifts the entire screen one character to the right.
It takes about 1.7 seconds to shift the picture all the way to the right.



For anyone who wants to get into c64 programming: Get this book!

It is full of lookup tables, datasheets and schematics!
If you like my work: why not give me an internet?








Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: C64 Programming Adventures
« Reply #6 on: February 12, 2014, 04:49:54 pm »
Very cool! What language was it done with?

Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
Re: C64 Programming Adventures
« Reply #7 on: February 12, 2014, 04:53:42 pm »
This is done in 6510 ASM. There is no way you can do it this fast in basic.

Slow and large code...
Code: [Select]
joy2      = 56320

vic       = $d000
spr0_x    = $00
spr0_y    = $01

screen0H   = $04
screen1H   = $08

ptr0      = $FC
ptr1      = $FE

defm incw
        inc /1
        bne @no_carry
        inc /1 + $01
@no_carry
        endm


*=$1000
start
         
loop
          ldx #0
          stx ptr0       ;ptr0L
          stx ptr1       ;ptr1L
          ldx #screen0H
          stx ptr0+$01   ;ptr0H
          ldx #screen1H
          stx ptr1+$01   ;ptr1H
          ldx #$08
          jsr copy_loop1
          lda #$25
          sta vic + $18
         
          ldx #0
          stx ptr0       ;ptr0L
          stx ptr1       ;ptr1L
          ldx #screen0H
          stx ptr0+$01   ;ptr0H
          ldx #screen1H
          stx ptr1+$01   ;ptr1H
          ldx #$08
          jsr copy_loop0
          lda #$15
          sta vic + $18

          jmp loop
          ;;;;;;;;;;;;;;;;
copy_loop1
                         ;Start of program.
          ldy #0             
          lda (ptr0),y       ;Copy from screen0
          incw ptr0
          ldy #1
          sta (ptr1),y     ;Save to screen1.
          incw ptr1         

          cpx ptr0 + $01  ; Stop if end of screen is reached.
          bne copy_loop1
          rts
         
copy_loop0
                         ;Start of program.
          ldy #0             
          lda (ptr1),y       ;Copy from screen0
          incw ptr1
          ldy #1
          sta (ptr0),y     ;Save to screen1.
          incw ptr0         

          cpx ptr0 + $01  ; Stop if end of screen is reached.
          bne copy_loop0
          rts
I will optimize this eventually. I want to add smooth scrolling.
« Last Edit: February 12, 2014, 04:54:53 pm by Keoni29 »
If you like my work: why not give me an internet?








Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: C64 Programming Adventures
« Reply #8 on: February 12, 2014, 04:54:51 pm »
Ah, ok. I wasn't sure how competent C64 BASIC was. :P

*Edit*I'm still considering getting a C64 as well as some other old computers to fool around with. ;)
« Last Edit: February 12, 2014, 04:56:46 pm by Art_of_camelot »

Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
Re: C64 Programming Adventures
« Reply #9 on: February 12, 2014, 04:56:38 pm »
This is a 1MHz cpu copying 1000 characters over and over again to generate the next screen. It is double buffered, so I copy the screen from one buffer to another with an offset of 1. The cpu is not fast enough to copy the entire screen in one frame, hence the double buffer. While one screen is being generated the other is being displayed by the video chip.
« Last Edit: February 12, 2014, 05:12:02 pm by Keoni29 »
If you like my work: why not give me an internet?








Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
Re: C64 Programming Adventures
« Reply #10 on: February 16, 2014, 08:42:59 am »
I made a little test rig with a 6507 (cut down version of the 6502) that I can use for debugging pieces of code on actual hardware.
The setup is as follows:
A propeller chip is wired up to the 6507's data, address and control bus. It acts as if it were ram. It also generates the clock pulses for the 6507 cpu. The benefit over using regular ram is that I can log all reads and writes on a serial terminal on my computer.

Code for the 6507 and propeller chip in the spoiler:
Spoiler For Spoiler:
Test code listing loaded onto the propeller chip:
Code: [Select]
   $0000 a2 01     ldx #$01
    $0002 e8        inx
    $0003 86 06     stx $06
    $0005 4c 00 00  jmp $0000
This code will modify itself twice. First it will change the jump instruction so it jumps to $0002 and the next loop it changes it so it jumps to $0003. After that it will not modify the code anymore since the inx instruction is not being executed anymore.

Code for the propeller chip.
Code: [Select]
CON

  'Set up the clock mode
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000
  '5 MHz clock * 16x PLL = 80 MHz system clock speed  
VAR

  'Globally accessible variables
  byte ph0
  byte rw
  byte reset
  byte a
  byte mode
  long addr
  byte progmem[$2000]
  
OBJ

  'in leiu of Parallax Serial Terminal, FullDuplexSerial is being used to communicate with the terminal
  serial        : "FullDuplexSerial"

  
PUB Main | i
{{
  Starts execution

  This test program attempts to test all aspects of the FullDuplexSerial object.
  It executs each public method call provided by FullDuplexSerial.  Set your
  terminal to a baud rate of 9600 baud to see the output.
  
  parameters:    none
  return:        none
  
  example usage: N/A - executes on startup

}}
  ph0 := 27
  rw  := 26
  reset := 25

  mode := 0
  addr := 0
  
  dira[7..0]:=$00
  dira[20..8]:=$00
  dira[ph0]:=1
  dira[rw]:=0
  dira[reset]:=1
  outa[ph0]:=1
  outa[7..0]:=$00
  {
    $0000 a2 01      ldx #$01
    $0002 e8          inx
    $0003 86 06      stx $06
    $0005 4c 00 00  jmp $0000
  }
  progmem[$0000]:=$a2
  progmem[$0001]:=$01
  progmem[$0002]:=$e8
  progmem[$0003]:=$86
  progmem[$0004]:=$06
  progmem[$0005]:=$4c
  progmem[$0006]:=$00
  progmem[$0007]:=$00
  
  progmem[$1FFC]:=$00
  progmem[$1FFD]:=$00  
  
  'pulse reset
  outa[reset]:=0
  repeat 8
    outa[ph0]:=0
    outa[ph0]:=1
  outa[reset]:=1

  repeat 4
    Wait_1_Second

  'start the FullDuplexSerial object
  serial.Start(31, 30, %0000, 9_600)                    'requires 1 cog for operation

  'Main loop for ram emulator + control signal generator
  repeat
    'Clock low
    outa[ph0]:=0

    'Read R/W line
    if ina[rw]==0
      dira[7..0]:=0
      serial.tx(87)'w
      mode := 0
    else
      dira[7..0]:=$ff
      serial.tx(82)
      mode := 1
    
    'Display address bus value
    serial.tx(32)
    addr:=ina[20..8]
    serial.hex(addr,4)

    'Read/write byte from/to data bus
    if mode == 1
      outa[7..0] := progmem[addr]
        
    serial.tx(32)
    'Clock high
    outa[ph0]:=1
    
    if mode == 0
      progmem[addr] := ina[7..0]  
    'Look at Data bus
    serial.hex(ina[7..0],2)
    
    serial.tx(32)
    serial.tx(13)

PUB Wait_1_Second
{{
  Pauses the calling cog's execution for approximately one second.
    
  parameters:    none
  return:        none
  
  example usage: Wait_1_Second
}}

  waitcnt(cnt + clkfreq)

pub Wait_100_Ms
  waitcnt(clkfreq/10 + cnt)

Edit: I am reworking the code a bit so you can control everything from a serial terminal. After a reset the propeller chip waits for the pc to send it a program. You can just send a binary file using realterm and it will work. Note that it puts the program at 0002 (the reset vector is also 0002.) I will probably write a program for windows that allows you to send programs by just dragging them over the icon.
« Last Edit: February 16, 2014, 04:41:37 pm by Keoni29 »
If you like my work: why not give me an internet?








Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
Re: C64 Programming Adventures
« Reply #11 on: February 17, 2014, 04:32:21 pm »
Added features:
- 4 bit I/O port with programmable data direction.
   $0000 [3..0] Data direction register
   $0001 [3..0] Input/Output register
-You can send binaries via realterm.

New example code: Toggles an LED on the I/O port
Code: [Select]
*=2
lda #01
sta $00

loop0:
lda $01
and #2
beq loop0:

loop1:
lda $01
and #2
bne loop1:

lda $01
and #1
eor #1
sta $01

jmp loop0:
.end
« Last Edit: February 17, 2014, 04:34:30 pm by Keoni29 »
If you like my work: why not give me an internet?








Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
Re: C64 Programming Adventures
« Reply #12 on: July 09, 2014, 05:33:36 pm »
Yet another member owns a commodore 64 now. I found a whole stack of commodore stuff in a thriftshop including 3 disk drives, 2 cartridges, a datasette and ofc. a commodore 64.  aeTIos came over to my place today and came to pick it up. Expect more software to be released soon!


Left: me, right: aeTIos.
If you like my work: why not give me an internet?








Offline Streetwalrus

  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3821
  • Rating: +80/-8
    • View Profile
Re: C64 Programming Adventures
« Reply #13 on: July 09, 2014, 05:36:51 pm »
Cool ! :D Also, you both need to grow some hair. :P

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55942
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: C64 Programming Adventures
« Reply #14 on: July 09, 2014, 11:40:03 pm »
Cool ! :D Also, you both need to grow some hair. :P
Well, not everyone necessarily wants 12 inch long hairs like us, though :P


By the way Keoni29 do you think Reuben Quest: Ev Awakening or Supersonic Ball would be feasible on the C64? :P