145 lines
2.7 KiB
ArmAsm
145 lines
2.7 KiB
ArmAsm
;;; -*- 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 CTRL1 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
|
|
|
|
|
|
progdest = $fe
|
|
CLKMASK = %00000010
|
|
CTRL1 = $DC01
|
|
|
|
.org $80d
|
|
coldstart: ;; Draw an at sign on screen to show that program has loaded
|
|
lda #$0
|
|
sta $400
|
|
sta progdest
|
|
lda #$c0
|
|
sta progdest+1
|
|
waitstart: ;; Wait until joystick 2 has been pulled down to start the program
|
|
lda $dc00
|
|
and #$02
|
|
bne waitstart
|
|
|
|
;; Change border colour for debugging
|
|
lda #$03
|
|
sta $d020
|
|
teststart:
|
|
jsr check_for_load_start ; Check if start_bit is correct
|
|
bcs @error ; The routine sets carry in the event of an error
|
|
beq teststart
|
|
@doneforever:
|
|
jmp $c000 ; starts the program?
|
|
@error:
|
|
lda #1
|
|
rts
|
|
|
|
check_for_load_start:
|
|
lda #CLKMASK
|
|
bit CTRL1
|
|
bne start
|
|
lda #$00
|
|
rts
|
|
start:
|
|
sei
|
|
;; change border color for debugging purposes
|
|
ldx #$02
|
|
stx $d020
|
|
ldy #$00
|
|
jmp new_byte
|
|
|
|
wait_for_bit_start:
|
|
lda #CLKMASK
|
|
@loop:
|
|
bit CTRL1
|
|
beq @loop
|
|
|
|
lda #CLKMASK
|
|
bit CTRL1
|
|
beq error
|
|
lda CTRL1
|
|
|
|
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 being read from the stream. The bits are shifted from the left
|
|
;; When we shift out this 1 in BYTE below we save the BYTE to memory.
|
|
lda #%10000000
|
|
sta BYTE
|
|
wait_for_bit_end:
|
|
lda #CLKMASK
|
|
@loop:
|
|
bit CTRL1
|
|
bne @loop
|
|
;; Debug show the clock is low
|
|
lda #$00
|
|
sta $d020
|
|
|
|
jmp wait_for_bit_start
|
|
|
|
done:
|
|
lda #$01
|
|
cli
|
|
clc
|
|
rts
|
|
|
|
error:
|
|
;; TODO
|
|
cli
|
|
sec
|
|
rts
|
|
|
|
BYTE = $400
|
|
LEN = $402
|
|
stop: .word $0000
|
|
loaded: .byte 0
|