Reputation: 21
I have been trying to load a bitmap to the screen and play a sid file at the same time using an IRQ interrupt. I have it working, the Bitmap displays great, and the SID file plays wonderfully, but that's it. I want to be able to move on to the next sequence of my program either with a timer or a press of the space bar. But the entire program has frozen at the loop which checks for the timer, or in the example, I am providing the press of the space bar, but nothing happens.
When looking at the debugger (I use the visual debugger C64 65XE NES Debugger v0.64.58.4) I can see that the only area of activity is the memory where the Sid file is located $6000 onwards. It appears that I am missing something super obvious here, but not a single tutorial has the answer. I have tried to isolate the issue by removing the bitmap, but the same thing happens, so it must be in the interrupt section of the code, perhaps I'm using SEI or CEI incorrectly, I don't know!? I have tried other sid files and used different memory locations but nothing is working.
Here is the code...
; 10 SYS (2064)
*=$0801
BYTE $0E, $08, $0A, $00, $9E, $20, $28, $32, $30, $36, $34, $29, $00, $00, $00
;Assign labels to memory
chapter_no = $1000
timer = $1001
;C64 Kernal Instructions used in this simulation
print_line = $AB1E
plot = $FFF0
chrout = $FFD2
C_Raster_Line = $d012
*=$0810
play_music
;Initiate the music. This is done but putting the value 00 into the x- and
;y-registers, and call the subroutine that resets the SID-chip. The properties
;in the SID file stated that the init routine for the music is at $6000
lda #$00
tax
tay
jsr $6000
;Turn off the interrupts
sei
lda #$7f
sta $dc0d
sta $dd0d
lda #$01
sta $d01a
lda #$1b
ldx #$08
ldy #$14
sta $d011
stx $d016
sty $d018
lda #<irq
ldx #>irq
ldy #$7e
sta $0314
stx $0315
sty $d012
lda $dc0d
lda $dd0d
asl $d019
cli
lda #$00 ; enable CIA I and CIA II interrupts
sta $dc0d
sta $dd0d
lda #$10 ; enable VIC interrupts
sta $d011
lda #$01 ; enable IRQ interrupts
sta $d01a
start_BitmapLoader
;Set the chapter to...
;CHAPTER ONE!
lda #01
sta chapter_no
lda #147
jsr chrout
chapter_1
clc
lda #$00
ldx #00
ldy #00
;Load the bitmap to screen
lda $4710
sta $d020
sta $d021
ldx #$00
loaddccimage
lda $3f40,x
sta $0400,x
lda $4040,x
sta $0500,x
lda $4140,x
sta $0600,x
lda $4240,x
sta $0700,x
lda $4328,x
sta $d800,x
lda $4428,x
sta $d900,x
lda $4528,x
sta $da00,x
lda $4628,x
sta $db00,x
inx
bne loaddccimage
lda #$3b
sta $d011
lda #$18
sta $d016
lda #$18
sta $d018
start_screen_jmp
; Check for space bar input
jsr $FFE4 ; C64 Kernal GETIN routine
cmp #$20 ; Check if input is space bar
bne start_screen_jmp ; If not space bar, continue infinite loop
; If space bar pressed, clear screen and switch to character mode
jsr $FFE4 ; Clear keyboard buffer
lda #$93 ; C64 Kernal CLRSCR routine
jsr $E544
lda #$0C ; Switch to character mode
sta $D011
lda #$00
sta $D016
lda #$00
sta $D018
;Stop the music
lda #$00
tax
tay
jsr $6000
start_screen_jmp2
;Loop forever and ever
jmp start_screen_jmp2
*=$1ffe
incbin "MainBmp.prg"
irq
jsr $6003
asl $d019
jmp $ea81
; music code and data
*=$6000
music_player
incbin "future60.sid", $7e
Upvotes: 2
Views: 130
Reputation: 947
There are three ways to end interrupts on a Commodore 64.
jmp $ea31
is the standard way to run your code first then continue with kernel service routine.
jmp $ea81
works faster. It just put the register values from stack and ends the interrupt. It did no else. If you choose this option you can call SCNKEY manually to update the keyboard buffer.
Instead of relaying to kernal you can do all manually. i.e.:
PLA
TAY
PLA
TAX
PLA
RTI
As you are using jmp $ea81
you have two options. Either call SCNKEY first:
; Check for space bar input
jsr $ea87 ; Call SCNKEY
jsr $FFE4 ; C64 Kernal GETIN routine
cmp #$20 ; Check if input is space bar
bne start_screen_jmp ; If not space bar, continue infinite loop
or use your own keyboard scan
; Check for space bar
lda $dc01 ; Check Data Port B
cmp #$ef ; For space bar
bne start_scree_jmp ; If not space bar, continue infinite loop
Another solution would be to use jmp $ea31
instead of jmp $ea81
.
Upvotes: 1