;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- ;;This program reads a data stream from the joystick port and saves it in memory. ;;The datastream format is as sutch: ;; ;;############################################ ;; 16-bit byte-length (big endian) | data ;;############################################ ;; The data comes from CTRL2 bit 0 and the clock is at bit 1 ;; The stream starts when the clock is pulled high, after that comes a ;; 16-bit big endian number that matches the byte-lenght of the data that will get sent. ;; When the hole stream has ended the clock is pulled low until the next stream! ;; The data is then stored in ram with the first byte in progdest and the last in progdest + byte-length ;; At the end the program run the code stored at progdest with a jmp! ;; More documentation on the Joystick port can be found here: https://www.c64-wiki.com/wiki/Joystick CLKMASK = %00000010 CTRL2 = $DC00 .org $80d coldstart: ;; Draw a dollar sign on screen to show that program has loaded lda #$0 sta $400 waitstart: ;; Wait until joystick 1 has been pulled forwards to start this program lda $dc01 and #$01 bne waitstart ;; Change boarder colour for debuging lda #$00 sta $d020 teststart: jsr check_for_load_start ; Check if start_bit is correct bcs @error ; Idk why C=1 ask john beq teststart jmp $c000 ; starts the program? jmp $c000 @error: lda #1 sta $0400 ;lets store 1 att this address for debuging purposes rts check_for_load_start: lda #CLKMASK bit CTRL2 bne start ; branch if Z ==0 <--> CTRL2 and CLKMASK ==0 <---> CTRL2 bit 2 == 0 lda #$00 rts start: sei ;; change boarder collor for debuging purposes ldx #$02 stx $d020 ldy #$00 jmp new_byte wait_for_bit_start: lda #CLKMASK @loop: bit CTRL2 beq @loop lda #CLKMASK bit CTRL2 beq error lda CTRL2 lsr ror BYTE bcc wait_for_bit_end txa ; get the zero flag from X beq @normal dex lda BYTE sta LEN,x txa bne @notdone ;; Computing stop address clc lda LEN adc z:progdest sta stop lda LEN+1 adc z:progdest+1 sta stop+1 jmp @notdone @normal: ;; Byte finished, storing lda BYTE sta (progdest), y inc z:progdest bne @noinchi inc z:progdest+1 @noinchi: ;; Comparing progdest against stop address lda z:progdest cmp stop bne @notdone lda z:progdest+1 cmp stop+1 bne @notdone jmp done @notdone: new_byte: ;; BYTE is the byte beaing read from the stream. The bits are shifted from the left ;; When we shift out this 1 in BYTE bellow we save the BYTE to memory. lda #%10000000 sta BYTE wait_for_bit_end: lda #CLKMASK @loop: bit CTRL2 bne @loop jmp wait_for_bit_start done: lda #$01 cli clc rts error: ;; TODO cli sec rts BYTE = $400 LEN = $402 progdest = $fe stop: .word $0000 loaded: .byte 0